Implementing a high-score table for my nearly-finished game

This forum is currently in read-only mode.
From the Asset Store
Human/Character Base Pixel Art Sprites in various poses (nearly 100 files)
  • So I am more or less finished with my game, my first major project in Construct. The levels are constructed, the game engine is more or less finished, and I am only waiting on some artwork so i can have an intro and credits sequence.

    So things are pretty good.

    If you'd like, you can play what i have right here:

    http://dl.dropbox.com/u/29072735/SpaceshipGameAlpha.zip

    5 levels of super action!

    ----

    Anyway, I am thinking, since i am mostly done, I am thinking of implementing a high-score

    system and a timer.

    More specifically:

    -A score system, and upon finishing the game, or getting a game over, a local hi-score table that the player can enter their initials into, which would be saved for the next time they play the game

    What would be the best way to go about this? What tutorials/.CAPs are recommended for me to look at?

    -As for a timer, I assume you'd just set up a global variable, or private variable called TIME, and have every X milliseconds, 1-subtracted from var.TIME?

    Some refinements:

    -At the end of the game, I'd like like to have it so that the timer, whatever time is left, counts down really fast and the score meter fills up equally fast (you know, like at the end of every SMB level).

    Would I do this using "every X milliseconds" action? Say, like when Function "TimeAdd" is called,

    Every 10 Milliseconds

    GlobalVar TIME greater than 0

    -Subtract 5 from var.TIME

    -Add 5 to var.SCORE

    Like that?

    ---

    I am sorry if this is unclear; I am still not entirely sure how I want to do everything.

    In any event, if you just want to play the game itself, you can surely do so!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It might get boring that I point to my example Verve! all the time. But I really made it to cover as much as possible to show ways to realize things. Of course, Verve! also features a hiscore, complete with sorting algorithm and auto-save. Have a look at it, every single event in Verve! is extensively commented.

    For the timer, you could also use the system expression timer and a timestamp. timer returns the time passed since start of the game in milliseconds.

    + start of layout

    -> set 'timestamp' to timer

    -> set 'maxTime' to [somevalue]

    + always

    -> set 'remaining' to 'maxTime' - (timer - 'timestamp')

    -> set text to int('remaining')

    + 'remaining' <= 0

    -> game over

    The third point is one possible way to do it, but the 'every 10 milliseconds' doesn't make much sense. When running your game v-synced it might be played at 60 fps, that's 16.67ms. You could also reduce Time vs Score with TimeDelta:

    (50 * TimeDelta would mean substracting 50 points per second. If the game runs at 60 fps, it will substract 0.834 per tick. At 25 fps it would be 2 per tick. Overall 50 per second)

    + 'remaining' >= 50 * TimeDelta

    -> Substract 50 * TimeDelta from 'remaining'

    -> Add 50 * TimeDelta to 'score'

    -> set text to int('score')

    + else

    -> level complete

    EDIT: It was late yesterday and I'm giving the examples without using Construct. I made one mistake, in my example 'maxTime' would have to be a value expressed in milliseconds. You surely don't want that, so just change

    -> set 'remaining' to 'maxTime' - (timer - 'timestamp')

    to

    -> set 'remaining' to 'maxTime' - ((timer - 'timestamp') / 1000)

    Now 'maxTime' can be a value expressed in seconds.

  • You know, i did download Verve a long time ago, but I have yet to look through everything within the example, so I apologize for making you bring it up yet again! ; )

    Thank you for the pointers, as I'll be trying to implement these now into my game build.

  • I have not finished yet with this task, mainly because of real-life business, along with me not understanding arrays very well.

    I have some more questions, if anyone would be kind enough to answer.

    1) Tulamide, when you say in your post

    "set timestamp to 'timer'"

    Is timer a global variable? Or is it a behavior? Same with timestamp.

    I am unsure, because I can't find anything preset that I can set them too. I am unfamiliar with CC expressions, and it looks like the Wiki for CC has been hidden away somewhere.

    2)

    So the way I am understanding arrays, they are like grids with values at each of the grid spaces.

    Now, I want a high-score table where people can enter their names, but I don't want something like "type your name here" since that is kind of lame.

    I was wondering, that maybe I can set up an array which has in each space the value for a letter, like A, or H, or a number, 0-9. Stuff like that.

    Of course, I don't know how I'd get that to work, but is it possible?

    3) Tutorials seem to be split on this- to do a score system, and a high-score system, do you go with arrays, or do you go with INI files (perhaps protected by CRC32), or perhaps some mixture of the two? Whatever is easier is good for me!

    As I said in my now defunct OP account, this is the last major thing (and it's quite a major thing!) before the game is complete, so any and all help would be appreciated, on top of the kind and generous help I've received thus far.

  • Is timer a global variable? Or is it a behavior? Same with timestamp.

    ... you could also use the system expression timer ... timer returns the time passed since start of the game in milliseconds img src="smileys/smiley4.gif" border="0" align="middle">

    But I admit, I wasn't very clear on that.

    Here is the link to the Wiki, btw: Construct Wiki

    Timer: It is a system expression. You access it either by typing "Timer" where needed, or by selecting "Get timer" in the expression wizard of the system object.

    Timestamp: The single quotation marks I used were to indicate that it is a variable. Either global or private - I prefer PV where possible.

    The principle of that method is to get a pointer to a certain time. This can be compared to another time, and if some predefined period has elapsed, you can trigger any other actions you need at that time.

    Calling timer after game ran for 5 seconds:

    timer will return 5000

    Calling timer after game ran for 7 seconds:

    timer will return 7000

    If you use a variable 'timestamp' and fill it once with timer after the game ran for 5 seconds:

    'timestamp' will be filled with timer, and timer returns 5000, so

    'timestamp' = 5000

    If you constantly test against 'timestamp':

    if timer - 2000 = 'timestamp'

    This condition will be true as soon as timer reaches 7000, because 7000 - 2000 = 5000

    Instead of the number 2000, you could use another variable, I called it 'maxTime'. It is the period allowed before the condition will become true:

    if timer - 'maxTime' = 'timestamp'

    Now the problem is, you not just want something to happen after 2 seconds, you also want to inform the player about how many time there is left. That's the third variable 'remaining'. It needs to be set to the difference of 'maxTime' and the current progress within the period. After 0.5s the remaining time is 1.5s, etc:

    set 'remaining' to 'maxTime' - (timer - 'timestamp')

    Let's fill this with values to see how it works. 'timestamp' = 5000, 'maxTime' = 2000.

    We call this action by chance when timer returns 6500, that's 1.5s after we filled 'timestamp':

    set 'remaining' to 2000 - (6500 - 5000) => 2000 - 1500 => 500 or 0.5s

    But 'remaining' will always be calculated, so it can get negative. Imagine we call the action, when timer will return 10000, that's 5 seconds after we filled 'timestamp':

    set 'remaining' to 2000 - (10000 - 5000) => 2000 - 5000 => -3000 or -3s

    We surely don't want that to happen, so we need to catch that before it goes negative:

    'remaining' <= 0

    This condition will be used to trigger any action that makes sense. You could use it to end the game, or you could fill 'timestamp' again with timer, that would reset the timing, so we get a continous loop of a countdown from 2s to 0s, 2s to 0s, ..., or you could switch to another layout. Whatever is needed.

    2)

    So the way I am understanding arrays, they are like grids with values at each of the grid spaces.

    Now, I want a high-score table where people can enter their names, but I don't want something like "type your name here" since that is kind of lame.

    I was wondering, that maybe I can set up an array which has in each space the value for a letter, like A, or H, or a number, 0-9. Stuff like that.

    Of course, I don't know how I'd get that to work, but is it possible?

    I'm sorry but I don't quite understand. Is it the kind of input (name typing, or selecting letters per digit by using up/down/left/right) you are concerned of, or the actual values to store?

    3) Tutorials seem to be split on this- to do a score system, and a high-score system, do you go with arrays, or do you go with INI files (perhaps protected by CRC32), or perhaps some mixture of the two? Whatever is easier is good for me!

    They both are relatively easy. Using ini-files you have all of the informations stored in 1 file, while arrays may use 2,3 or more files, depending on the informations to save, but are more easily sortable. There are two other possibilities: You could also use a hash table.

    Arrays and hash table save their data in a binary format (non human readable), while ini files are simple text files. So you don't really need a crc32 protection for arrays/hashtables.

    Last, but not least you could use 's', a fantastic plugin by lucid. Sorting is easy as well as saving/loading. Plus, all data is not only saved in binary format, but encrypted also, without the need for extra code.

  • ... you could also use the system expression timer ... timer returns the time passed since start of the game in milliseconds <img src="smileys/smiley4.gif" border="0" align="middle">

    But I admit, I wasn't very clear on that.

    Here is the link to the Wiki, btw: Construct Wiki

    Thanks for clearing that up with the very helpful explanation. I usually take posts like that and save them to a word file for future reference. : D

    I wasn't entirely sure if I needed one or two variables (apparently 3), or if there was a behavior or object I should have been using. Tomorrow when i am at my laptop with the CAP project file I'll begin to sort things out.

    I'm sorry but I don't quite understand. Is it the kind of input (name typing, or selecting letters per digit by using up/down/left/right) you are concerned of, or the actual values to store?

    Yeah, it's just name input. But it's like the old arcade inputs, where there are three spots, in which you can put any letter or number you like. Like:

    _ _ _

    can be

    B T D

    or

    6 Y T

    or whatever you want to input.

    Selecting letters. I was thinking maybe use an array to store all of those selections, in some way.

    What I was thinking was that each spot on the array corresponds to a PV- let's call it "NameEntry"

    1 on NameEntry corresponds to A, 2 to B, and so on.

    So for the three blank spots, scrolling down would increase the value of NameEntry, thus scrolling through the letters/numbers, before resetting back to A.

    Does that make sense?

    They both are relatively easy. Using ini-files you have all of the informations stored in 1 file, while arrays may use 2,3 or more files, depending on the informations to save, but are more easily sortable. There are two other possibilities: You could also use a hash table.

    Arrays and hash table save their data in a binary format (non human readable), while ini files are simple text files. So you don't really need a crc32 protection for arrays/hashtables.

    Last, but not least you could use 's', a fantastic plugin by lucid. Sorting is easy as well as saving/loading. Plus, all data is not only saved in binary format, but encrypted also, without the need for extra code.

    It seems with Construct the possibilities are endless :)

    While I'll definitely take a look into S plugin, and maybe play around with INIs or hashes for a future project (that I might as well finish), I think I'll try to parse out arrays, unless I prove to stupid to figure them out (it took me like a week just to finally visually/mentally GRASP just what an array was, ha ha).

  • What I was thinking was that each spot on the array corresponds to a PV- let's call it "NameEntry"

    1 on NameEntry corresponds to A, 2 to B, and so on.

    So for the three blank spots, scrolling down would increase the value of NameEntry, thus scrolling through the letters/numbers, before resetting back to A.

    Does that make sense?

    Yes it does. Just keep it as simple as possible. Decide which way to go (text boxes or sprites), then use efficient routines.

    For sprites, just add all the letters as frames and switch the frame number according to the input. No need for an array. You could then save the score data with the framenumbers instead of actual letters (e.g. 2000 points from "ABC" would be saved as "2000, 1, 2, 3" or similar)

    For textboxes you would setup a 1-dimensional array with all the letters, and fill the textbox with the index received through input (e.g. Set text to Array(currentIndex)). Again, you could save the score with indices instead of real letters.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)