• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Triggering Player Variable

Status
Not open for further replies.
Level 5
Joined
Sep 19, 2006
Messages
152
Do commands such as "Player Number of Triggering Player" create more "computer drain" in very long triggers? If so, is it better than to set a variable at the start of the trigger (something such as Set X = Player Number of Triggering Player), as in the following example:

Untitled Trigger 001
Events
Conditions
Actions
Player - Set (Triggering player) Current gold to 750
Set Hero[(Player number of (Triggering player))] = (Last created unit)
Set Unit[(Player number of (Triggering player))] = (Sold unit)
Set Target[(Player number of (Triggering player))] = (Target unit of ability being cast)

or

Untitled Trigger 001
Events
Conditions
Actions
Set PlayerNumber = (Player number of (Triggering player))
Player - Set (Player(PlayerNumber)) Current gold to 750
Set Hero[PlayerNumber] = (Last created unit)
Set Unit[PlayerNumber] = (Sold unit)
Set Target[PlayerNumber] = (Target unit of ability being cast)
 
Level 5
Joined
Sep 19, 2006
Messages
152
Thanks for the replies, fellas; but in truth I'm quite noobish at all of this, and all the GUI talk is Greek to me.

Of the 2 examples listed in my post, which would be the more efficient? If it's the latter, would subscribing the same variable PlayerNumber to EVERY trigger pose a problem?
 
Level 6
Joined
Mar 2, 2006
Messages
306
okay, he gets it, gui bad, jass divine... good answer for every gui question...

yes you should save the function result in a variable instead of calling the function 5 times. aside from making your trigger code more efficient, you must know that some of those (Event Response - XXX) functions lose their value after a smallest wait...

mentioning waits brings us to your second question:
would subscribing the same variable PlayerNumber to EVERY trigger pose a problem?
generally, yes. problem lies in waits. whenever you say wait 5 game-time seconds, other triggers will get executed within those 5 seconds (perhaps hundreds), and that can include other instances of the waiting trigger. in a plastic example:
  • set X = 7
  • Wait 5 game-time seconds.
  • Do something important with X
after the wait, X may not be 7 at all! (if no other trigger uses X, it should be 7, but if 20 triggers use X for their purposes, no way it will stay 7 after those 5 sec)

if your map will use complicated triggers, you will soon have to learn about local variables...

and one more word of advice: dont call your global variable X, i or s; always give it a nice and descriptive name.
 
Level 5
Joined
Sep 19, 2006
Messages
152
Thanks, guys! If I'm understanding the lessons correctly, then using a command like

local integer X //or something more creative than X, as edge[d1] points out
set X = (TriggeringPlayer) //this is just for show, I know it's really something like GetConvertedID...blah.blah...

will generate a unique version of X for each player executing the trigger, even if it's simultaneously?

Set Hero(X) = last created unit, for example, would then also be unique for each player applying this trigger?

I really appreciate all the feedback!
 
Level 11
Joined
Jul 12, 2005
Messages
764
But you cannot use them as globals! It won't appear on the variable list. You have to put the correct GUI-to-JASS converted lines instead of GUI actions. Like:
local integer n = GetPlayerId(GetTriggeringPlayer())
set udg_Hero[n] = GetLastCreatedUnit()
set udg_Unit[n] = GetSoldUnit()
...
All of them as custom script.
 
Status
Not open for further replies.
Top