/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!")
ID:161170
Jun 7 2008, 4:18 pm
|
|
Alright, how would I go about storing all of the questions and answers to a bunch of questions without doing this:
/obj/Questions Perhaps something like this (not DM): questions = ("What?", "Cool!", |
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?") |
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: 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 And later, I have: proc And even later: Check(T as text,var/mob/M) 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. |
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.