Login | Register

Quiz script

July 16, 2006, 14:16 by Calle
[loading]
-->
This how to create a script which asks you for an answer and then if the answer is correct it says so, it shows the right answer and asks again. This is an excellent method for memorizing.

You are a lot more likely to start study, for an example the capital cities, if you got a good method which you know works. I have used this method, developed by myself, and I like it. But it is only good for static information, like lists and such.

Different lists, for an example the cities, can be found at Wikipedia among others. My list comes from Wikipedia. The file structure looks like this: Country City, new line

I start with the code, and then I explain:

file = file_text_open_read("cities.txt";);

while(!file_text_eof(file)) {
read = file_text_read_string(file);
file_text_readln(file);
stringc = string_copy(read,1,string_pos(" ",read));
ans = string_replace_all(string_copy(read,string_pos(" ",read),
string_length(read)-string_pos(" ",read))," ","";);

question = get_string("Capital of##"+stringc,"";);

if (question="quit";) {
game_end();
exit;
}
while (question!=ans) {
get_string("Correct answer:##",ans);
question = get_string("Huvudstad för:##"+stringc,"";);
}
}


I assume most of you can figure out where I am initializing the variable file and what the read variable does. I will just briefly explain the logic of this script. As you can see I got two loops. The first one will end when the file, file, reaches the end. The second one, which is ran several times within the each run of the first loop, will end when the variable question do not match the variable ans. Variable ans which we can see earlier in the code determines the correct answer and question holds the information from the get_string function. So basically first loop chooses a new question, second loop continues until that question got the right answer. I have also input a special condition, so that if the user enters quit the repetition will quit. This is necessary since we are using pop-ups.

Ask if there is something more you want explained!

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games