Edit: Solved, use TriggerAddEventUnitRegion(t, UnitRefFromUnit(u), r, flag) to accomplish this functionality. See attached map for a demo.
Hey, so I would like to create a trigger that functions essentially as follows:
Events: gv_unitvar enters gv_regionvar
Conditions: ...
Actions: ...
My current approach was to create a custom action definition called TriggerAddEventUnitRegion using the parameters from the native function in the archive, checking the native option, and then making the unit parameter passed by reference. Next, I created my function with the actions that I want to happen when the trigger fires. And finally, I created the trigger and called my action TriggerAddEventUnitRegion passing as a parameter my unit var and region var. However, the unit variable seems to be broken, it is being treated as null it seems (trigger is firing whenever Any Unit enters the region). I looked at the sciprt, the code that's being generated for the unit parameter is UnitRefFromVariable("gv_unitvar") - at first I was like "Oh that's a sweet function," but at the same time it's not working for me :/
I can't be the only one who has tried to do this, anyone got this working?
(Current shitty workaround: check condition after the trigger fires, but then I get a trigger firing possibly dozens of times a second when I really only want it to fire a few times per minute.)
Ive ran into issue with doing fancy things with events didn't work or broke. i am of the understanding that events cant really receive dynamic content and that things like triggering unit inst set until after the event. So i also came to the same conclusion that you did.
region events firing off dozens of times a second isn't too bad. especially with a fast condition. large loops are a larger issue. to minimize the firing you can use generic triggers to do the work. For example, a "TriggerAddEventUnitRegion" with generic unit and specific region. that would then sort the initial information and pass the information off to sub triggers. this way when a unit walks into a region instead of multiple triggers going off, only 1 does.
Thanks for the reply man.. kind of sad about that.
I guess it's ok for now, since the trigger condition check is super fast (1 <= triggering player <= 10), it just seems like really sloppy style and I can't understand why the editor wouldn't have a way to do this.
It seems the problem is in the function UnitRefFromVariable that the compiler automatically sticks in there, which ends up just being a null reference. Maybe there's some way to dynamically get an actual reference to the unit, and then it should work...
you could try galaxy script. It may be more open to the idea. As for efficiency, make a master trigger for any triggers with identical events. so if you have 2 or more triggers with "map initialization" you can delete the event and create a trigger with "map initialization" that calls upon the them
You need to enter the event dynamically to the trigger to work for non-preplaced units. It is important to set the unit variable BEFORE adding the event. The event itself is static and will not poll the newest value of the variables it uses.
The easiest way to achieve this is to create a new action definition (function) with default parameters and the following content:
initEventsGame-MapinitializationLocalVariablesu=NoUnit<Unit>ConditionsActions-------createanon-preplacedunit.Unit-Create1Critter-Urubuforplayer1at(PositionofMarine[63.74,63.00]) facing (Position of Marine [63.74,63.00]) (No Options)
Variable - Set u = (Last created unit)
------- make region enter react to created unit and preplaced zergling
add region enter event(unit enters region, u, Region 001, True)
add region enter event(unit enters region, Zergling [63.80,64.94], Region 001, True)
I thought this is exactly what I did, I will make a very simple test of concept map tonight and make sure though.
Edit: Bloody hell, I made a super simple map with only this functionality and it worked... I must have gotten lost in the complexities of everything... Will try to see where I slipped up.
Edit 2: Found the difference!
When using a pass by reference parameter, the editor uses the function UnitRefFromVariable(string) as I stated in my OP, however Mille, you used the function UnitRefFromUnit. Could have just told me that haha...
Anyway, looks like this issue is solved! To any one else who wants to do "Variable unit enters variable region" triggers, it can certainly be accomplished, just make sure to use UnitRefFromUnit for the unit parameter to TriggerAddEventRegion.
Edit: Solved, use TriggerAddEventUnitRegion(t, UnitRefFromUnit(u), r, flag) to accomplish this functionality. See attached map for a demo.
Hey, so I would like to create a trigger that functions essentially as follows:
Events: gv_unitvar enters gv_regionvar
Conditions: ...
Actions: ...
My current approach was to create a custom action definition called TriggerAddEventUnitRegion using the parameters from the native function in the archive, checking the native option, and then making the unit parameter passed by reference. Next, I created my function with the actions that I want to happen when the trigger fires. And finally, I created the trigger and called my action TriggerAddEventUnitRegion passing as a parameter my unit var and region var. However, the unit variable seems to be broken, it is being treated as null it seems (trigger is firing whenever Any Unit enters the region). I looked at the sciprt, the code that's being generated for the unit parameter is UnitRefFromVariable("gv_unitvar") - at first I was like "Oh that's a sweet function," but at the same time it's not working for me :/
I can't be the only one who has tried to do this, anyone got this working?
(Current shitty workaround: check condition after the trigger fires, but then I get a trigger firing possibly dozens of times a second when I really only want it to fire a few times per minute.)
raw data view is annoying but alright.
Ive ran into issue with doing fancy things with events didn't work or broke. i am of the understanding that events cant really receive dynamic content and that things like triggering unit inst set until after the event. So i also came to the same conclusion that you did.
region events firing off dozens of times a second isn't too bad. especially with a fast condition. large loops are a larger issue. to minimize the firing you can use generic triggers to do the work. For example, a "TriggerAddEventUnitRegion" with generic unit and specific region. that would then sort the initial information and pass the information off to sub triggers. this way when a unit walks into a region instead of multiple triggers going off, only 1 does.
@SoulTaker916: Go
Thanks for the reply man.. kind of sad about that.
I guess it's ok for now, since the trigger condition check is super fast (1 <= triggering player <= 10), it just seems like really sloppy style and I can't understand why the editor wouldn't have a way to do this.
It seems the problem is in the function UnitRefFromVariable that the compiler automatically sticks in there, which ends up just being a null reference. Maybe there's some way to dynamically get an actual reference to the unit, and then it should work...
you could try galaxy script. It may be more open to the idea. As for efficiency, make a master trigger for any triggers with identical events. so if you have 2 or more triggers with "map initialization" you can delete the event and create a trigger with "map initialization" that calls upon the them
You need to enter the event dynamically to the trigger to work for non-preplaced units. It is important to set the unit variable BEFORE adding the event. The event itself is static and will not poll the newest value of the variables it uses.
The easiest way to achieve this is to create a new action definition (function) with default parameters and the following content:
This function can then be used as follows:
@Mille25: Go
I thought this is exactly what I did, I will make a very simple test of concept map tonight and make sure though.
Edit: Bloody hell, I made a super simple map with only this functionality and it worked... I must have gotten lost in the complexities of everything... Will try to see where I slipped up.
Edit 2: Found the difference!
When using a pass by reference parameter, the editor uses the function UnitRefFromVariable(string) as I stated in my OP, however Mille, you used the function UnitRefFromUnit. Could have just told me that haha...
Anyway, looks like this issue is solved! To any one else who wants to do "Variable unit enters variable region" triggers, it can certainly be accomplished, just make sure to use UnitRefFromUnit for the unit parameter to TriggerAddEventRegion.