Calling a function from a String

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,132
Location
The Kingdom of New Zealand
I'm looking to make a more dynamic TopPanel, so that modders (i.e. me) can add new Yield Per Turn values without complicated workarounds that potentially conflict with other mods. To do this, though, I need to interpret a string as a function, and I'm not sure how to properly use loadstring, or whether it works fully in this game. So it would be much appreciated if someone can enlighten me as to whether this is possible. Thanks.

This is what I have:

Code:
local numGold = loadstring("JFD_Test" .. "()")()

iGoldPerTurn = iGoldPerTurn + numGold

This is the error:

Code:
attempt to perform arithmetic on local 'numGold' (a function value)
 
Assuming this page is still in-date, the load* methods have been sand-boxed and can't be used.
 
Back
Top Bottom