ID:163048
 
I'm still looking for an example of coding for multiple choice questions in game. basically at this point I just want an npc or event to trigger a multiple choice question randomly from a list, then when the player picks a responce it tells the player wether he was correct, or false.

I've been looking around the site alot at demos and all that and I'm just not seeing and direct examples that could be modified to this purpose. THe daunting giant dictionary of commands is all that seems to maybe have what I need to get to my solution and I am a newb so that's just taking me quite a while to digest, but even telling me what part of the dictionary to look in would be helpful thanks.

Mike

obj/test_paper/verb/pop_quiz()
var/choice = input(usr,"2 times 2?","Question") in list("2","4","8","I don't know.")
// Ask [usr] the question "2 times 2?" in an input box with the title "Question",
// and give him the choices "2","4","8" and "I don't know."
if(choice == "4")
usr << "Correct."
else if(choice == "I don't know.")
usr << "Study study study."
else
usr << "Incorrect."
In response to DivineO'peanut
thanx that works, I wasn't quite sure what test_paper was referring to and how to define it, so I just made it /mob/verb/pop_quiz() for now to make it a user command, I'll play with it and see if I can get it to output a random quesstion and get it to be a mob triggered event, and what not, with rewards and penalties. But hey thanx alot, I've been stumped trying to find the various peices for that coding.

Mike
In response to Kichimichi
Uhm, test_paper was the name of the object, that's just an easier way to kick it down. But you would probaly recognize it as

obj
Test_paper
icon = 'objects.dmi'
icon_state = "Testpaper"
verb
Take_The_Test()
// This is where the other stuff would go


In response to DivineO'peanut
SO I've gotten to the point where correct answeres are rewarding gold and experience, now if I can figure out how to get a large question list to be drawn from randomly so it's not always the same question, I should be able to insert it anywhere I want to make it a key game mechanic.

Mike

mob/verb/pop_quiz()
var/choice = input(usr,"2 times 2?","Question") in list("2","4","8","I don't know.")

if(choice == "4")
usr << "Correct."
usr:MakeGold()
usr:GiveExp()
else if(choice == "I don't know.")
usr << "Study study study."
else
usr << "Incorrect."

proc
MakeGold()
var/obj/gold/G = new(loc) //create a new obj from the gold blueprint
G.amount = rand(1,100) //set its amount variable randomly
..()
proc
GiveExp()
var/exp = rand(1,10)
usr:experience += exp
usr << "You gain [exp] experience."
obj
gold
icon = 'gold.dmi'
var
amount = 10
verb
get()
set category = "Action" //obj/gold/verb/get()
set src in view(0) //src must be close
usr << "You pick up [amount] gold."
usr.wealth += amount //add to usr.wealth
del(src) //delete the gold
In response to Kichimichi
That may be a bit more complicated. You want a multi-dimensional associative list, whereas the format is <code>"question content"=list(list(answers),correct answer)</code> may require you to parse it a bit.

Seeing as you seem like the learning type (and not the ripping type), I'll supply you demo code:

var/list

/*
This list contains all of the randomly picked
questions, in the format I specified earlier.
It contains two example questions, which you
should expand upon.
*/

question_list = list(

/*
Ask "2 times 2", with the possible answers
"2","4","8".
*/

"2 times 2?" = list(list("2","4","8"),"4"),

"4 times 2?" = list(list("4","8","16"),"8"))

proc

/*
Parse a question from the question_list, and show
it to Target.

Args:
Target client/mob being showed the question.
QuestionContent The content of the question. e.g. "2 times 2?".

Returns:
1 if correct answer.
0 if answer not correct.
*/

ParseQuestion(Target,QuestionContent)
var/list/Answers = question_list[QuestionContent][1]
if(!Answers) return FALSE // No answers found for QuestionContent.
var/CorrectAnswer = question_list[QuestionContent][2]
if(!CorrectAnswer) return FALSE
var/GivenAnswer = input(Target,QuestionContent) in Answers
return (GivenAnswer == CorrectAnswer)


// Example usage of supplied code:
mob/verb/get_random_question()
var/RandomQuestion = pick(question_list)
var/Answer = ParseQuestion(usr,RandomQuestion)
if(Answer == TRUE)
src << "True."
else
src << "False."


I also suggest you do some research on lists and the <code>pick()</code> procedure.
In response to DivineO'peanut
Hey thanx alot, yeah im getting along with it, figuring out what works and what doesn't. I def want to be able to write my code all myself, just difficult to get past the first tutorials to the next level of them, they seem to go from really basic right into anthologies of code explanations, and the DM guide is kinda like learning chinese by looking at a dictionary but hardly ever seeing it used in example. To a certian extent I suppose I am ripping since, I'll take what in english would be

"the dog went down the road"
and converting it to
"the man went up the hill"

while much of what I'm doing is not from absolute scratch, I can't simply learn by definitions and leet speak discriptions, I have to sometimes get a jump ahead with an example tha shows where things work, and then I can figure out why playing with it and using some of this to go here and there.

I certianly wouldn't want to rip someones game model or sprites, or the basic mechanics though, I want what I make to be unique and I have unique desires for my projects, and so regardless of how choppy my code is my product will look very original, and I'll try my best to know what I'm doing but then man must first learn to crawl, then he can think about walking flying and being a god.

Mike
In response to Kichimichi
 var/list
question_list1 = list("Serratia Marcesens is what color?" = list(list("red","blue","green","brown"),"red"),"What does 'saltatory' mean?" = list(list("4","8","16"),"8"))


proc
ParseQuestion(Target,QuestionContent)
var/list/Answers = question_list1[QuestionContent][1]
if(!Answers) return FALSE
var/CorrectAnswer = question_list1[QuestionContent][2]
if(!CorrectAnswer) return FALSE
var/GivenAnswer = input(Target,QuestionContent) in Answers
return (GivenAnswer == CorrectAnswer)
mob/verb/Psiblast1(mob/M as mob in oview(1))

var/Psiblast = pick(question_list1)
var/Answer = ParseQuestion(usr,Psiblast)
if(Answer == TRUE)
src:attack(M)
else
src << "False."


got it to initiate a verb when the correct answer was spit out but I can't add more questions to the list yerg >< tried just repeating the format and got a "topmost and expected } error, no idea what that means

Mike-
In response to Kichimichi
Wow spent an hour figuring out that the extra elipse comes only at the end of the list, what a dork i am.

Mike
Let me know if you're interested in checking out the game as it progresses I'll upload the file or email it to you. It's coming together finally, I don;t have rewards for gameplay yet like levels or items to buy, but you can run around killing mobs and collecting exp at this point.

Mike
In response to Kichimichi
I prefer playing games when they are complete. Thanks for the offer though!
In response to DivineO'peanut
I'll make an NPC named DivineO'peanut in your honor for all the help anyhow. So far I've got the mobs moving randomly, statpoint rewards per level, stats that improve attack dmg and HP amounts, change weather in game, have to use the quiz questions to attack if the answer is wrong it hits the player with feedback damage,

atm I'm working on getting the npc's unique stats and abilities (I have it set kinda retarded all the mobs including the client us the same skeleton to start on, and it's somewhat ugly trying to get the game to let me back out of that lol)
looking for ways to set up a shopkeeper and other NPC's, maybe quests, equipable items, buy sell trade ect. at least for now it's kinda fun the way it is and I can get a pile of my study questions for school loaded in, great study aid much more fun than flashcards heh

Mike