sorting our arrays its very complicated,
but first, im not suggesting you to use multi arrays. its not that implented well in dbp. use types instead.
`%Project Title%
`%Source File Name%
`======================
type TScoreList
Name as String
Score as Integer
endtype
txt as string
var as byte
var = 0
NewName as String
NewScore as Integer
//after you created scores, the scores gonna be loaded on next time you run the game. enjoy! :)
LoadScoresFromFile("Scores.txt")
do
cls
txt = Entry$(1)
//name
if var = 0
text 0,0,"Name >: "+txt
if EnterKey=1 and len(txt) > 2
var = 1
txt = left$(txt,len(txt)-1);
NewName = txt
txt = ""
clear entry buffer
endif
endif
//Score Number
if var = 2 then var = 0
if var = 1
text 0,0,"Name: "+NewName
text 0,15,"Score >: "+txt
if EnterKey=1 and val(txt)>0
var = 2
txt = left$(txt,len(txt)-1);
NewScore = val(txt)
txt = ""
AddToScoreBoard(NewName,NewScore)
NewName = ""
NewScore = 0
var = 2
clear entry buffer
//Saving the score to file..
SaveHighScoreToFile("Scores.txt")
endif
endif
ShowScores()
EnterKeyJunk()
loop
function ShowScores()
a as integer
text 200,0,"Score List:"
for a=0 to array count(MyScore())
text 210,15+(15*a),MyScore(a).Name+" scored: "+str$(MyScore(a).Score)
next a
endfunction
function AddToScoreBoard(name as String,Score as Integer)
dim MyScore(array count(MyScore())+1) as TScoreList
a as integer
a = array count(MyScore())
MyScore(a).Name = ""
MyScore(a).Score = 0
b as integer
c as integer
//if the score is empty, then add new score normaly. if not, then find the place in the score tree..
if a = 0
MyScore(a).Name = Name
MyScore(a).Score = Score
Exitfunction
endif
b = a
repeat
if MyScore(b).Score > Score
//checking the score tree from down to up by scores. if the score is bigger then the one before him then it will add the person to that position..
for c = a to b+1 step -1
MyScore(c) = MyScore(c-1)
next c
//now, after we moved all the scores from the spot to bottom, we can register the new score to b+1
MyScore(b+1).Name = Name
MyScore(b+1).Score = Score
exitfunction
endif
dec b
until b=-1
//now, if the score is bigger than all the scores, make him on top:
for c = a to 1 step -1
MyScore(c) = MyScore(c-1)
next c
MyScore(0).Name = Name
Myscore(0).Score = Score
endfunction
global EnterKey as Byte
function EnterKeyJunk()
if EnterKey = 3 then EnterKey = 0
if returnkey()=0 and EnterKey = 2 then EnterKey = 3
if EnterKey = 1 then EnterKey = 2
if EnterKey = 0 and returnkey()=1 then EnterKey = 1
endfunction
function SaveHighScoreToFile(fname as String)
a as integer
if file exist(fname)=1 then delete file fname
open to write 1,fname
for a=0 to array count(MyScore())
write string 1,"Name: "+MyScore(a).Name
write string 1,"Score: "+str$(MyScore(a).Score)
next a
close file 1
endfunction
function LoadScoresFromFile(fname as String)
if file exist(fname)=0 then exitfunction
//Empty the array
dim MyScore(0) as TScoreList
empty array MyScore()
Name as String
Score as Integer
a as integer
open to read 1,fname
repeat
read string 1,s$
if left$(s$,len("Name: ")) = "Name: " then Name = right$(s$,len(s$)-len("Name: "))
if left$(s$,len("Score: ")) = "Score: "
Score = val(right$(s$,len(s$)-len("Score: ")))
dim MyScore(array count(MyScore())+1) as TScoreList
a = array count(MyScore())
MyScore(a).Name = Name
MyScore(a).Score = Score
endif
until file end(1)
close file 1
endfunction
this seens the last 7.7 bug fix, there was a massive change in array, so if you got array error inside it, you will have to upgrade your dbp version to the beta one.
as i said before, sorting arrays is very complicated, but it is possible.
i hope you understand the code, cuz its not that easy to read.
[edit] wtf! his thread is moved (i see only my answer to his thread but i dont see his thread at all.. lol)
more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]