HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Local Variables with GUI Trigger help please

12-27-2006, 07:16 AM#1
Oblivion9
I have read thru as many threads as I could find trying to figure out how to incorporate local variables with regular GUI triggers such as:

Trigger:
Custom script: local location udg_TempPoint = GetTempSpace()
Set TempPoint = (Center of UnitSpawn <gen>)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing degrees
Custom script: call RemoveLocation( udg_TempPoint )
What I don't get is how you actually use that local variable in a GUI trigger. Which is exactly this part: "Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing degrees" TempPoint, or for that matter any local variable that I've tried does not show up on those silly drop down menus.

I know many of you will suggest that I just learn JASS, and for a person who has been doing this as long as I have, I should. I just don't have all the time in the world, especially since I have not been able to locate the entire syntax of JASS. (I know winmpq on .j files and such and such... but I don't just need the names, I need some examples on the declarations so I can get a feel for the language)

I have searched several of the JASS/Memory Leaks threads such as:
http://www.wc3campaigns.net/showthread.php?t=55022
http://www.wc3campaigns.net/showthread.php?t=81872
http://www.wc3campaigns.net/showthread.php?t=12687
http://www.wc3campaigns.net/showthread.php?t=81267
http://www.wc3campaigns.net/showthread.php?t=89982
without any luck, so if someone could just tell me that either a) Local Variables can not be used with GUI triggers or b) that they can and you need x, y and z to do it. I have read that I can just do most of it in GUI then convert it to custom scripts and change variables in there to local ones and what not, but I've also read that that can cause WE to crash...

And lastly, I am doing a item combine system with powerups (thanks RodOfNod, zen87, and Vex for your responses on that), which kinda works. The one problem I have is that there are 36 combos (20 involving 2 items and a power up and 16 involving 1 item and a power up) and I was hoping to maybe do it a more efficient way... Perhaps by declaring each item in a global item-type array and a corresponding global item-type (powerup) array then just using a loop to parse thru each unit has item of item-type group/powerup equal true then do blah blah... But, this would have to be a declared function/trigger that wouldn't run unless conditions (allied shop test and unit-type) were met. I was thinking that locals would work really well in that (a local TMPInteger for the for loop, local TMPItem = GetManipulatedItem(), and a local TMPUnit = GetTriggerUnit()) then they could be destroyed to save on memory leaks.

Any help you can offer would be greatly appreciated. Thank you.
12-27-2006, 07:20 AM#2
PipeDream
Declare the variable TempPoint in the global editor. When you declare the variable locally, the local copy will override, but you can still pick the name out of the GUI editor.

Declaring multiple locals this way breaks down, which is when you use GetTempSpace(). This isn't one of those cases, so all you need to do is declare the variable and assign Center of Unit Spawn to it.
12-27-2006, 02:59 PM#3
Chocobo
Remember using locals in GUI do not work if you are using that half local/global inside a new function. (Pick Every Unit In.., Pick Every Player.., If Then Else...)
12-27-2006, 04:58 PM#4
Themerion
1. Create the global (normal) variable named XXX.
- This will make it show up in the variable-list.

2. Do exactly as you've already done.

3. The script/trigger will always look for the local variable first. This means that if you have a local variable and a global variable with the same name, then the local variable will be the one which is used.

4. I think that you have to nullify the local variable too. set udg_XXX=null
Trigger:
Custom script: local location udg_XXX = GetTempSpace()
Set TempPoint = (Center of UnitSpawn <gen>)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing degrees
Custom script: call RemoveLocation( udg_XXX )
Custom script: set udg_XXX=null

Also pay attention to what Chocobo said! Assigning local variables in GUI does NOT work in the cases:

Trigger:
Unit Group - Pick every unit in ... and do (Actions)
Player Group - Pick every player in ... and do (Actions)
Destructible - Pick every destructible in ... and do (Actions)

AFAIK, it does work in if-statements. It's just that it doesn't work in the conditions. In other words, you cannot have a local variable in an if-condition. The "then" and "else" things are fine though.
12-27-2006, 07:36 PM#5
Oblivion9
So locals don't work in conditions... is that just for GUI triggers or does that apply to JASS scripts as well?
12-28-2006, 12:52 PM#6
Chocobo
Quote:
Originally Posted by Oblivion9
So locals don't work in conditions... is that just for GUI triggers or does that apply to JASS scripts as well?

It can not work in GUI because the IF Condition(s) are in a new function. But it works in JASS if you put something like :

Collapse JASS:
function whatever takes nothing returns nothing
if whatever conditions then whatever actions
    
else if whatever conditions then whatever actions
    loop
        exitwhen whatever conditions
        whatever actions
    endloop
    whatever actions
    
endif
whatever actions
endfunction

Which is not :
Collapse JASS:
function RandomCond1 takes integer udg_range, real udg_x returns boolean
    if udg_RectRanged[udg_range] then
        set udg_RectRange[udg_range] = udg_x
        return true
    endif
    return false
endfunction

function RandomCond2 takes nothing returns boolean
    if udg_RectRanged[udg_range] then
        set udg_RectRange[udg_range] = udg_x
        return true
    endif
    return false
endfunction

function whatever takes integer udg_range, real udg_x returns nothing
local integer udg_range=udg_range
local real udg_x=udg_x
if RandomCond2() then whatever actions //The condition does not work fine, 
    
else if RandomCond1(udg_range,udg_x) then whatever actions //The condition works fine
    loop
        exitwhen whatever conditions
        whatever actions
    endloop
    whatever actions
    
endif
whatever actions
endfunction
12-29-2006, 12:30 AM#7
Pyrogasm
If you wanted to use a local in a condition, couldn't you do it (in theory) by using a global variable also. Could you not set the global equal to the local, use the global in the condition, and then code for leaks? Something like this:
Trigger:
Collapse Events
Unit - A unit dies
Condtions
Collapse Actions
Custom Script: local unit udg_My_Local_Point
Set My_Local_Point equal to (Position of (Triggering Unit))
Set My_Global_Point equal to My_Local_Point
Collapse If (All Condtions are true, then do (Actions), else do (Actions)
Collapse If - Condtions
(My_Global_Point is in (Explode Death <gen>)) equal to true
Collapse Then - Actions
Custom Script: call RemoveLocation( udg_My_Global_Point )
Special Effect - Create a special effect at (My_Local_Point ) using Special\Talktome.mdx
Special Effect - Destroy (Last created special effect)
Collapse Else - Actions
Custom Script: call RemoveLocation( udg_My_Global_Point )
Custom Script: set udg_My_Local_Point = null
12-29-2006, 01:34 AM#8
PipeDream
Yes. In your example, since there are no waits or things that could trigger other triggers, you could get rid of the local entirely. For the ways people normally use GUI, you only need locals to work around places where other threads can intercept globals.
12-29-2006, 04:58 AM#9
Ammorth
Quote:
Originally Posted by Pyrogasm
If you wanted to use a local in a condition, couldn't you do it (in theory) by using a global variable also. Could you not set the global equal to the local, use the global in the condition, and then code for leaks? Something like this:
Trigger:
Collapse Events
Unit - A unit dies
Condtions
Collapse Actions
Custom Script: local unit udg_My_Local_Point
Set My_Local_Point equal to (Position of (Triggering Unit))
Set My_Global_Point equal to My_Local_Point
Collapse If (All Condtions are true, then do (Actions), else do (Actions)
Collapse If - Condtions
(My_Global_Point is in (Explode Death <gen>)) equal to true
Collapse Then - Actions
Custom Script: call RemoveLocation( udg_My_Global_Point )
Special Effect - Create a special effect at (My_Local_Point ) using Special\Talktome.mdx
Special Effect - Destroy (Last created special effect)
Collapse Else - Actions
Custom Script: call RemoveLocation( udg_My_Global_Point )
Custom Script: set udg_My_Local_Point = null

An easier way (in my opinnion) is to use custom text for the if/then/else instead of transfering the local to a global and back again. ie:
Trigger:
Custom Script: local unit somelocalvariable = udg_someunit
Custom Script: if GetTriggerUnit() = somelocalvariable then
Unit - Kill somelocalvariable
Custom Script: else
Unit - Hide somelocalvariable
Custom Script: endif
12-29-2006, 06:43 AM#10
Pyrogasm
Oh. So locals can be used in custom script if's, but not GUI if's. I did not now that.
12-29-2006, 07:11 AM#11
Chocobo
Quote:
Originally Posted by Pyrogasm
Oh. So locals can be used in custom script if's, but not GUI if's. I did not now that.

Quote:
An easier way (in my opinnion) is to use custom text for the if/then/else instead of transfering the local to a global and back again. ie:

Locals in GUI using "Pick Every" things with a TriggerSleepAction or a PolledWait won't work (Because we can overwrite over after the sleep. Or maybe you will again use a new local?). And also, those lines create a new function from GUI, so you will have to transfer the local to a global, and then the global to a local (maybe?).
12-29-2006, 09:17 AM#12
rulerofiron99
goto varaible manager thingy, make arrayed point,

Set tempPoint[4] = position of unit
Unit - create units at tempPoint[4]
Custom Script: call RemoveLocation(udg_tempPoint[4])

or

Set tempPoint = position
Unit - bla blah blah
Custom script: call RemoveLocation(tempPoint)


This is how I've been doing it for a long time now, and it works fine. glhf.