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

For loops question.

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
  • Update Income
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (Number of players), do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Player((Integer A)))) and do (Actions)
            • Loop - Actions
              • Game - Display to (All players) the text: incoe
              • If ((Unit-type of (Picked unit)) Equal to Gold Mine) then do (If ((Unit-type of (Triggering unit)) Equal to Gold Mine) then do (Player - Set (Owner of (Picked unit)) Current gold to (((Owner of (Picked unit)) Current gold) + 1)) else do (Do nothing)) else do (Game - Display to (All players) the text: nope)

I'm trying to give 1 gold to each player that owns a gold mine, but this trigger doesn't seem to fire properly even though I have gold mines made. Any idea what the problem is?
 
Level 12
Joined
Dec 2, 2016
Messages
733
  • Update Income
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (Number of players), do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Player((Integer A)))) and do (Actions)
            • Loop - Actions
              • If ((Unit-type of (Picked unit)) Equal to Gold Mine) then do (If ((Picked unit) Equal to (Constructed structure)) then do (Player - Set (Owner of (Picked unit)) Current gold to (((Owner of (Picked unit)) Current gold) + 1)) else do (Do nothing)) else do (Game - Display to (All players) the text: nope)
All I added was the check to see if it's a constructed structure and it's no longer working. Does that not mean it's finished constructing?
If I don't check to see if it's finished, people can build gold mines right before the minute turns and get income then cancel the gold mines and still keep their resources.
 
Level 14
Joined
Nov 30, 2013
Messages
926
  • Update Income
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (Number of players), do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Player((Integer A)))) and do (Actions)
            • Loop - Actions
              • If ((Unit-type of (Picked unit)) Equal to Gold Mine) then do (If ((Picked unit) Equal to (Constructed structure)) then do (Player - Set (Owner of (Picked unit)) Current gold to (((Owner of (Picked unit)) Current gold) + 1)) else do (Do nothing)) else do (Game - Display to (All players) the text: nope)
All I added was the check to see if it's a constructed structure and it's no longer working. Does that not mean it's finished constructing?
If I don't check to see if it's finished, people can build gold mines right before the minute turns and get income then cancel the gold mines and still keep their resources.
Constructed structure doesn't work for a time-event trigger.

It's only used for selecting the newly built structure as variable for the trigger, with the event of 'A unit finished construction.'
 
Level 12
Joined
Dec 2, 2016
Messages
733
The easiest way that I know of is to use the unit finishes building event and save a finished_building variable.

Can be done with a unit indexer or hashtables, if you do not know how to use that there is no way, probably.

  • Create Hash
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Goldmines = (Last created hashtable)
  • Builds gold mine
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Gold Mine
    • Actions
      • Hashtable - Save Handle Of(Last created unit) as 0 of 0 in Goldmines

Am I doing this right, I found a small tutorial on hashtables but it isn't making that much sense to me. I don't understand 'as 0 of 0' Or does the 1st integer represent an index, and the other int represent the max index?

If I did this right, did it save the last constructed unit to the hashtable?

And if it did, I guess I could check how many objects are in the hashtable and then declare that my gold income?
 

Chaosy

Tutorial Reviewer
Level 41
Joined
Jun 9, 2011
Messages
13,239
You're on the right track.

What you want to do is save that this structure is completed, and bind that to the unit.

So you want to save "true" (since it is built now, and false is the default value you do not need to set that)

Then, you need to choose where to save.

In your example you chose 0, 0 which does not really help since each unit will overwrite the last one by saving at the same location in the hashtable.

Luckily, each unit has an unique number, known as the "handle".

So, save "true" at positions "handle of constructed unit", "0"

You then load that value from the hashtable in your other trigger.
 
Level 19
Joined
Oct 17, 2012
Messages
859
@Rugarus The following is a better solution to your issue:

1 integer array
1 condition
No need to search the entire map for the correct units every period (which is an expensive operation with a lot of units)

Note: For the lower income trigger, you might want to also check if the building was already constructed as to not lose income falsely.

  • Up Income
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set Income[(Player number of (Triggering player))] = (Income[(Player number of (Triggering player))] + 1)
  • Add Gold
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Player - Add Income[(Player number of (Picked player))] to (Picked player) Current gold
  • Lower Income
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set Income[(Player number of (Triggering player))] = (Income[(Player number of (Triggering player))] - 1)
 
Last edited:
Status
Not open for further replies.
Top