How to track and set a specific value in an array variable

Solu9

You can change this now in User CP.
Reaction score
216
The title may be misleading.

Lets say I assign 5 different units to an array unit variable:
set Unit_Array[1] to Monster-A
set Unit_Array[2] to Monster-B
set Unit_Array[3] to Monster-C
set Unit_Array[4] to Monster-D
set Unit_Array[5] to Monster-E

Great!
Now I want a variable which stores a real for use to calculate how fast a timer will count later on.
set TimeSpeed_Array[1] to 1
set TimeSpeed_Array[2] to 1
set TimeSpeed_Array[3] to 1
set TimeSpeed_Array[4] to 1
set TimeSpeed_Array[5] to 1

Awesome!
Now if Unit_Array[X] picks up Boots of Speed then the TimeSpeed_Array for that specific unit will be set to (TimeSpeed[X] - 0.25) (that's 0.75 in case it was too hard to calculate yourself)

Now to the tricky part.

Events - a unit acquire an item
Conditions - item acquired equal to Boots of Speed
Actions -
If-
acquiring unit equal to Unit_Array[?]
Then-
set TimeSpeed_Array[?] to (TimeSpeed_Array[X] - 0.25)
Else-

You notice the two question marks up there? Thats the question.
----------------------------------------------------------------------------------------------------------


The timer that expires is run in a different trigger and there is a timer for each of the units involved. I take this can be set in a timer array variable as well. But let's leave that for now.
 

maxou

You can change this now in User CP.
Reaction score
15
2 ways to do it :

1st way :

when you save units :

set Unit_Array[1] to Monster-A
set Unit_Array[2] to Monster-B

add this line

Save 1 as custom value of Monster-A
Save 2 as custom value of Monster-B

Then the [ ? ] becomes [Custom value of acquiring unit]


2nd way :

for each (integer A) from 1 to 5
Actions -
If-
acquiring unit equal to Unit_Array[Integer A]
Then-
set TimeSpeed_Array[Integer A] to (TimeSpeed_Array[X] - 0.25)
Else-

Skip remaining actions (this action is placed after the if/then/else, in the (for each) loop.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
612
Tbh using a For loop seems more efficient if you're only using it for a few units. Otherwise hashtables would be faster.
 

thorhunter

You can change this now in User CP.
Reaction score
32
The timer that expires is run in a different trigger and there is a timer for each of the units involved. I take this can be set in a timer array variable as well. But let's leave that for now.

I don't think you even need seperate timers for each unit, franky I wouldn't even use a timer for this one. Just a trigger that keeps running itself, unless you want to create some sort of time gaps between turns, in this case one universal timer will suffice (unless you want to display timers, but there are better ways to do it).

2nd way :

for each (integer A) from 1 to 5
Actions -
If-
acquiring unit equal to Unit_Array[Integer A]
Then-
set TimeSpeed_Array[Integer A] to (TimeSpeed_Array[X] - 0.25)
Else-

Skip remaining actions (this action is placed after the if/then/else, in the (for each) loop.
This is the way I basically do things up (no idea why you need to skip remaining actions, could you explain that?) I've never experienced any process problems, even upon reaching editor's 100k operation limit (used about 6 loops one within another), and game was smooth on multiplayer, so I think this is the last thing you should worry about when choosing a way that you feel comfortable with.
 

Solu9

You can change this now in User CP.
Reaction score
216
I don't think you even need seperate timers for each unit, franky I wouldn't even use a timer for this one. Just a trigger that keeps running itself, unless you want to create some sort of time gaps between turns, in this case one universal timer will suffice (unless you want to display timers, but there are better ways to do it).

Each unit will have different timers based on circumstances.
I'll forward you to the thread about the actual system if you are interested.
http://www.thehelper.net/threads/turn-based-map-test.156716/
 

thorhunter

You can change this now in User CP.
Reaction score
32
I probably misunderstood, I thought you refer to 'countdown timers' while you actually refer to integer array, is that correct?
 

Solu9

You can change this now in User CP.
Reaction score
216
I probably misunderstood, I thought you refer to 'countdown timers' while you actually refer to integer array, is that correct?

The real variable controls how fast an expiring timer will... well, expire. The reason it's a real is so it can be imported to the "set timer" without any work arounds. I guess.
 

thorhunter

You can change this now in User CP.
Reaction score
32
Yes, I see what you did there but in this case instead of using seperate timers for each unit you can have like one trigger that loops every second and decreases all real timer values by 'timer speed' value (each character has it individually), then - depending if the value reaches some point - allows action for this unit and resets its 'timer' variable. I checked the map and there's an issue of unpaused unit that I don't take action with counterattacking every enemy that comes nearby.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top