I’m creating loot roll system. Some chests with the loot have less items, some have more.
So, I want to create a loop that checks how many item rolls left. On output I want to get the same number of different variables.
For example, if the chest contains 5 items, I want it to return me 5 variables $clothingloot1, $clothingloot2, $clothingloot3, $clothingloot4, $clothingloot5. Each of these variables should store information that was given inside the loop
So I need to change the variable inside the loop with each step and save it for later use.
That’s the code that I have atm, but it doesn’t work:
<<for _g to 0; _g lt $rewardscount; _g++>>
<<set $clothingloot[_g] to $lootrange1.pluck()>>
I’ve just found it’s possible to create variables using other variables.
In the example below I created temporary variable _t and stored my desired dynamic variable’s name in it "$clothingloot"+_x
Then I used a weird <<print>> technique. It doesn’t print anything, but it’s needed to settle the right name of the variable.
As a result, it creates a new variable with each loop step. $clothingloot1, $clothingloot2, etc.
Each variable is a randomly picked item with it’s own values (from items list $commonloot).
<<for _x to 1; _x lte $rewardscount; _x++>>
<<set _t to "$clothingloot"+_x>>
<<print "<<set "+_t+" to $commonloot.pluck()>>">>