|
Post by johnno56 on Apr 20, 2020 17:17:53 GMT -6
Ok. This is a minor update release. An "in game" high score has been added. Of course, it will reset to zero, if you quit the game and restart.
I am researching a suitable method of storing, retrieving and sorting, an external high score table... Do not hold your breath waiting... unless you like the colour purple... lol
|
|
|
Post by n00b on Apr 20, 2020 23:00:12 GMT -6
This game is incredible. I could actually see this coming with a computer when you first get it like that space pinball game from Windows XP (I played that game to death).
As for storing your high scores you could just write them to a text file and read them back in on start up.
Lets say you have your high scores in an array:
Dim high_scores[5] high_scores[0] = 500 high_scores[1] = 500 high_scores[2] = 500 high_scores[3] = 500 high_scores[4] = 500
You can save them to a file like this:
f = FreeFile FileOpen(f, "high_scores.txt", TEXT_OUTPUT)
For i = 0 to 4 WriteLine(f, Str(high_scores[0]) + "\n") 'You need the \n in there otherwise they will all be on the same line Next
FileClose(f)
You can them read them back into your program like this:
f = FreeFile If FileExists("high_scores.txt") Then 'Its always a good idea to make sure the file you are trying to open actually exists FileOpen(f, "high_scores.txt", TEXT_INPUT)
i = 0
While Not EOF(f) 'Read until end of file high_scores[i] = Val( ReadLine(f) ) i = i + 1
If i = 5 Then 'Just to make sure we dont read more than what we need Exit While End If Wend FileClose(f) End If
Let me know if any of that doesn't make since.
|
|
|
Post by johnno56 on Apr 21, 2020 5:58:13 GMT -6
Ah... The allusive "\n"... I had started on a "save" routine and, for the life of me, I couldn't figure out why the two records ended up concatenated...
I will put aside my feeble effort and give your version a shot... I was worried about file paths for other machines, but if the high score file is in the source directory, I suppose that should not be an issue...
Thank you for the code. I will let you know how it turns out. Cool.
|
|
|
Post by johnno56 on Apr 21, 2020 6:09:15 GMT -6
Here is my efforts based on your example... Do NOT create a table....
This will create a table if it does not exist. Then it will read the table and finally view the table.
It uses the default horrible text... It's a proof of concept and not a beauty pageant entry... lol
Once it has finished. Re-run the program... The high score table exits... No point recreating it... The table will be read then viewed...
xmax = 800 ymax = 600 title$ = "Highscore Table Test"
WindowOpen(1,title$,0,0,xmax,ymax,0) CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0) ClearCanvas
setColor(rgb(255,255,255))
Dim hi_scores[5] hi_scores[0] = 500 hi_scores[1] = 500 hi_scores[2] = 500 hi_scores[3] = 500 hi_scores[4] = 500 Dim hi_names$[5] hi_names$[0] = "Noname" hi_names$[1] = "Noname" hi_names$[2] = "Noname" hi_names$[3] = "Noname" hi_names$[4] = "Noname"
sub tableCreate() if FileExists("hi_scores.txt") then prints("high score already exists...") wait(3000) return else f = FreeFile FileOpen(f, "hi_scores.txt", TEXT_OUTPUT) for i = 0 to 4 WriteLine(f, hi_names$[i] + "\n") WriteLine(f, str(hi_scores[i]) + "\n") next FileClose(f) prints("File Created...") end if end sub
sub tableRead() f = FreeFile if FileExists("hi_scores.txt") then FileOpen(f, "hi_scores.txt", TEXT_INPUT) i = 0 while not eof(f) hi_names$[i] = ReadLine(f) hi_scores[i] = val(ReadLine(f)) i = i + 1 if i = 5 then Exit While end if wend FileClose(f) prints("High score has been read...") prints("") wait(3000) else prints("High score file does not exist...") wait(3000) return end if end sub
sub tableView() for i = 0 to 4 prints(hi_names$[i] + " ..... " + str(hi_scores[i])) prints("") next end sub
tableCreate() wait(1000) tableRead() wait(1000) tableView()
wait(3000)
The only thing left to do is to apply a sort routine to the finished table and "dress it up a bit" and integrate it into the game...
|
|
|
Post by johnno56 on Apr 21, 2020 6:15:58 GMT -6
Oh. I forgot one small detail...
I will need to create a routine to check if the player's score actually 'qualifies' to be added...
|
|
|
Post by n00b on Apr 21, 2020 6:58:11 GMT -6
Yeah, you definitely don't want to have a score of 0 on your high score table. That might give players a false sense of confidence. I much prefer to have my dreams crushed by reality as early as possible.
|
|
|
Post by johnno56 on Apr 21, 2020 15:29:04 GMT -6
I have put together a rough outline and tested with scores above and below '500' and it seems to work... The notification part... "Yes" or "No".
Now I have to figure out how to 'insert' the new score into the table... I will need to sort the table... This is getting harder... Pong is looking good... I need coffee...
|
|
|
Post by johnno56 on Apr 21, 2020 16:56:56 GMT -6
Ok. Finally managed to insert the new high score....
Process: Check if new score qualifies. If not, return to game... if yes. Message "New high score" etc copy the existing high score file Remove original Add player name and score to high score arrays *this is where the sort routine goes* create new high score file remove the copy of the high score file review the new table return to the game
I have tested this process several times and has worked without error... I know! I even surprised myself!
I just need to find and apply a sort routine to the new table. Then I can begin the integration... The only quirk is, now that names have been added to the table, a method of entering a new name will have to be added to the main game... Moo ha ha...
Back to my coffee...
|
|
|
Post by tbird on Apr 21, 2020 20:57:48 GMT -6
Looking awesome, cant wait to play the "final" version!!
|
|
|
Post by johnno56 on Apr 22, 2020 0:33:25 GMT -6
Could someone please look through the attached sort program? These are all direct conversions from various sites. They all work (do not crash) but do not produce the right results. Ignore the crude display. Working on getting the routines to function as they should.
Sort.bas contains two bubble sort routines and a selection sort routine.
The 'only' routine that I can get to work is a shell sort....
I will test these routines using sdlbasic and compare the results....
As soon as the sorting is fixed, I can begin to work on a high score table, assuming I have sufficient wits about me to do so...
I have been working on this all day... A simple sort routine... grrr...
|
|
|
Post by n00b on Apr 22, 2020 12:21:17 GMT -6
Hey johnno, I pointed out an issue with your swap routine in the tips and tricks section. The other issue you are going to run into is that BYREF will always write to index 0 in an array. It is something I am working on fixing currently.
The workaround for that is to just use regular variables.
ex.
Function swap(ByRef a, ByRef b) tmp=a a=b b=tmp End Function
x = 1 y = 2
Print "Pre-Swap" Print "x = ";x Print "y = ";y swap(x,y) Print "\nPost-Swap" Print "x = ";x Print "y = ";y
|
|
|
Post by johnno56 on Apr 22, 2020 15:52:26 GMT -6
Understood...
I changed the swap function, ran the example that you provided (only using swap), and it ran as intended. "a" and "b" were indeed swapped.
I do not think that the swap routine is the cause, in it's original state, it would have contributed...
Reason: Only two of the four sort functions use the swap routine. I think it may be how RC handles arrays. I could be wrong. My limited experience with RC is not helping... lol
I ran all four sort routines. All of them ran to completion. None of them produced a sorted list. Bubblesort2 and Selection use the "new" swap function. Before using the new function, those routines would just produce the unsorted list then hang. (reason for "contributed")
I even tested the shellsort (no swap function) and it to ran but did not sort.
I can understand maybe one or two sort routines failing but all five? I am left with three conclusions: I am doing something wrong; RC does something weird to arrays or I am not meant to have a game with a high score table... Most frustrating... My apologies... The game is far from finished and I am quickly running out of time... It's all too obvious that I lack patience and the ability to cope with pressure... lol I don't know how you guys seem to produce games, with what I would class as, effortlessness... I will continue to look for other sort routines in the meantime...
|
|
|
Post by johnno56 on Apr 22, 2020 17:19:11 GMT -6
Ok. Of all the places to look for a sort routine... Basic256... Who would have thought?
xmax = 640 ymax = 480 title$ = "Sort Test"
WindowOpen(1,title$,windowpos_centered,windowpos_centered,xmax,ymax,0) CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0) ClearCanvas setColor(rgb(255,255,255)) randomize(timer)
maxEntries = 10 temp = 0 sorted = false swapped = 0
dim array[maxEntries + 1] setColor(rgb(255,255,255)) prints("Unsorted...")
for i = 0 to maxEntries - 1 array[i] = rand(100) + 100 prints(str(array[i])) next
setColor(rgb(255,128,0)) prints("Sorted...")
' ============= ' SWAP function ' ============= Function swap( ByRef a, ByRef b ) tmp = a a = b b = tmp End Function
' ===================== BubbleSort ====================== ' The BubbleSort algorithm: ' Comparing adjacent elements dnd swapping pairs that are ' out of order. It continues to do this until there no ' longer any pairs remaining that need to be swapped. ' ====================================================== sub BubbleSort() sorted = false while sorted = false sorted = true for i = 0 to maxEntries - 1 if array[i] > array[i + 1] then ' swap(array[i],array[i + 1]) temp = array[i] array[i] = array[i + 1] array[i + 1] = temp sorted = false end if next wend end sub
BubbleSort()
for i = maxEntries to 1 step -1 prints(str(array[i])) next
waitkey This one actually works! I was looking also for a descending sort, but thought, why not just display the list in reverse?
Bingo! Program ran without error and produced a sorted list.
There is wrinkle... This sounds a bit like, "But wait! There's more..." lol
Run the program using swap (obviously commenting out the 'old school' part... To quote Burt Ward "Robin" (Batman 1966), "Riddle me that one, Batman."
The next part is how to add names... Moo ha ha...
|
|
|
Post by johnno56 on Apr 22, 2020 23:04:58 GMT -6
I'm probably going to need some advise.... (Didn't expect that one, did you? lol)
I have files going left and right; Not knowing Arthur from Martha... (all those general Euphemisms meaning, chaos rules...) On top of that I am trying to figure out how to implement the high score table into the game... I'll probably figure it out eventually, but in the meantime, I'm kind of going nuts try to get my head around all this! I don't know how you guys do it...
Theory: Simplest plan of attack is to have a routine to initialise a 'default' table (in code or external file). Check to see if the player qualifies to be on the list. No. Return to the game. Yes. Insert the player into the list. (which will cause the lowest score to "drop off"). Sort the new table. Remove the old table (after making a copy). Save the new table. Return to the game.
If that sounds about right, let me know, then I will tackle one part of the plan at a time...
I apologise... Stress and I do not play well together....
|
|
|
Post by johnno56 on Apr 23, 2020 0:30:07 GMT -6
Here is a quick question... Let's set the Wayback machine to QBasic... QBasic had the function "Print using()" to format text... This would be ideal for a high score table. Is there a way for RC to emulate that function? Just curious...
|
|