• 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!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[Solved] Set custom variable

Status
Not open for further replies.
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.
 
Last edited:
Status
Not open for further replies.
Back
Top