ID:147681
 
A part of this game being worked on has an option that you can be asked a random question. If you get it right, it rewards you , but if you get it wrong, you are asked again.. now this is a little not too revealing peice of the code

mob/verb/Ask()
name = "Ask"
var/R = rand(1,20)
if(R == 1)
var/A = input("What does this look like","") as text
if(A == "Bird")
usr << "Correct!"
spawn()
Ask()
else
usr << "Wrong!"
now the problem is. I dont know how to spawn it to the same question again if you get it wrong. I dont want it to start over. Because if i spawn, it will just give you a different random question. I want to know how to respawn the same question when you get it wrong.
Vexonater wrote:
I dont want it to start over. Because if i spawn, it will just give you a different random question. I want to know how to respawn the same question when you get it wrong.

I see two obvious solutions. One would be to use GOTO, but that would (of course) be evil, and get many objects thrown at me by certain people.

So, I suggest a list and loop:

var/list/questions = list(
"What is your favourite colour?" = "Blue",
"What is the average velocity of an european swallow?" = "14.7")

mob/verb/Ask()
var/Q = 1
while(Q < questions.len+1)
var/answer = questions[Q]
var/response = input(src,questions[Q]) as text
if(response == questions[answer])
src << "Correct!"
Q++
else
src << "Wrong!"