• 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.

Question on Efficiency

Status
Not open for further replies.
Level 15
Joined
Jul 9, 2008
Messages
1,552
i have a trigger that im going to use on detecting when a building dies if its = to what ever builder do actions

would it to be more sufficent with a heap of if/then/else on each building or create a truigger with the building as a condition for each one
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
If the procedure run for each is simlar then both methods will cause a lot of procedural coupling. If they are simlar consider some sort of system which uses a hashtable to map the building type to some data values run.

This would give a look up time of O(1) and also reduce code complexity.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
He is saying that you could save the unit type of the builder for the unit type of the dying unit.

Unit types are integers so you'd use something like this:
  • Custom script: call SaveInteger(hashtable, bID, 0, uID)
Where bID is the unit type id of the building and uID is the builder's unit type id. Check the raw codes in object editor, press Ctrl + D.

When a building dies:
  • Custom script: set unit type = LoadInteger(hashtable, GetUnitTypeId(GetTriggerUnit()), 0)
Or you could save the builder tpes into an array and save the array index for the building types.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Then attach it to the handleID for the building then. It would save you doing many specific unit comparisions.

A hashtable has a far better lookup complexity than itterating through a list of things to compare to (aka, Linear Search).

Out of the 2 inefficient options you gave, the multiple selection (case like) is the best as it does not have a constant complexity of O(n) but instead has a complexity rage of O(1) to O(n) which will save time. In addition it creates less interpreter threads which saves time.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
i have a trigger that im going to use on detecting when a building dies if its = to what ever builder do actions

im talking about a building not builder

Okay.

Initialize
  • Custom script: call SaveInteger(hashtable, bID, 0, goldGiven)
When a building dies:
  • Custom script: set integer = LoadInteger(hashtable, GetUnitTypeId(GetTriggerUnit()), 0)
Add the loaded value to the gold of each player.
 
Level 17
Joined
Apr 3, 2010
Messages
1,101
No Hashtables are inbuilt in the Gui -- In the drop down on sections It has HAshtable-- Create a hashtable
Then you want to save the hashtable as a variable for refernce then you want to follow the above -.-. Preplaced buildings do nothing to the code.

The only custom code which was suggested was For save and for getting id on death-Basically the recording of the buildings . But the actualy creation can be done in gui.



A Hashtable is basicalyl a grid used for indexing

I.E

Y 1 2 3 4 5 6 7 8 9 10
X
1 H H H H H H H H H H
2 H H H H H H H H H H
3 H H H H H H H H H H
4 H H H H H H H H H H
5 H H H H H H H H H H
6 H H H H H H H H H H
7 H H H H H H H H H H
8 H H H H H H H H H H
9 H H H H H H H H H H
10 H H H H H H H H H H


Etc

H=Handle

A HandleID is a referce to a point of data or unit

Leaks are unused Handles which arn't removed.
So if you know what a leak is and how to destroy it now you know what exactly your destroying. And will be able to relate to how a Handle is
Points
Integers
Strings
etc....

You can reference things for indexing via hashtable
You can save handles to it
And Recall handles for it

_- So its like a data storage.
 
Status
Not open for further replies.
Top