Using Sugarcube 2.21.0
Currently, I can’t pass the $hand object to the $activeCard object. I’m trying to do the Stupid Print Trick:
There is a heavy door in front of you. <<nobr>><<for _i=0; _i< $hand.length; _i++>> <<='<<button "' + '$hand[_i].name' + '">><<set ' + '$activeCard' + ' = ' + '$hand[_i]' + '>><<script>>state.display(state.active.title, null, "back")<</script>><</button>>'>> <</for>><</nobr>> <<switch $activeCard.suit>> <<"cups">>You try to sweettalk the door, but it ignores your pleas. <<"swords">>You attempt to pick the lock on the door... <<"wands">>You smash the door open! <<"coins">>You study the door for weaknesses... <<default>> <</switch>> [[Do it|DoorResult]]
When I force the ‘$hand[_i]’ variable to 0,1,or 2, it works, but I can’t seem to dynamically generate the different variables. The current error is “bad evaluation: Cannot read property ‘suit’ of undefined”
- How can I dynamically generate the buttons so that correspond to cards in hand
- Is there a better way to denote the card they want to play without passing it to $activeCard? My ultimate goal would be to create a challenge widget or some function that could accept arguments and clean up the individual code passages.
Thanks for any help!!