- Jan 19, 2018
- 38
- 70
So I thought I'd try to make a simple multiple choice name guessing game as my first ever Twine game (or game at all for that matter), as of couple of days ago I hadn't done any programming ever. I've been tinkering about finding out how things work and what I need to do, and now I've hit a bit of a roadblock.
I can't figure out how to set a variable to a random value from one array without it being the same as a value present in a different array.
Basically I'm trying to make 4 unique options but it keeps coming out similar to this:
Below is the code I'm currently using. It's not the actual game, just one passage out of many in a dev build where I figure stuff out.
EDIT:
I've done some improvements to the code with the help of the Reddit Twinegames Discord:
Maybe not the most elegant of coding, but it works so far and it's quite satisfying cobbling together a Frankensteins monster of a game.
Oh, and $starList changed name to $namelist and is set in an "INITIAL-SETTINGS" passage which is the starting passage, the above code is for the "GAME-PHASE" passage.
I can't figure out how to set a variable to a random value from one array without it being the same as a value present in a different array.
Basically I'm trying to make 4 unique options but it keeps coming out similar to this:
Might as well describe how game the will work: An image of a random pornstar is displayed, below it are four radiobuttons with the correct answer and three random incorrect ones. No plot at all, and if I'm correct it should be doable in three passages.Maserati
Sarah Louise Young
Sarah Louise Young
Lisa Ann
Below is the code I'm currently using. It's not the actual game, just one passage out of many in a dev build where I figure stuff out.
Code:
<<nobr>>
<<set $imgPath to "./images/">>
<<set $currentOptions = []>>
<<set $pastStar = []>>
/* LIST OF ALL OF THE GIRLS */
<<set $starList = ["Ana Foxxx",
"Belladonna",
"Christy Mack",
"Cory Chase",
"Gianna Michaels",
"Lisa Ann",
"Maserati",
"Sarah Louise Young"]>>
/* POPULATE THE 4 ANSWER OPTIONS */
<<set $option1 = $starList.random()>>
<<set $currentOptions.push($option1)>>
<<set $option2 = $starList.random()>>
<<for _option2 to 0; _option2 is $currentOption; _starList.random++>>
<<set $option2 = $starList.random()>>
<</for>>
<<set $currentOptions.push($option2)>>
<<set $option3 = $starList.random()>>
<<for _option3 to 0; _option3 is $currentOption; _starList.random++>>
<<set $option3 = $starList.random()>>
<</for>>
<<set $currentOptions.push($option3)>>
<<set $option4 = $starList.random()>>
<<for _option4 to 0; _option4 is $currentOption; _starList.random++>>
<<set $option4 = $starList.random()>>
<</for>>
<<set $currentOptions.push($option4)>>
/* DEFINE THE CORRECT ANSWER */
<<set $correctStar = $currentOptions.random()>>
/* ADD CURRENT CORRECT ANSWER TO LIST OF PAST ONES */
<<set $pastStar.push($correctStar)>>
/* DISPLAY THE CORRECT ANSWERS RANDOM IMAGE */
[img[$imgPath + $correctStar + " " + random(1, 3) + ".jpg"]]
/* CHECK NAME OPTION AND CURRENT CORRECT ANSWER*/
<</nobr>>
Name options
<<print $option1>>
<<print $option2>>
<<print $option3>>
<<print $option4>>
correct star
<<print $correctStar>>
EDIT:
I've done some improvements to the code with the help of the Reddit Twinegames Discord:
Code:
<<nobr>>
<<set $imgPath to "./images/">>
<<set $currentOptions = []>>
/* SET OPTIONS 1 THROUGH 4 */
<<set _names = clone($nameList)>>
<<set _names.shuffle()>>
<<set $option1 = _names[0]>>
<<set $option2 = _names[1]>>
<<set $option3 = _names[2]>>
<<set $option4 = _names[3]>>
/* SET $currentOptions TO OPTION 1 THROUGH 4 */
<<set $currentOptions.push($option1)>>
<<set $currentOptions.push($option2)>>
<<set $currentOptions.push($option3)>>
<<set $currentOptions.push($option4)>>
/* DEFINE THE CORRECT ANSWER */
<<set $answer = $currentOptions.random()>>
/* ADD CURRENT CORRECT ANSWER TO LIST OF PAST ONES */
/* <<set $pastName.push($answer)>> */
/* DISPLAY THE CORRECT ANSWERS RANDOM IMAGE */
[img[$imgPath + $answer + " " + random(1, 3) + ".jpg"]]
/* CHECK NAME OPTION AND CURRENT CORRECT ANSWER*/
<</nobr>>
<<button $option1>> <<if $option1 is $answer>> <<goto [[CORRECT]]>> <<else>> <<goto [[WRONG]]>> <</if>> <</button>>
<<button $option2>> <<if $option2 is $answer>> <<goto [[CORRECT]]>> <<else>> <<goto [[WRONG]]>> <</if>> <</button>>
<<button $option3>> <<if $option3 is $answer>> <<goto [[CORRECT]]>> <<else>> <<goto [[WRONG]]>> <</if>> <</button>>
<<button $option4>> <<if $option4 is $answer>> <<goto [[CORRECT]]>> <<else>> <<goto [[WRONG]]>> <</if>> <</button>>
Oh, and $starList changed name to $namelist and is set in an "INITIAL-SETTINGS" passage which is the starting passage, the above code is for the "GAME-PHASE" passage.
Last edited: