0 votes
by (710 points)

I have an array containing various strings that are not dialogue - i.e. You see an apple, You see a pear, etc. - and I want to add a dialogue string "I like apples." To the same array.

I have two questions:

1. How can I apply CSS markup just to the dialogue string? I tried to do this by pushing @@.player;"I like apples"@@ to the array, but it doesn't work, I assume because of synthax reasons.

2. How can I make sure that the dialogue has quotation marks around it?

<<set $items to ["apples","pears","figs"]>>
/*<<set $items to $items.push(@@.player;"I like apples"@@)>>*/
<<for $i = 0; $i < 5; $i++>>
<<print either($items)>>
<</for>>

 

1 Answer

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

The markup you're attempting to push into the array is a string, so you have to quote it in some fashion.  NOTE: The <Array>.push() method alters the array and returns the new length, so you do not need or want to assign the result back to the variable.

 

Using double quotes

The nested double quotes must be either escaped by a backslash or replaced with something else (e.g. the double quote entity &quot; or the quote markup <q>...</q>).  I'm simply going to show how to escape the nested quotes here.

<<run $items.push("@@.player;\"I like apples\"@@")>>


Using single quotes

The double quotes do not need to be escaped and there are no nested single quotes.

<<run $items.push('@@.player;"I like apples"@@')>>

 

...