This site requires JavaScript, please enable it in your browser!
Greenfoot back
Adi18
Adi18 wrote ...

2018/2/9

Q&A

Adi18 Adi18

2018/2/9

#
Can I do a program in which, if I touch an object, a question arises and I write the answer and if it is right to go on?
danpost danpost

2018/2/9

#
Use the 'ask' method of the World class when the object is touched. The method will hold everything until a response is given. Then compare the response, if not null, to the correct answer before proceeding.
Adi18 Adi18

2018/2/9

#
And if I would not want to stop while responding. I can do that?
danpost danpost

2018/2/9

#
Adi18 wrote...
Can I do a program in which, if I touch an object, a question arises and I write the answer and if it is right to go on?
Adi18 wrote...
And if I would not want to stop while responding. I can do that?
Aren't those contradictions as far as what you want to do?
Adi18 Adi18

2018/2/9

#
sorry ... I want to defend my question and I give an answer, and stop when I write the correct answer ... how should this look like code?
danpost danpost

2018/2/9

#
Maybe there is misunderstanding here. How about a little more info! You ask a question; if answer is correct, stop what, exactly? if answer is wrong, what? -- attempt another answer? Please state each step possible scenario, step by step.
Adi18 Adi18

2018/2/9

#
if the answer is correct / wrong to erase that bar that appears when you call Greenfoot.ask and keep the answer
danpost danpost

2018/2/9

#
The ask bar will go away as soon as the response is given. The answer can be assigned to a local variable or saved in a field:
String response = Greenfoot.ask("What the question is?");
if (response != null && "answer".equals(response))
{
    // correct
}
else
{
    // wrong or not answered
}
Adi18 Adi18

2018/2/9

#
thank you !!!
You need to login to post a reply.