I just need to know if it is possible to make an array and have it use different phrases or sayings like speech. something like:
<<set $arrayname to ["Hello there", "Hi", "What's up", "How's it hanging"]>>
either($arrayname)
would this work?
I just need to know if it is possible to make an array and have it use different phrases or sayings like speech. something like:
<<set $arrayname to ["Hello there", "Hi", "What's up", "How's it hanging"]>>
either($arrayname)
would this work?
This is how array are coded, yes.
Thought either($arrayname)
won’t do anything. You’d need to use a macro to have it shown on the page:
<<print either($arrayname)>> -> will print one of the elements
<<set _var to either($arrayname)>> -> will save one of the elements in a temporary variable, which you can use to show it on the page
<<if either($arrayname) is VALUE>>
...
Additional to Manon’s advice.
SugarCube adds a number of “random” related methods to the Array, like the <Array>.random()
method, which can be used to achieve similar outcomes as the either()
function…
eg. <Array>.random()
based variations of Manon’s examples.
<<print $arrayname.random()>> -> will print one of the elements
<<set _var to $arrayname.random()>> -> will save one of the elements in a temporary variable, which you can use to show it on the page
<<if $arrayname.random() is VALUE>>
The other “random” related Array methods are: <Array>.randomMany()
, <Array>.pluck()
, and <Array>.pluckMany()
This worked perfect thank you for the help.
Ill be sure to remember that for the future thank you. I wonder now though if there is a way i could make each phrase in the array a different color when they print out. Would a span work within the array?