So I have this code, which works to cycle through things I like and display them.
:: StoryTitle
Simplified test
:: StoryData
{
"ifid": "E5D6D657-EB7B-41E1-BB94-A1F539B702C5",
"format": "SugarCube",
"format-version": "2.30.0",
"start": "The Start"
}
:: StoryInit
<<set $likes = [
"I like pizza.",
"I like ice cream.",
"I like pop.",
"I like soda.",
"I like cola.",
"I like cookies.",
"I like pretzels.",
"I like candy.",
"I like cereal.",
"I like lemonade.",
"I like licorice.",
"I like chocolate.",
"I like dark chocolate.",
"I like white chocolate."
]
>>
:: StoryMenu [StoryMenu]
:: Widgets [widget nobr]
<<widget picklike>><<nobr>>
<<set $idx = random(0,$likes.length/2)>>
<<set _thislike = $likes[$idx]>>
<<run $likes.delete(_thislike)>>
<<print _thislike>>
<<run $likes.push(_thislike)>>
||||$likes.length
<</nobr>>
<</widget>>
:: The Start
<<picklike>>
[[Like more stuff.|The Start]]
:: PassageFooter
:: PassageHeader
:: Stylesheet [stylesheet nobr]
The problem comes when I want to say “Again, I like…”
Adding in this code
<<if not _thislike.contains("Again, ")>><<set _thislike = "Again, " + (_thislike)>><</if>
Creates a situation where <<run $likes.push(_thislike)>> doesn’t work! But if I put a <<run likes.push(“!”)>> before it, everything works as intended.
I’m glad I got stuff to work, but I’m wondering why doesn’t the first run $likes fire with the modified string, and how would I fix that?
When you do this, is _thislike defined before the <<run $likes.push(_thislike)>>?
(unrelated, but if you tag a passage with nobr, you don’t need to also use the <<nobr>> macro)
EDIT : after messing around with the code, I’ve made a second widget with the Again, element (though in a way that isn’t added to back to the array).
TweeGo doesn’t execute the contents of a (standard) Passage. It only assembles the contents of the Passages together, along with a Story Format Template, to generate a Story HTML file.
A (standard) Passage can contain pure nonsense and TweeGo wouldn’t care, the runtime engine of the selected Story Format on the other hand will.