The Dink Network

How To: High Score Saving (w/ Mayhem Implementation)

August 6th 2003, 05:49 AM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
With the advent of arcade-type D-Mods (like Dinkanoid or Dink Racer or Mayhem), automatic high score saving would help make the experience much more fun. But it is absent in these D-Mods, and the only alternative is to keep a record of your own high scores by hand. And who wants to do that?

In fact, I found a relatively easy way to save high scores when I was working on Frogger v1.00 a few years ago (which has since been abandoned). Here is how:

Step 1:

Create a new, empty screen. Tile it black (for DinkEdit users, the only proper black tiles are between the floor and tree tiles on tile screen 1). Give it a base script of 'title', save and exit.

Step 2:

Open main.c, and add the high-score variables you're going to use, such as "&highscore". If you have multiple difficulties/modes, then create a high-score variable for each one.

Step 3:

Create a new script called title.c. Give it a main procedure, and put wait(1); followed by save_game(11); at the very top. Then open start.c, and Cut everything past the load_sound() lines. Paste these lines into title.c after save_game(11);. Save and close title.c. Go back to start.c and add the following lines after the load_sound() lines:

int &temp = game_exist(11);
if (&temp != 0)
{
load_game(11);
kill_this_task();
}
&player_map = 1; //Change to the empty screen you created in Step 1
load_screen();
draw_screen();
kill_this_task();


Save and close start.c.

Step 4:

When the player 'wins' your game, see if their current score is greater than the existing high score. If it is, set the high score variable to the current score of the player. Then just do this:

&player_map = 1; //Change to the empty screen you created in Step 1
load_screen();
draw_screen();
kill_this_task();


And tada! The high score is saved to the save game, and can be retrieved from title.c (for a say_xy line or whatnot). Do not try to get smart and use save_game(11); any time you want; it *has* to be on the blank screen with the base script of 'title'.

If there is a way to lose your game, then just use restart_game(); to get back to the title screen, and it won't save the high score.

As an example, I've applied the above techniques to Paul Pliska's Mayhem. You can download the unofficial patch here. His lack of high-score saving prompted the release of this tutorial, as well as a comment by magicman requesting high-score saving in future dink.exe improvements.

NOTE: I had to do quite a lot of tweaking (i.e. copying code from Paul Pliska's transfer D-Mod) to get high score saving to work with Mayhem, as it uses editor_type, and editor_seq quite extensively. And of course, saving the game saves these values as well. These tweaks are noted in the code, so you can see what you (usually) shouldn't have to do in most arcade-style games. So I guess I should have used Dink Racer as an example, but I *really* wanted high score support in Mayhem

NOTE 2: The above technique will not work in Dinkanoid. You can sort-of save and load the game, and each of these would have different high score values, and there isn't any known way of passing information between save games.
August 6th 2003, 01:14 PM
wizardg.gif
Paul
Peasant He/Him United States
 
Hey, I'm glad you liked Mayhem enough to mess with it. Works pretty good. Too bad about editor_data slowing the thing down. One solution would be to give each game an ID number and let the script on each object keep track of whether they were modified in the current game or a previous one by saving that number in editor_seq. BTW, that sound caused by my "bizarre decision" can be avoided by adding draw_status(); after the buttons are created.
August 6th 2003, 03:27 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
I just found a bug: if you fail to get a new high score, it will go back to the title screen without resetting the editor_data or restarting the game, so all of the previous changes would still be in effect.

Maybe I'll release v1.1 tonight to fix that, and the sounds on the title screen.

One solution would be to give each game an ID number and let the script on each object keep track of whether they were modified in the current game or a previous one by saving that number in editor_seq.

Hmm... would that work? The script won't be run if it has an editor_type of 1, right? How would you get around that? And what about sprites that use editor_seq and editor_frame (like smashed barrels)?

And speaking of bugs, I found a couple (that aren't due to my high score support). On screen 36 (the upstairs of the weapon store), almost everything has the barrel-strength potion script It makes things kinda easy.

Also, the boot store (screen 54) exit warps you over to 'Fairy Inn' entrance (screen 370).
August 6th 2003, 10:37 PM
anon.gif
Paul
Ghost They/Them
 
I guess I didn't quite explain. I meant instead of using editor_type. In the barrel example, the script would flaten it if the editor_seq is equel to the current game's ID, which it would be set to when you get it. Then you could use editor_frame if for any extra data, (but most things only have two states anyway). The only hard part to simulate would be the editor type to die and come back later, something most arcade games don't need much anyway.

And thanks for the bugs, I suppose I'll have to release a patch/updated version at some point. Maybe I'll even try to get the high score thing going in there.
November 11th 2003, 12:27 PM
old.gif
isnt this just easier?

scripts:

//Just main.c
main.c
global_int("&Score", 0);
global_int("&HighScore", 0);

//start / load a game
start-*.c

//load the savedgame here, and if he starts the game, reset back the
&player_map, sp_x and sp_y settings of dink.

//The script that controls the game
Game.c

if (&score > &highscore)
{
&highscore = &score;
say("NEW RECORD!", 1);
//Save the game here (forgot the command)
} else {
say("TRY AGAIN!", 1);
}

Its allmost the same as redink1 said, but this is quite easier/faster
November 11th 2003, 01:06 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Uh... that is almost the same thing I said, except I went into more detail and yours won't work. How will it display the high scores on the title screen? Yes, in some instances yours would be slightly easier to implement.
November 11th 2003, 01:29 PM
old.gif
Haha

int &buffer = say_xy("High Score: &highscore", x, y);
sp_kill(&buffer, 0);
int &wbuffer = say_xy("Current Score: &score", x, y);
sp_kill(&wbuffer, 0);
November 11th 2003, 01:38 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Um... ok... but if you don't load the game until you press the Start button (if I read your somewhat confusing 'easy' explanation correctly), then it will not display on the title screen.
November 11th 2003, 02:42 PM
old.gif
dang, explaining is a lot more difficult then making it X_X
November 11th 2003, 03:15 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
As is the case with every human endeavour.
November 13th 2003, 12:30 PM
custom_fish.png
SabreTrout
Noble He/Him United Kingdom
Tigertigertiger. 
What about a Time Machine? That's a lot easier to theorize about and discuss than to actually make...
November 13th 2003, 03:38 PM
old.gif
Blah, going to the past with a time machine == suicide.

Example:
You meet a stranger, he wants to start his own business, but he needs $50 for a start. You dont give him the money. Years later, you read in the newspaper that he's rich... You make a time machine to go back into time, and give him the $50. What happens?

You gave him the $50, so you didn't have to go back in time to give him the $50, so you couldn't give him the $50, because you didn't need to go back in time. So....
November 17th 2003, 01:21 PM
bonca.gif
Christiaan
Bard They/Them Netherlands
Lazy bum 
he doesn't quite need the money if he already got rich, does he?
November 17th 2003, 03:24 PM
old.gif
He wanted $50 to start his business. And ofcourse you want to go back and give him the $50. You can claim 25% or more of his money LATER so you will become rich too...