| 10-05-2002, 12:47 AM | #1 |
Guest | Is there a wa to make a local variable in a trigger? I know that JASS supports "local unit u = null" for example, but whenever I try to put it in my map, it tells me that it expects a code statment there, i.e. it doesn't like "local unit u = null". Any ideas? And no, I don't want to just make a global variable, because I need it to be thread safe.... Thanks :D |
| 10-05-2002, 12:59 AM | #2 |
yes local vars do work. Only in custom text and I use them quite often :) If you get really lazy you could just use Blizzard.j defined variables there are really alot of them. Alot of integers alot of unit alot real...That you'll probably never use. Especially bj_ghoul which I can't actually find its use in blizzard.j :) |
| 10-05-2002, 03:51 AM | #3 | |
Guest | Quote:
I don't think you can initialize vars when you declare them. You have to declare (local type name) then set them (set name = value). Care. |
| 10-05-2002, 04:39 AM | #4 |
This is probably your problem, you must declare local variables before any other statements. You can initialize them when you declare them. OK local integer i = 0 local integer j = 0 set udg_myGlobalArray[i] = 0 NOT OK call SomeRandomTrig() local integer i = 0 set udg_myGlobalArray[i] = 0 |
| 10-05-2002, 07:42 AM | #5 |
Guest | So I can do this in the regular map editor? Because this doesn't work... function blah takes nothing returns nothing local integer i = 0 local integer j = 0 set udg_myGlobalArray[i] = 0 endfunction |
| 10-05-2002, 11:36 AM | #6 |
Tell us the error message, please. |
| 10-05-2002, 02:24 PM | #7 |
That code should work. it is important you tell us what the error is as superiki said or start looking at blizzard.j variables if you get lazy |
| 10-05-2002, 05:48 PM | #8 |
Local variable what? I don't quite understand what it is or what it's used for. If it's what I think it's for (a variable that only exists on one computer in a multiplayer game) then i find it much easier to use variable arrays and store them based on the number of the players... |
| 10-05-2002, 11:22 PM | #9 |
a local variable is a variable that can only be used in the triggers it was created in.... (right?) |
| 10-05-2002, 11:48 PM | #10 |
There are no local trigger variables. Just local function variables. Their scope is the function they were created in. |
| 10-06-2002, 01:05 AM | #11 |
Oh yes I see... I should've figured that out for myself, seeing as how I program VB. I'm not all here today. Still really don't see the use of them though. |
| 10-06-2002, 05:21 PM | #12 |
Fear I might agree with you but when I'm creating triggers on the fly it does help to just use a local trigger as after that run of the function it is destroyed and the local trigger will still run, if the function again for a different player it will still run with the same name, however if I use globals then it will not run the first. |
| 10-06-2002, 07:58 PM | #13 |
Fear.Factor: The use of them is to make sure a trigger is thread safe -- i.e., one trigger may be running 5 times at the same time. Say for example a trigger that goes off when a unit is killed -- what if 5 units are killed at the exact same time? If you store the unit that is killed in a variable, then reference that variable throughout the rest of the function, you'll run into problems, because between the time the variable is first changed, and the actions are done on that variable, the value of the variable will be changed by another instance of the trigger (because multiple copies can run at once). |
