How i can push variable into an array in SugarCube1?

0 votes
asked Jul 19, 2017 by acki (240 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
answered Jul 19, 2017 by greyelf (65,350 points)
selected Jul 19, 2017 by acki
 
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 []>>

 

commented Jul 19, 2017 by acki (240 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.
...