• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Same Variable for Multiple Triggers (not Array)

Status
Not open for further replies.

hdm

hdm

Level 9
Joined
Nov 19, 2011
Messages
384
Can I do so ? The variable leads a unit instantly to a location. Suppose we have two regions near each other, one on left and one on the right. If a player enters a certain string like -Thisregion then the Variable is set to the right region (and the unit moves to the right region instantly). If a player enters -Thatregion then the SAME variable is set to the left region. Ofc, if a player enters a string for a region, e.g Left region, the trigger is turned off for this player, so he can't enter the string for the right region. But the other players ? What happen to them ?

To make it clear, here is the Trigger:

The Right Region Trigger (Call it X) For P1

  • Play as X P1
    • Events
      • Player - Player 1 (Red) types a chat message containing -Rightregion as An exact match
    • Conditions
    • Actions
      • Set PointStringCheat = (Center of Right Region <gen>)
      • Unit - Move Spirit of Warrior 0186 <gen> instantly to PointStringCheat
      • Custom script: call RemoveLocation(udg_PointStringCheat)
      • Trigger - Turn off (This trigger)
The Right Region Trigger for P2

  • Play as X P2
    • Events
      • Player - Player 2 (Blue) types a chat message containing -Rightregion as An exact match
    • Conditions
    • Actions
      • Set PointStringCheat = (Center of Right Region <gen>)
      • Unit - Move Spirit of Warrior 0187 <gen> instantly to PointStringCheat
      • Custom script: call RemoveLocation(udg_PointStringCheat)
      • Trigger - Turn off (This trigger)
The left Region for P1 (Call it Y)


  • Play as Y P1
    • Events
      • Player - Player 1 (Red) types a chat message containing -LeftRegion as An exact match
    • Conditions
    • Actions
      • Set PointStringCheat = (Center of Left Region <gen>)
      • Unit - Move Spirit of Warrior 0186 <gen> instantly to PointStringCheat
      • Custom script: call RemoveLocation(udg_PointStringCheat)
      • Trigger - Turn off (This trigger)
And so go on with p2 p3 etc. Both left and right region. The Spirit of Warrior is killed and removed from the game after he moves to certain region.

You can see all them use the same variable for location. This is my question, does it work properly ?
 
Level 12
Joined
May 22, 2015
Messages
1,051
Yes that will work properly. You could probably restructure these triggers more nicely so you don't need two for every player, but that's a separate thing.

Triggers only run one at a time. Even if a hundred triggers all happen at the same time (say you have 100 of your X P1 triggers), the position variable will work fine, because it will set and destroy the point each time before running the next trigger.

The one place you have to worry about is when you have trigger actions that can cause other triggers to run -> such as damaging a unit, killing a unit, casting a spell, etc. If you use the same variables in the other triggers, they will get overwritten and will likely cause problems.
 
Level 12
Joined
May 22, 2015
Messages
1,051
This is what we basically call a temp(oral) variable

I think "temporary" is the word it is short for.

Anyway, this why you might see some code like:
set tempInt = 3

tempInt is an integer variable that doesn't store anything important. It is only needed for a brief moment so that your triggers don't get super cluttered. In the case of points, using some kind of tempPoint is necessary in order to delete it properly.
 
Level 12
Joined
Jan 2, 2016
Messages
973
By the way: the way you've made these triggers - if player 1 writes "-Rightregion" - he wouldn't be able to enter the right region again, but he will be able to enter the left one!

I'd also like to suggest a better way to structire these triggers:
instead of making 2 triggers per player - you can make only 1:
(first you need to store the units you are moving into a unit variable (array), let's say size = 13)
Events would be "player 1 writes rightregion; player 1 writes leftregion; player 2 writes...." and so on
actions:Set ~some integer~ = PlayerNumber(TriggeringPlayer)
if ~a boolean[~the integer~]~ is equal to false then do the following actions (otherwise do nothing):
if (string comparison) entered chat string equal to "-Rightregion" then
Set PointStringCheat = center of right region
else Set PointStringCheat = center of left region
Unit - move ~the unit variable[~the integer~]~ to PointStringCheat
Set ~the boolean[~the integer~]~ to true
 
Status
Not open for further replies.
Top