ID:141220
 
Code:
mob
NPC
name = "Teacher"
icon = 'Teacher.dmi'
verb
Talk()
set src in oview(2)
set category ="Teacher"
switch(input("Ready for school?", text) in list ("Yes","No"))
if("No")
world << "[usr] doesnt wanna do school!!"
if("Yes")
switch(input("What grade am I teaching, again?", text) in list ("8th","9th"))
if("8th")
world << "Alright! [usr] is about to start doing 8th grade work!"
sleep(10)
world << "Okay, today is going to be expressions! It's really very simple.."
sleep(10)
world << " Say you have the problem 9x. We'll let x=2."
sleep(10)
world << "All you would do is plug 2 in for x so the problem becomes 9(2)"
sleep(20)
world << "As you may already know 9(2) is same as 9x2. So the answer is 18!"
sleep(10)
world << "Okay time to test you out!"
sleep(10)
world << "Be sure to have scrap paper handy! We're gonna check your work!!!!"
sleep(10)
switch(input("24 Divided by M...Let M = 3", text) in list ("24", "3","12","8"))
if("24")
src.Point-=1
world << "Sorry, that was wrong. The correct answer is 8"
if("3")
src.Point-=1
world << "Sorry, that was wrong. The correct answer is 8"
if("12")
src.Point-=1
world << "Sorry, that was wrong. The correct answer is 8"
if("8")
src.Point += 1
world << "Thats correct! A point has been added to your score!"


Problem description:
I have two problems. When they pick the correct answer the points do not go up by 1, and when they pick the incorrect answer they do not go down by 1, they just dont move at all. Still shows Points: 0. The code im using to show that though is Points: [Point] if that matters. Also, how can I make it so that even if they pick the incorrect answer it moves on to the next question? The only way I know how is to set up a whole exam through each answer, including the incorrect ones, which would be a whole lot of work, anyone know how I can do it easier? Thanks a bunch guys for the help guys! If you dont wanna help, no bashing please.
src is the source, in this case the teacher. You're making the teacher's points go up or down. :P

You could make them move on to the next question by making each question a proc, and when someone talks to the teacher it calls the Question1 proc, and at the end of that one it calls the Question2 proc, etc.

This would also allow you to save what last question they were on, so that when they talk to the teacher it can check and take them to whichever question they were on instead of starting from the beginning.
In response to Zaole
Oh wow, Im such an idiot. I have changed to usr.Point and it works fine, brain fart I guess, lol. Thanks for the idea for my second problem, I'll change it to procs. I love how helpful this forum is :D.
In response to ChicoTheMan94
I prefer just making a world var list, to hold each question's answers.
var/list/Question_1 = list("1","2","3","4")
var/list/Question_2 = list("5","6","7","8")

//then plugging in those lists into the switch() statements

switch(input(usr,"1 + 1 = ?","Question 1") in Question_1)
if("1")
usr<<"Correct! +1 to your score!"
usr.score ++
else
usr<<"Incorrect. -1 to your score."
usr.score --
switch(input(usr,"2 x 4 = ?","Question 2") in Question_2)
if("8")
usr<<"Correct! +1 to your score!"
usr.score ++
else
usr<<"Incorrect. -1 to your score."
usr.score --
//...


Also, else can, and should be used in switch() statements like the ones you have.
In response to Spunky_Girl
If going to use a var for the answers, why not a var for the question too? And then just loop through it.
In response to T3h P3ngu1n
Loop? Why would you use any sort of loop? That, to me, is so out of place >_>

The reason I don't make the questions their own variables is because none of the questions are the same, where the answer-set could be. He could have an answer set, for example, of different number orders (eg. least to greatest, greatest to least, etc). But the questions will ask for a different correct answer from the same answer-set.

Why would any kind of "test" do such a thing? I don't know, but it sure throws some people off o.O It turns into a "matching" question, BYOND style, I guess :D
In response to Spunky_Girl
Test
var/correct=0
var/list/questions
var/name
proc
GiveTest(mob/m)
//correct=0
for(var/Question/q in questions)
if( q.choices[ input(m, q.question, name ) in q.choices ])
correct+=1
m << "[correct] correct out of [questions.len]"

New()
var/list/quests=list()
for(var/m in questions)
var/p=text2path("/Question/[m]")
if(p)
quests+=new p
else
world.log << "Error: Bad question name."
questions=quests

FirstTest
name="Beginners' Test"
questions=list("CowsAre","OneAndOne")



Question
var/list/choices
var/question

CowsAre
question="What color is the African cow?"
choices=list("Black","White","Yellow","Pink"=1)

OneAndOne
question="What is 1+1?"
choices=list("3","2"=1,"4","5")

mob
verb
testtest()
var/Test/l=new/Test/FirstTest
l.GiveTest(src)


I really have no idea what you're talking about, Spunky_Girl. I put this together to show somewhat I mean. It may not work exactly like some would want, but can easily be edited to do so.
In response to Spunky_Girl
Spunky_Girl wrote:
Loop? Why would you use any sort of loop? That, to me, is so out of place >_>

Oh, really? So I take it that duplicating the same code again and again for every question seems in-place? Remember, whenever you need to manually repeat the same code a lot of times to achieve something, you're most likely going about it in a bad manner. This design issue is practically the same as putting a new Get() verb on every item in your game.
With a system like he posted, all you need to do to add a new question are its necessary properties, like the choices and in which tests it appears. No code duplication per question, so as you can see it's a much cleaner solution.
Loops are precisely for repeating things, and you need to repeat the same thing for each question (prompt for player input, compare input to correct choice, etc...), so a loop is very much in place here.
In response to T3h P3ngu1n
Oh, okay. I see what you meant by looping through the questions. You never mentioned putting them in a list var. You just said "a var". :\

You don't know what "matching" is?! O.O How long has it been since you've taken a middle/high school test/quiz! >:O (I'm fairly certain colleges don't utilize "matching" style questions)