Page 1 of 2

SCOREBOARD

PostPosted: Tue May 29, 2007 8:59 am
by d-soldier
... So my current project is about done, but I just started working on my scoreboard (after you die, or win) and I just realised that I've been starring at my monitor blankly for several minutes...I understand the whole loardvars thing from the tutorial, but how would I even go about setting up multiple text strings displaying "initials"/"score" in order from highest score to lowest? ... I think the scripting for the scoreboard itself is going to be ten times more complicated then anything in the game! :shock:

PostPosted: Tue May 29, 2007 4:32 pm
by Sgt. Sparky
I will make a Demo. :D

PostPosted: Tue May 29, 2007 4:46 pm
by d-soldier
I can always count on you Sparky! :D

PostPosted: Tue May 29, 2007 4:47 pm
by Sgt. Sparky
:D
Yay!


I am adding Names to. :D

PostPosted: Tue May 29, 2007 4:49 pm
by d-soldier
For your help, I'll put your name in the top three.

PostPosted: Tue May 29, 2007 6:01 pm
by Sgt. Sparky
Weee! :D

okay, I have everything in exept the Names. :(
I get a suspicious pointer conversation error,
and it will not run,
I am trying to copy text onto an Array position. :(
it will not work. :'(
( strcpy(NAMES[i], NEWNAME); I will think of a better way)

oh, And it still saves just so ya' know. :D
EDIT:
wait!
I forgot to make NAMES a string!
that is why! :lol:
*feels dumb*

PostPosted: Tue May 29, 2007 6:11 pm
by Sgt. Sparky

PostPosted: Wed May 30, 2007 12:57 am
by d-soldier
wow... Nice work there... I look at the coding in that demo and I am reminded of why I should stick to graphic illustration... :( My current project (if you win) creates a box for you to enter your name, and I want that information (with the score) to be stored in a score file. The scoreboard itself it a seperate game (loaded after the real game ends, and can be accessed from the main menu(which is also a serperate game))... So, in relation to that setup, how would i seperate that long script attatched to the filled region between the two? Thanks in advance, I'll be sure to tack your name into the credits for all the help! :D

PostPosted: Wed May 30, 2007 6:30 pm
by Sgt. Sparky
:D
simple:
look at the code when you press the "OK" filled actor,
look how it reads the file,
just use the read code(the fread() stuff) after you create the variables mentioned there.
the print it the same way it prints onto the text actor(bottom part of the code. :D)

PostPosted: Thu May 31, 2007 5:19 am
by d-soldier
.. seriously, I look at this code, and I might as well be looking at algebra... starting to think I dont really need a scoreboard...

PostPosted: Thu May 31, 2007 6:48 am
by DilloDude
I made a working high-score page system for my Super-Human game I'm working on (see my sig). It stores the top ten highscores and along with the player's initials, and the character they used. The results are sorted when a new one isadded, and they are displayed in a single text actor. (Limitations have to be made for length, because a text string can contain only 255 characters.) If you like, I'll post a simplified and commented version of the code for you soon.

PostPosted: Thu May 31, 2007 4:12 pm
by Sgt. Sparky
DilloDude wrote:I made a working high-score page system for my Super-Human game I'm working on (see my sig). It stores the top ten highscores and along with the player's initials, and the character they used. The results are sorted when a new one isadded, and they are displayed in a single text actor. (Limitations have to be made for length, because a text string can contain only 255 characters.) If you like, I'll post a simplified and commented version of the code for you soon.

mine is a single text actor as well. :D
but I still would be glad to see a simpler version if it works better.(most likely does.) :D

PostPosted: Fri Jun 01, 2007 5:32 am
by DilloDude
Here's what I have: First I have three variables in which to save the state of the highscores:
  1. recscore as an integer array of size 10, which is saved in HSCORE. This variable stores the top ten highscores.
  2. recnam is a string array of size ten, also saved in HSCORE. This is where the player's initials are stored.
  3. recchar is another string array saved in HSCORE. This is an array of size 10 where the character used to obtain the score is stored.
I am also using an integer called score; this is where the current score is stored.
The name entry screen (image below) is made of three actors:
  1. NameMenu is the actor that is the background image; it includes a text-box where the text actor goes and instructions for entering your name.
  2. ScoreCount2 is a number that shows the score you achieved.
  3. NAMTXT is a text actor where you enter your initials. I have simplified it so that you only use letters and spaces. For best alligning results, you will need to use a fixed-width font (such as courier, or you can make your own as an image font or use mine (link below)).
The high-score display screen (third image) consists of two actors:
  1. HscoreMenu is the background actor, it also has a keydown event to return to the title screen.
  2. HscoreTXT is the text actor that displays the high-scores. It has the same sort of font as mentioned above. Because the text string is limited to 255 characters, I have limited the spaces between the different fields to one, and the character name shouldn't be longer than twelve, the score is limited to six charcters (It isn't that likely that you'll score more than 999999 points).

And now for the script that drives it.
My view actor has an event that checks when the game is over. It goes through some actions that stop the game, and then it checks if the score is big enough to be on the high-score list:
Code: Select all
if (score >recscore[9])//the ten spots in recchar are numbered 0-9, so check if score is greater than the lowest one
{
    //script to move to the name entry scrren and enable events on NAMTXT
    ScoreCount2.textNumber = score;//set the display on the name entry menu to the score
}
else
{
    //if score does not go on the list, return to the appropriate menu to play again and set score to 0
}


NameMenu only has a create actor event where it sets its x and y position and disables collision state.
NAMTXT is where the real action takes place. On the createactor event, disable collision state, and all events. Then initialize the text:
Code: Select all
strcpy(text, "_");
This just means that when no name has been entered yet, an nderscore is displayed.
Next comes the keydown event. Make it any key, with repeat disabled. Then use the following script (edit it if needed, I'll try to put plenty of comments in it)
Code: Select all
int k = getLastKey();//create an integer which stores the key pressed.
unsigned char len = strlen(text);//create a variable to store the length of the string entered.
if (strncmp(text, "_", 1) == 0)//if no text has been entered, remove the underscore
{
    char dummy[4];//create a temporary string
    strncpy(dummy, text, len - 1);//fill this string with all of the text, except for the last character
    len --;//decrease the value of the string length
    strcpy(text, dummy);//copy the temporary value back into the text
}

if (k >= KEY_a && k <= KEY_z)//if the key is a letter key, add the appropriate charcter
{
    if (len < 3)//don't put a new character if the string is already full
    {
        char add[2];//create a temporary string to hold the value to add on
        add[0] = k - 32;//set the value of the first character of this string to the appropriate value based on the pressed key
        strcat(text, add);// add this temporary string to the text
    }
}
else if (k == KEY_BACKSPACE)//if backspaced is pressed, remove the last character (same as above, except you must check the length first)
{
    if (len > 0)
    {
        char dummy[4];
        strncpy(dummy, text, len - 1);
        strcpy(text, dummy);
    }
}
else if (k == KEY_SPACE)//add a space if that key is pressed
{
    strcat(text, " ");
}
else if (k == KEY_RETURN && len > 0 && strncmp(text, "   ", len))//if the key pressed is enter, and there is text in the string, and the string is not all spaces, submit the highscore
{
    setKeys();//this is a function I wrote to remap the keys to the player's configuration. If you aren't having custom controls, you don't need this
    view.x += 600;//move the view to the high-score screen
    EventEnable("HscoreMenu", EVENTALL);//enable events on the high-score screen
    EventDisable("Event Actor", EVENTALL);//disable events on the text
    //update hscore
    {
        int i, slot;//initialize some variables

        //find the space where the new high-score number should go
        slot = 9;
        while (slot > 0 && score > recscore[slot - 1])
        {
            slot --;
        }
 
        //move all lower scores down on slot
        for (i = 9; i >slot; i --)
        {
            recscore[i] = recscore[i - 1];//move the score
            strcpy(recchar[i], recchar[i - 1]);//move the character
            strcpy(recnam[i], recnam[i - 1]);//move the player's nam
        }
        recscore[slot] = score; score = 0;//set the score appropriate spot
        strcpy(recchar[slot], character);//put the character in the appropriate spot
        strcpy(recnam[slot], text);//put the initials in the appropriate spot
 
        saveVars("conf.shd", "HSCORE");//save the new high-score list
        SendActivationEvent("HscoreTXT");//tell the high-score screen to update the score
    }
}


HscoreMenu has a create actor event where it sets its initial position, disables collision state, and disables events. It also has a keydown event to return you to the main menu. This should also disable events on the event actor.
Finally, you need to display the high-score list. HscoreTXT has a create actor event:
Code: Select all
char i;//make a counter variable
char add[26];//make a string for one line
loadVars("conf.shd", "HSCORE");//load the high-scores
strcpy(text, "");//start with nothing in the text

for (i = 0; i < 10; i ++)//loop through for each line
{
    sprintf(add, "%-4.4s%-13.13s%06i\n\n", recnam[i], recchar[i], recscore[i]);//fill up the line
    //%-4.4s: the - means left allign. The 4 means to put four characters even if there are more. The .4 means don't put more than four characters in. The s says that the variable is a string.
    //%-13.13s: same as above, except thirteen characters (twelve for the character name, plus one space).
    //%06i: the 06 means that six characters will be inserted, any characters not part of the number will be zeroes. The i says that it is an integer.
    //\n\n: insert two newline characters, to move down two lines.
    strcat(text, add);//add the line onto the text.
}

HscoreTXT also has an activation event (from NAMTXT) that does the same as the above script except without loading the vars.
I think that wraps it all up. As with all codes and solutions that someone gives you, try to understand what makes it work. That way you will be able to learn from it, and use bits of it for other stuff (so you can make your own
games rather than someone else telling you everything to do). If you have problems with getting it to work, adapting it to your situation, or understanding parts of it, just post and I (or someone else) should be able to help you.

PS: It looks complicated (and a lot of things do when you just see the completed lot) but it is really quite simple.

Here is the link to the font I made: http://www.imageviper.com/displayimage/ ... _black.bmp

PostPosted: Fri Jun 01, 2007 6:09 am
by d-soldier
Wow... it does look complicated... thanks for taking all the time to type it up and explain it Dillo.

??

PostPosted: Fri Jun 01, 2007 3:12 pm
by d-soldier
That first big block of code (for the keydown event of the text actor), everytime I copy it and past it into GE causes GE to crash... not when I try to play it, but just by pasting it into the script editor! Very strange...
-------
So (from the pics below) I have a little box that comes up when the player wins, or loses the game... There is a text actor in the box, which is where I want the initials to go. Since the score has been displayed throughout the game, I don't care to have it displayed in the box too. So once the player eneters his initials and clicks on the "okay" button, the game ends, loading a seperate game to display the scoreboard. (this way people could view the scoreboard from the game menu as well, bypassing the game if they choose). So in relation to my setup, how would I rig this coding?