2019-08-19 05:25:06

Hello! I am working on a songquiz game in bgt. My problem is, when i try to serialize my high scores, the game keeps showing up an error message i set. What is wrong? Here's the code:

#include"dynamic_menu.bgt"
void main()
{
show_game_window("Songquiz!");
tts_voice voice;
voice.speak_wait("Welcome to songquiz!");
mainmenu();
}
void mainmenu()
{
dynamic_menu menu;
menu.add_item_tts("Start the quiz");
menu.add_item_tts("Exit");
menu.add_item_tts("High scores");
int choose=menu.run("Main menu.",true);
if(choose==1)
{
start();
}
if(choose==2)
{

highscore();
}
}
void start()
{
tts_voice voice;
dynamic_menu name;
voice.speak_wait("Would you like name the song mode or name the artist mode?");
name.add_item_tts("Name the song");
int result=name.run("Choose",true);
if(result==1)
{
namesong();
}
}
void namesong()
{
tts_voice voice;

int score=0;
voice.speak_wait("What song is this one?");
sound song1;
song1.load("musiccut.wav");
song1.play();
wait(16000);
voice.speak_wait("A: Con calma");
voice.speak_wait("B: All for love");
voice.speak_wait("Or c: Back from the death");
while(!key_pressed(KEY_ESCAPE))
{
if(key_pressed(KEY_A))
{
voice.speak_wait("Really you thought so? Seriously? The correct answer was: Back from the death.");
voice.speak_wait("Your final score was"+score);
mainmenu();
}
else if(key_pressed(KEY_B))
{
voice.speak_wait("nonononono! Just no!");
voice.speak_wait("Your final score was"+score);
mainmenu();
}
if(key_pressed(KEY_C))
{
voice.speak_wait("Congrads! That was correct!");
score=score+300;
}
dictionary data;
data.set("score",score);
if(data.exists(score))
{
data.get("score",score);
serialize(data);
}
else
{
alert("Error!","There was an error");
}

}
}
void highscore()
{
tts_voice voice;
voice.speak_wait("Your highscore was+score");
}

Best regards: Marco

2019-08-19 06:03:31

the problem is with the line

if(data.exists(score))

it should be changed to

if(data.exists("score"))

2019-08-19 14:16:47

Not only that, but the second option in your menu is exit, so if you're checking for mres==2 or whatever, it is of corse activating the exit option.

2019-08-20 03:23:20

If you press exit, it will bring up the high scores, because of the order you have the menu in.