0 votes
by (470 points)

hi guys. How i can push variable into an array in SugarCube1? 

i have this code:

<<set $inv_lab to []>>

<<set $meteorite = {
	"available": "False",
	"name": "Rock",
	"weight": 30,
	"cost": 1000
}>>

<<set $inv_lab.push("$meteorite")>>

but i get this

Error: <<set>>: bad evaluation: Cannot read property 'push' of undefined

what im doing wrong? 

1 Answer

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

Which version of SugarCube 1 are you using, be cause I tested your example in v1.0.35 and their were no errors.

I suggest not using underscores in your story variable names, as it has a special meaning in SugarCube 2.x and may cause you issues if you ever decided to upgrade to it.

<<set $invLab to []>>

 

by (470 points)

yes, it works! thank you smiley

...