Noob question about list and array.

Hi i m very new to Unity and programing in generale , i did some python coding before and i m wondering if Unity have any list and tuples equivalent ?

i d like to make a very simple " guess the answer" game.With simple YES or NOT choice , the idea is to put each question and answer together as a tuple which will be inside a list of questions…
?
any ideas

thank you.

please forgive my poor english.

Yes, you have access to Arrays, Lists, ArrayLists, etc depending on whether you use JS or C#. Search the scripting reference docs for detailed info.

Hi i found this pseudo code to make make a quiz games for my kids, does anyone can give me a clue to translate it in unityjavascript ?

int i=0; to get the question number
Array[20,20] quest;//20 questions and their answers
bool lost=false;

while(lost==false i<=19)
{
ask quest[i,i];
if(wrong answer)
{
lost=true;
}
else
{
i++;
}
}

if(lost=true)
{
say sry u lost
}
else
{
say congrats u won
}

here’s something you can build on that will demonstrate how you can store the questions and answers in a single array then access them…

class Item {
	var question : String;
	var answer : String;
}

var questions : Item []; //Exposes array of Item in inspector where you can edit question/answer data

function Start () {
	for (questionNumber = 0; questionNumber < questions.length; questionNumber ++) {
		print (questionNumber);
		print (questions[questionNumber].question);
		print (questions[questionNumber].answer);
	}
}

just figure out how you will display the questions…

questions[questionNumber].question

then figure out how to wait for the player’s answer
then compare the player’s answer to

questions[questionNumber].answer

Thank you Atomic bob,

When you say “in a single array” do you mean Q and A in the same string ?

i m not good enough yet :frowning:

is possible to use the Gui stuff to click ? what about multiple answers propostions ?

Thx

the Q and A are separate strings that are members of the same array.

we are basically making our own data structure in the first four lines with a type we called “Item”

class Item { 
   var question : String; 
   var answer : String; 
}

then creating an array of them…

var questions : Item [];

note: in “Item”, you could have any amount of variables which could be strings, floats, booleans, gameObjects, or whatever

copy and paste that simple script i wrote save it, place an empty gameobject into the hierarchy and attach the script you saved to it . when you look in the inspector you should see your variables and be able to edit them. set the size of the array to the amount of questions you want to ask and enter the data in the boxes that pop up which represent the Q and A… the actual data does not need to be hard coded into the script

after entering that data, run your game… nothing spectacular will happen onscreen, but in the console window it will print out all the data you entered in the inspector.

in the script I wrote, questions represents the entire array which holds the Q and A.

questions[questionNumber].question

represents your question and

questions[questionNumber].answer

represents your corresponding answer

Yes, you should be able to use the GUI stuff; however, I haven’t used it enough to suggest exactly how to do it

You should be able to do multiple answers with this method, you will just have to add additional members to the “Item” we created or make “answer” in “Item” an array of Strings instead of a single String.[/code]