Thanks to Virtual Nomad for your help.
This will save and load top 10 scores and names on WIN.
save location...
C:/users/[name]/AppData/Local/AGKApps/YOUR GAME NAME/media/save.dat
// Project: load save top 10 scores
// Created: 24-05-19
SetErrorMode(2)
//SetVSync(1)
width# = GetMaxDeviceWidth()
height# = GetMaxDeviceHeight()
SetWindowSize(width#,height#,1)
SetSyncRate(30,0)
SetDisplayAspect(-1.0)
SetScissor(0,0,0,0)
UseNewDefaultFonts(1)
SetPrintSize(3)
SetSkyboxVisible(1)
SetSkyBoxHorizonColor(0,0,0)
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx top 10 hi scores setup, load and first save
// C:/users/[name]/AppData/Local/AGKApps/YOUR GAME NAME/media/save.dat << you can delete save file here to reset scores
type scores
name$ as string
data as integer
endtype
global dim scored[10] as scores
global dim slider[10] as scores
if GetFileExists("save.dat")
ThisFile = OpenToRead("save.dat")
ThisSave$ = ReadLine(ThisFile)
else
ThisSave$ = "missing"
endIf
if ThisSave$ <> "missing"
Total = CountStringTokens(ThisSave$, "|") //total sets of paired data in string
for x = 1 to Total
ThisStat$ = GetStringToken(ThisSave$, "|", x) //divide the paired info (name$:data) and assign
scored[x].name$ = GetStringToken(ThisStat$,":", 1)
scored[x].data = VAL(GetStringToken(ThisStat$,":", 2))
next x
else // if missing then save default hi score file
for x=1 to 10
scored[x].name$ = "ando"
scored[x].data = (11-x)*1000
next x
//create respective pairs of data (name:score)
first$=scored[1].name$+":"+str(scored[1].data)
second$=scored[2].name$+":"+str(scored[2].data)
third$=scored[3].name$+":"+str(scored[3].data)
fourth$=scored[4].name$+":"+str(scored[4].data)
fifth$=scored[5].name$+":"+str(scored[5].data)
sixth$=scored[6].name$+":"+str(scored[6].data)
seventh$=scored[7].name$+":"+str(scored[7].data)
eighth$=scored[8].name$+":"+str(scored[8].data)
nineth$=scored[9].name$+":"+str(scored[9].data)
tenth$=scored[10].name$+":"+str(scored[10].data)
//combine individual data sets separated by pipes |
SaveString$ = first$ + "|" + second$ + "|" + third$ + "|" + fourth$ + "|" + fifth$ + "|" + sixth$ + "|" + seventh$ + "|" + eighth$ + "|" + nineth$ + "|" + tenth$
ThisFile = OpenToWrite("save.dat")
WriteLine(ThisFile,SaveString$) //can use WriteString() to make "unreadable"
CloseFile(ThisFile)
endif
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
entername=LoadSound("please enter your name.wav")
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx title screen loop
start:
repeat
for x=1 to 10
print(" "+str(x)+" "+scored[x].name$+" "+str(scored[x].data))
next x
for i=1 to 5
print(" ")
next i
print("")
print("")
print(" TITLE SCREEN GOES HERE")
print("")
print("")
print(" spacebar to continue")
print(" escape to quit")
sync()
if GetrawKeyPressed(27) then end // Escape key quits program
until GetRawKeyPressed(32) // spacebar to continue
// keep this if you want the save name voice
playname=0
// keep and use these 2 variables
score=0
gameover=0
do
print(" Top 10 Score Rank "+str(slot))
print(" SCORE "+str(score))
print("")
print("")
print("")
print(" hold Z key to simulate increasing score")
print(" press X key to simulate gameover")
if getrawkeystate(90) then score=score+random(50,100) // Z key
if getrawkeystate(88) then gameover=1 // X key
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx prepare and save
for x=9 to 1 step -1
if score < scored[10].data then slot=11
if score > scored[x+1].data
if score < scored[x].data
slot=x+1
endif
endif
if score > scored[1].data then slot=1
next x
if gameover=1
if slot < 11
for x=9 to 1 step -1
slider[x+1].name$=scored[x].name$
slider[x+1].data=scored[x].data
next x
StartTextInput()
text$ = ""
playname=1
repeat
if not GetSoundInstancePlaying(inst)
if playname=1
inst=playsound(entername,70,0)
playname=2
endif
endif
text$ = GetTextInput ( )
if text$="" then text$="HAHA"
sync()
until getrawkeypressed(13)
endif
gameover=2
endif
if gameover=2
for x=10 to 1 step -1
if x>slot
scored[x].name$=slider[x].name$
scored[x].data=slider[x].data
endif
if x=slot
scored[x].name$=text$
scored[x].data=score
endif
next x
gameover=3
endif
if gameover=3
//create respective pairs of data (name:score)
first$=scored[1].name$+":"+str(scored[1].data)
second$=scored[2].name$+":"+str(scored[2].data)
third$=scored[3].name$+":"+str(scored[3].data)
fourth$=scored[4].name$+":"+str(scored[4].data)
fifth$=scored[5].name$+":"+str(scored[5].data)
sixth$=scored[6].name$+":"+str(scored[6].data)
seventh$=scored[7].name$+":"+str(scored[7].data)
eighth$=scored[8].name$+":"+str(scored[8].data)
nineth$=scored[9].name$+":"+str(scored[9].data)
tenth$=scored[10].name$+":"+str(scored[10].data)
//combine individual data sets separated by pipes |
SaveString$ = first$ + "|" + second$ + "|" + third$ + "|" + fourth$ + "|" + fifth$ + "|" + sixth$ + "|" + seventh$ + "|" + eighth$ + "|" + nineth$ + "|" + tenth$
ThisFile = OpenToWrite("save.dat")
WriteLine(ThisFile,SaveString$) //can use WriteString() to make "unreadable"
CloseFile(ThisFile)
gameover=4
endif
sync()
if GetrawKeyPressed(27) or gameover=4 then goto start // Escape key
loop
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.