First Off I will be honest, I don't know much about what I am doing.
So I will give you what may be important information first. I am using "Twine 2.1.0 & Sugarcube 2.12.1."
Now off to the question.
I am looking to use arrays or recall their information multiple times, for example, the array:
<<set $Random to either("Koolaid","Pie","Can food")>> and then use the array to give a specific variable an identity <<set $Item1 to "$Random">> and then use that same array again but to be set with another variable <<set $Item2 to "$Random">>, This worked if I use the array once again in the middle of the passage, however, the problem came up when displaying the "Item1 and Item2" variable again in another passage.
I am not sure if I am doing this right, so feel free to recommend an alternative for what I am trying to do, the concept is that once a player clicks on a link the variables would change each time he clicks the same link again, becoming something different each time.
Comments
<<set $PlyrTrait to Array.random($Quirks)>>
<<print $PlyrTrait>>
Did some fiddling around and came up with this, still doesn't work but at least it is an actual array. (I think before was just a basic either function) I need to be able to change the Var inside the array what's it's pulled from the array. The only way I think of it ends up with a hundred if-then statements/
There's a few way to do that; one is to have the either() function run as a part of the link you describe later. Another is to use an array. I would recommend the array method personally. There's one other choice you'll need to make, and that's whether you want the computer to put the card back in the box after picking it, meaning the card can come up again, or whether you want it to be left out of the box. I'll detail how to do both below.
One other thing:
This code works, but probably not the way you want it to or for the reasons you want it to. You're storing a the name of the variable $Random as the variable $Item1. This is probably not what you're trying to do. The code you probably want is without quotes; this will save the referenced variable's value to the new variable instead of its name.
For example:
Yields "$x1", while
Yields "2"
So here's some code:
Using either():
Using <array>.random():
Using <array>.pluck():
In the code below, the value, after being selected, is removed from the array completely. This means you need a contingency plan for when the array runs out of values. We'll use a simple <<if>> statement in the below example.
I just saw this. I posted a big ol' thing.
Anyway,
Is not correct syntactically, at least for what you want to do. The value in the parentheses of the <array>.random() method is for defining a range of the values in the array to include. The <array> part of the method should be the name of the array variable. Note that arrays are zero-based, meaning the first value is 0, not 1.
Will select a random value from the $Quirks array and pass it to the $PlyrTrait variable.
By contrast:
etc.
Also
That extra comma at the end isn't going to do you any favors, so get rid of it.
I hope this makes sense, I am generally new at this but thought it would be a unique project.
Also the above is just an example not an effort filled attempt
Thank you! I have seen your responses on several other discussions it seems such a waste for you to have to answer such a simple question, yet still. Thankyou.
That's one question answer to my confusing game theory above.
Oh and thank @Chapel
<<if ["Smoothtalker","Socialite"].contains($PlyrTrait)>> <<set $Soc += (5)>> <<endif>>hoping the 5 would be a random number between 1-5Currently try to get a hang of things
NVM fix was (random(5))
The <Array>.contains() method has been deprecated for a while now. Use <Array>.includes() instead.