• 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.

[JASS] Simple question about locals.....

Status
Not open for further replies.
Level 9
Joined
Oct 11, 2009
Messages
477
I have a question, why do I get an error that reads "expected a name" in a trigger where I used the local but on the first trigger it works.


In other words, is it possible to retrieve a data of a local variable without using global variables in between two or more than a trigger?
 
I have a question, why do I get an error that reads "expected a name" in a trigger where I used the local but on the first trigger it works.


In other words, is it possible to retrieve a data of a local variable without using global variables in between two or more than a trigger?

You can't. You have to resort to hashtables/globals. Local variables are local to the function. =)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
JASS:
globals
    private real tempReal
endglobals

function ExampleChild takes nothing returns nothing
    if(tempReal>0) then
        call DoNothing()
    endif
endfunction

function Example takes nothing returns nothing
    set tempReal=3
    call ExampleChild()
endfunction

Remember, the above code is the same thing as:

JASS:
function ExampleChild takes real r returns nothing
    if(r>0) then
        call DoNothing()
    endif
endfunction

function Example takes nothing returns nothing
    call ExampleChild(3)
endfunction

You can use global variables to "transfer" data between functions that are executed sequentially because only one thread runs at a time. This is useful for certain things that do not allow parameters, such as group enumerations. Just so you know.
 
Status
Not open for further replies.
Top