Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
If I write in chat: "lumber 10" then it sets variable with name lumber to 10
If I write in chat: "gold 200" then it sets variable with name gold to 200
If there is no variable with name gold or lumber and still I write gold 200 or lumber 10, the variable cant be set.
I'm not sure converting a string to a variable reference is possible. A general purpose trigger than converts any "string number" chat message to "variable with name of string = number" probably isn't possible; this isn't python, unfortunately.
You'll have to write up a case for each variable you're using.
It is not possible to set a dynamic variable. All variable names, except some trigger events, require being declared at compile time.
One can simulate the mechanic using a switch of sorts. For example say you want to set the integer variables GoldIncome, WaveNumber or LivesLeft. The following function could be used to set the integer variable specified by a string to a specified value.
JASS:
function SetIntegerVariable takes string varname, integer value returns nothing
if varname = "GoldIncome" then
set GoldIncome = value
elseif varname = "WaveNumber"
set WaveNumber = value
elseif varname = "LivesLeft"
set LivesLeft = value
else
// Cannot resolve variable.
call BJDebugMsg("Invalid variable name!")
endif
endfunction
Since this is a linear search, the more variables added to it the longer it will take to run. It could easily support hundreds of variables as long as it is called very infrequently. Different such functions would be needed for each type of variable, such as one for strings, one for reals etc. Through use of StringHash it should be possible to use a binary search instead of a linear search for better scaling, however for productive use some form of third party script would need to be created which generates the necessary code.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.