HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Double LOCALs in GUI Not Working?? (Maybe)

09-11-2008, 03:58 AM#1
Kyrbi0
This does not work. Why?

Trigger:
Dark Swarm Summon xxx
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Dark Swarm
Collapse Actions
Custom script: local location udg_TempPoint
Custom script: local location udg_TempCasterPoint
Set TempPoint = (Target point of ability being cast)
Set TempCasterPoint = (Position of (Casting unit))
Custom script: set bj_wantDestroyGroup = true
Collapse Unit Group - Pick every unit in (Units within 150.00 of TempPoint matching (((Matching unit) belongs to an enemy of (Owner of (Casting unit))) Equal to True)) and do (Actions)
Collapse Loop - Actions
Unit - Create 1 Dummy - Dark Swarm (Corrupter) for (Owner of (Casting unit)) at TempCasterPoint facing Default building facing degrees
Unit - Order (Last created unit) to Human Dragonhawk Rider - Aerial Shackles (Picked unit)
Custom script: call RemoveLocation(udg_TempPoint)
Custom script: call RemoveLocation(udg_TempCasterPoint)
Custom script: set udg_TempPoint = null
Custom script: set udg_TempCasterPoint = null

(By "not work", I mean it either fails to produce the desired effect (creating a unit and ordering it), and/or that it crashed Wc3.)

Methinks it has something to do with trying to make 2 local variables in one trigger... Which sounds vaguely like something someone told me not to do. However, I can't see any way around it; how can I make this work (or others like it)?
09-11-2008, 04:33 AM#2
Av3n
You can only use the local variable trick once per GUI trigger a duh...

-Av3n
09-11-2008, 04:49 AM#3
Kyrbi0
Wow. That blows freakin' monkey chunks. Real hard.

~~~

So... Is there a solution? (don't say "Lrn2JASS" :/...)
09-11-2008, 04:50 AM#4
Vexorian
Quit coding.
09-11-2008, 04:54 AM#5
Ammorth
First off, no point in making them locals, since there is no wait. Only time it would be an issue is if you have an order event trigger that over-write the variables you use.

Secondly, the locals (if they did work) would not be able to be used in the loop of the group, since it is actually a seperate function without the locals, when it is converted to Jass on save.
09-11-2008, 05:00 AM#6
Kyrbi0
Quote:
Originally Posted by Vexorian
Quit coding.

Ouch. So... Since this was (originally)part of my Spell Olympics submission, I should refrain from submitting? :P

~~~

I'm not sure what you're referring to by "order event trigger", but it's a spell; technically, if any other unit on the map casts it near the same time, the variables could be overwritten (perhaps that's what you're referring to). Hence the locals.

No loops? That's unfortunate. I hope that doesn't crimp my style...
09-11-2008, 05:02 AM#7
Captain Griffen
Learn2jass.

Really. It's the only way forward.
09-11-2008, 05:09 AM#8
Pyrogasm
Even if you did have a wait, you can always create (normal) locals anyway and then transfer the relevant data between your globals and locals before/after the wait.
09-11-2008, 11:59 AM#9
Vexorian
Quote:
Ouch
Since I couldn't say you should learn Jass you didn't give me any choice, locals = learn Jass.
09-11-2008, 05:32 PM#10
Kyrbi0
Quote:
Originally Posted by Pyrogasm
Even if you did have a wait, you can always create (normal) locals anyway and then transfer the relevant data between your globals and locals before/after the wait.

Ok... How?

Quote:
Originally Posted by Vexorian
Since I couldn't say you should learn Jass you didn't give me any choice, locals = learn Jass.

Y'know, you remind me more and more of Simon Cowell.

If Locals = learn JASS, then I already know JASS. I just don't think I have the time to progress (nor the absolute need), so is there another "local-related" (or otherwise) bit of JASS knowledge that can help me out in this situation (and others like it)?
09-11-2008, 06:30 PM#11
the-thingy
As Av3n and Pyrogasm said, you don't even need locals (which is pretty much problem solved :P)

Anyway, locals declared outside a UG loop cannot be used inside the UG loop (since the loop actions are in a separate function)

Also, I think using bj_wantDestroyGroup can cause issues with other groups (if, say, you needed to use a ForGroup on the same UG twice, or in a periodic trigger) unless you set it back to false (since I don't think it's automatically reset once the ForGroup ends, you should check JASScraft/TESH function list for the approriate function, I think it's GetUnitInRangeOfLoc)
09-11-2008, 06:46 PM#12
Kyrbi0
Huh? How don't I need locals? (I mean, what if two casters cast it at once; one's "TempCasterPoint" is different from the other, thus breaking the spell (not to mention the "TempPoint")). Or is it instantaneous?

"UG" loop... "Universal Globals"? (But yes, I've heard about this :/...) Is this the same with If/Then/Elses?
(can can I re-call it as a local inside the Loop / If-Then-Else?)

I've also heard various murmurings about not using "bj_wantDestroyGroup" as well, but nothing concrete. But what does
Collapse JASS:
GetUnitInRangeOfLoc
do for me again?
09-11-2008, 07:35 PM#13
the-thingy
UG -> Unit Group (at least that's what I recognise UG as :P), same applies with the Matching Condition part (so you can't do Unit is Enemy of (Localized global player) or something)

And pretty much same thing happens with if-then-else (if you use the GUI version) - If conditions (in GUI) are handled in a separate function and, as a result, you can't use the locals there, but you could just add a few lines of custom script
Code:
Custom script: if GetWidgetLife (whichUnit) > .405 then [color="DarkGreen"]//i.e. condition returns true if the unit is alive
---Insert some actions here---
Custom script: else [color="DarkGreen"]//The else declaration isn't required, unless you actually plan on having else actions
---Insert other actions here---
Custom script: endif


Code:
Or is it instantaneous?
It's instantaneous, I'm 95% sure that it's completely impossible to overwrite variables in separate triggers if both triggers have no waits

Quote:
GetUnitInRangeOfLoc
That's one of the GUI unit group options (I think it's Unit In Range of Point, or something)

Quote:
(can can I re-call it as a local inside the Loop / If-Then-Else?)
Ye, just assign a global to the local variable immediately before running the unit group loop/if e.g.
Code:
local unit udg_UnitVar = GetTriggerUnit ()
---You can do it all in one line, or define it afterwards through the GUI action---
call TriggerSleepAction (5.0)
---Or just use the Wait action :P---
Set OtherUnit = UnitVar
Pick every unit in InsertGroupHere and do actions:
   ---Do some stuff with OtherUnit---
09-11-2008, 09:06 PM#14
Captain Griffen
Using locals there will fail to do what you expect. Learn jass, or don't use locals. Simple as that.
09-12-2008, 12:04 AM#15
Ammorth
All I was saying about the "order event trigger" is that is the only place where your variables can be over-written.

Each trigger will execute its actions completely until it either finishes or reaches a break.

There are 2 kinds of breaks; breaks with a duration, or breaks with an event.

Duration breaks are simply waits. They cause the trigger to stop executing for the desired time, and let other triggers execute. So, if your trigger doesn't have a wait, every action will be executed in order, whithout executing any other trigger. There is one exception though; when you use "event breaks"

Event breaks happen when one of your actions triggers an event. In your case, issuing an order to a unit counts as an event break. In the case of an event break, it pauses the execution of the trigger, and runs the event triggers (the triggers which have the event "A unit is issued an order"). Once all those trigger finish, or they reach a duration break, it continues to execute the rest of the actions in the starting function

Example:
Code:
Trigger A has 8 actions, action 4 is a wait.

TriggerA
Action1
Action2
Action3
Action4 - Duration break
// pause for duration
Action5
Action6
Action7
Action8
EndTrigger


As you can see, once the wait is over, it jumps right back into the trigger and executes each one in order without executing other triggers.

Now, if we have an event break, its a little different

Trigger B runs when a unit is ordered to move, it has 2 actions, and no breaks

Trigger B
Action1
Action2
EndTrigger

TriggerC has an event break (a unit is ordered to move) at action 3 of 5

TriggerC
Action1
Action2
Action3 - Event Break
// wait for event triggers to finish or duration break.
Action4
Action5
EndTrigger

If we stuck both TriggerC and TriggerB in the same flow-chart it would look like this

TriggerC
Action1
Action2
Action3 - Event Break
    TriggerB
    Action1
    Action2
    EndTrigger
Action4
Action5
EndTrigger

As you can see, once the event was reached, TriggerB executed completely, and then the game revenrted directly back to TriggerC to finish the execution.

The example shows that as long as you don't have duration breaks or event breaks, your variables won't be over-written. If you have duration breaks, you need to use locals. If you have event breaks, you can use locals, or you can trace through all your event triggers (that will be triggered by that event break) and make sure none of the variables are used in any of them.