0 votes
by (510 points)

Hi, i want to make simple system to random pickup array with monsters, i'm make simple code:

<<set $RndEnemy to random(5)>>

<<set $Monster to "$MonsterName"+$RndEnemy+".random()">>

$Monster

on forum i read about how make this, but now i dont know where is the link...
It's work fine, all text sum in one greate.

But it's make $MonsterName1.random in text style, not like array link.

1 Answer

+1 vote
by (44.7k points)
selected by
 
Best answer

There are a couple of ways to do that, but the best is probably like this:

<<set $Monster to State.variables["MonsterName"+random(5)].random()>>

"State.variables" is an object which holds the values of all story variables (the ones that start with "$") in SugarCube.  The string inside the brackets tells it which variable to get the value of, and then the ".random()" is applied to that that variable's array.

Hope that helps!  :-)

by (510 points)
Yes! It's works! Thank you!)
...