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
613
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 The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    Sticking with the desserts for now the latest recipe is Fried Apple Pies - https://www.thehelper.net/threads/recipe-fried-apple-pies.194297/
  • The Helper The Helper:
    Finally finding about some of the bots that are flooding the users online - bytespider apparently is a huge offender here - ignores robots.txt and comes in from a ton of different IPs

      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