• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] A Single Long Trigger or Many Small Triggers

Status
Not open for further replies.
Level 3
Joined
Sep 10, 2012
Messages
39
(Solved) A Single Long Trigger or Many Small Triggers

Greetings. I am attempting to create a stat system that assigns the stats to the units when they enter the map area. The question I am asking, then, is this: in-game, is it faster to have a multitude of smaller triggers to check the unit type, or would it be better to have one rather expansive trigger check through a multitude of unit types?

Edit: not sure it makes any difference, but felt I should say that I'm checking unit types via If/Then/Else functions.
 
Last edited:
Try to create as less triggers with same event as possible. So in your case, maybe 1 trigger is better.

I don't know your triggers, but looping through many unit types doesnt sound very good. Maybe best would be without check.

You could store data into hashtable with key[unitType]. Then when a unit enters world, just set a variable to UnitType of EnteringUnit and load the value out of hashtable. Or field is set or will return 0.
 
Level 3
Joined
Sep 10, 2012
Messages
39
Hmm. Well, I'll try test it out at some point in the near future, but an example would be extremely helpful - my knowledge of JASS is terribly poor.
 
Last edited:
Short example. We want to save a text to UnitType of footman. And whenever a unit enters the world, we display a message to know if it was a footman.

First in init, we save a string into hashtable with key of our UnitType, and later we load the string of our table of key UnitType. (as said actually UnitType it's an integer)

Variables are needed, but I think you can read out the type by their names. ("udg_" is the used prefix for variables created with the variable editor if you work with Custom script/JASS)

Init-trigger:
  • Custom script: set udg_hash = InitHashtable()
  • Custom script: call SaveString(udg_hash, 'hfoo', 0, "Hello, I'm a footman!")
Enter world
  • Custom script: local string s = LoadString(udg_hash, GetUnitTypeId(GetTriggerUnit()), 0)
  • Custom script: if s != null then
  • Custom script: call BJDebugMsg(s)
  • Custom script: else
  • Custom script: call BJDebugMsg(unknown unitType)
  • Custom script: endif


Init
  • Hashtable - Create New Hashtable
  • Set hash = LastCreatedHashtable
  • Set unitTypeVariable = Footman
  • Custom script: set udg_integerVariable = udg_unitTypeVariable
  • Hashtable - SaveString("Hello, I'm a footman!", integerVariable, 0, hash)
Enter
  • Custom script: set integerVariable = GetUnitTypeId(GetTriggerUnit())
  • Set stringVariable = Load(integerVariable, 0, hash)
  • If stringVariable is not <Empty String> then
  • Game - Display stringVariable
  • else
  • Game - Display "Unknown type"

Try it out, hope there are no syntax errors. After, if you still have problems you just can ask again.
 
Status
Not open for further replies.
Top