ID:161170
 
Alright, how would I go about storing all of the questions and answers to a bunch of questions without doing this:

/obj/Questions
var question, answer

one
question = "BLAH"
answer = "YLAH"

two
question = "TWO!"
answer = "Look!"


Perhaps something like this (not DM):

questions = ("What?", "Cool!",
"When?", "Neat!")
Learn about lists from the DM Guide (which you should read in full) and DM Reference. You can use an associative list for what you want here.
Also, if you're not actually using the /obj graphically, then you can make it a datum (a simpler class) instead. You may wish to look into that as well.
In response to Kaioken
Alright, thanks. I toyed around with associative lists, but couldn't really figure them out. I kept getting a "bad index" error.

Edit: Figured it out.

Edit2:

Alright, so do I have to do this like:

Answers = ("What is 2+2?","What is 3-2?")

Answers["What is 2+2?"] = "4"
Answers["What is 3-2?"] = "1"
In response to Seraphrevan
What I'm looking for is exactly like "dictionaries" in other languages, such as Python.
In response to Seraphrevan
Hm, lets see if this can help:
var/list/Q = list("What is 2+2?" = "4", "What is my name?" = "GhostAnime", "Boo?" = "Ahh!")  //  =list(Entry = Value). 4 is a text because of the input() following:

var/question = pick(Q) // Randomly picks a Question from the Q list
if(input(question,"?") == Q[question])
world << "You're correct!"


Q[question] --> Q["Entry"] returns the Value, so:
Q["What is 2+2?"] --> returns "4"

Note that if the value in the [] brackets is a number, it returns the entry:
Q[1] --> returns "What is 2+2?"
Q[Q[1]] --> Q["What is 2+2?"] --> returns "4"


You can have multi-dimentional lists ( ex: Q=list("A"=list("B"="C")) ) and you can change the value of the list entry through what you did before:
Q["What is 2+2?"] = "4?" <-- the Entry's value "4" is now "4?"
In response to Seraphrevan
Again, please do read the documentation.
In response to GhostAnime
I'm using an "Add a Question" type of verb to test some stuff. It's something like:
mob/verb
TestList()
var/list/Answers = new()
var/Q = input("What is the question?","Question",null) as text
Answers.Add(lowertext(input("What is the answer?","Answer",null) as text))
while(alert("Is there another answer?","Answer","Yes","No") == "Yes")
Answers.Add(lowertext(input("What is the answer?","Answer",null) as text))
world << list2params(Answers)
for(var/x in Answers)
TestList.Add(params2list("[Q]=[x]"))


And later, I have:
proc
Start()
currentq = pick(TestList)
currenta = TestList[currentq]


And even later:
Check(T as text,var/mob/M)
var/c = 0
for(var/x in currenta)
if(findtext(T,x))
c++
if(c)
if(!M.correct)
world << "<font color=red><b>[M.name]</b> has gotten the correct answer!</font>"
M << "<font color=red>Correct! Correct answers included:</font>"
for(var/l in currenta)
M << "<font color=red>[l]</font>"
M.correct = TRUE
winners.Add(M)
else
M << "<font color=red>You've already gotten this correct.</font>"
else
world << "<b>[M.name]:</b> [html_encode(T)]"


No errors. Except for the one where it doesn't check the answer correctly. This system works perfectly for a pre-defined list. I just want to be able to add questions.

Edit: I figured it out, and it was so easy. I feel stupid.