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 (156k 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

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.