The Dink Network

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

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
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.