With the exec Versus eval contemplation, can you just pass "result" in with the argslist to the function and have it set result? Some languages local changes to variables won't hold on return, haven't tested with python. Could also set result as a global variable which is cleared to false before you execute the python function, then let the writer of the function set the global result to what he needs.
I don't quite understand the question...
There is no function that it makes sense to pass in result. I'm guessing you're talking about
exec.
exec is actually a statement, and it is by default executed in the local namespace. That is if you write "
exec pythonCode" it will work exactly as if you replaced the
exec statement with the code in the
pytonCode object.
It is possible to execute the
exec in separate namespaces, but I see no reason to. The global namespace needs the civ modules, and the local namespace of
canCast exists for the sole purpose of executing the PyRequirement. Malicious code will be able to change the global namespace, but malicious code will always be malicious.
Or maybe you're thinking that PyRequirement is a function. It isn't, it's just loose code, that gets executed
inside the
canCast function.
When the
exec is done, you have access to all names the PyRequirement used. So the only problem is figuring out which name binds to the information you're interested in. A convention of using the name "result" would solve that.
(The nature of Python variables is simple. Python doesn't have variables.
Python works sufficiently different from C/C++/Ada/etcetera variables that using different names is warranted. Many innocent electrons have been tortured with discussions about this in Python newsgroups,
for instance. It's more similar to Java, only consistent.
It's not very important.)
And requiring 2 food growth would stop this example, but not the issue. What if I had 2 food growth, cast the spell, so now have 0 food growth, then I change my Floodplains/Farm working citizen to be a Engineer specialist? Now I am at -5 food per turn, and the infinite loop kicks in.
The problem is that the food export is an all or nothing deal. A master with seven slaves needs to be able to export 14 food, or it can't export any. Having the slaves export food like xienwolf said would avoid this, since each slave can gain or lose exporting food independently. The promotion would still need to have a 2
gap between gaining and losing itself though, to prevent it from taking away so much
that it causes itself to be lost.
And importing food
from several cities
to a single city sure seems like a more common use case.