I'm trying to run an IronPython script in C# but sometimes when I run it I get this error:
IronPython.Runtime.UnboundNameException: name 'str' is not defined
I can't figure out why this is happening; it only happens sometimes; right now it happens when I click a planet in my game to view the report on its abilities.
Here's the script I'm trying to run:
'Mines ' + str(Amount1) + ' minerals each turn (modified by planet value).'
As you can see I'm trying to concatenate some strings, one of which is a stringified Amount1 variable (Amount1 I think is the number 800 but it might be a more complex expression equal to 800, I'd have to check on that), but for some reason I'm getting an error saying the str
function is undefined, which makes no sense!
There are other scripts being included before this script runs; if you like I can find those and paste them here in case that might help...
edit: here's the full script that I'm running:
import sys, imp;
import __builtin__ as builtins;
builtins_code = """""";
exec builtins_code in builtins.__dict__;
import clr
clr.AddReference('System.Core')
import System
clr.ImportExtensions(System.Linq)
clr.AddReference('FrEee.Core')
import FrEee
import FrEee.Utility
clr.ImportExtensions(FrEee.Utility.Extensions)
from FrEee.Modding import Mod
from FrEee.Game.Objects.Space import Galaxy
from FrEee.Game.Objects.Civilization import Empire
'Mines ' + str(Amount1) + ' minerals each turn (modified by planet value).'
Could the exec builtins_code
line be deleting the str
function? If so, how can I make sure that builtins_code
gets added to builtins rather than replacing it?
edit2: nope, even if I remove the first four lines, it crashes when I process a turn in a single player game and then click my homeworld!
edit3: if I put the script in a text file and run it as a watch (see below) it runs just fine, even on the breakpoint where it crashes:
FrEee.Modding.ScriptEngine.EvaluateExpression<string>(System.IO.File.ReadAllText("c:/users/edkol/desktop/test.py")), ac