here's my full code for displaying a custom high score system:
// instance vars
var buffer = 0
var trigger = 0
// display setup
draw_set_font(fnt_highscores)
draw_set_color(c_white)
draw_set_halign(fa_left)
draw_set_valign(fa_middle)
// open save
ini_open("highscores.sav")
// reads file into 2d array
for (var i=0; i<10; i++)
{
scores[0,i] = ini_read_string(string(i+1), "place", 0)
scores[1,i] = ini_read_string(string(i+1), "name", 0)
scores[2,i] = ini_read_string(string(i+1), "score", 0)
}
// cycles through array to look for new high score
for (var i=0; i<10; i++)
{
// found one, run once.
if (global.points >= int64(scores[2,i]) && trigger == 0)
{
// starting from bottom, move value from number above to current
for (var j=9; j>i; j--)
{
scores[0,j] = scores[0,j-1]
scores[1,j] = scores[1,j-1]
scores[2,j] = scores[2,j-1]
}
// new high score
var initials = "beef"
scores[0,i] = string(i+1)
scores[1,i] = initials
scores[2,i] = global.points
trigger++
}
// display score
var j = i + 1
draw_text(global.centerw - 150, global.centerh - 220 + buffer, string(j) + ".")
draw_text(global.centerw - 100, global.centerh - 220 + buffer, scores[1,i])
draw_text(global.centerw + 20, global.centerh - 220 + buffer, scores[2,i])
buffer += 40
}
// write to file - NOT WORKING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for (var i=0; i<10; i++)
{
ini_write_string(string(i+1), "place", scores[0,i])
ini_write_string(string(i+1), "name", scores[1,i])
ini_write_string(string(i+1), "score", string(scores[2,i]))
}
// close save
ini_close()
// draws flashing text
scr_flash_alpha(300)
draw_text(50,room_height - 50, "Start or R Key to Restart. Q to quit")
draw_set_alpha(1)
The "write to file" lines (near the buttom) is causing the issues. Here's what it's doing when I beat a high score:
Interestingly, if I comment out the write to ini lines, everything works perfectly as intended (just doesn't save the info to the ini, obviously)
So, all my looping IS working, just when it goes to write to the ini it isn't writting the values correctly. Any hints? I've been re-writing this for hours and getting no where laughs
Thank you so much in advance!!!
(EDIT: Here's my highscores.sav - note that entries 10 and 9 are exactly identical, down to the "place" value. Also interesting is that it starts at 10 and works it's way to 1. When I wrote the default saves, I numbered them 1-10.)
[10]
score="2500"
name="beef"
place="9"
[9]
score="2500"
name="beef"
place="9"
[8]
score="3000"
name="ASS"
place="8"
[7]
score="3800"
name="MAL"
place="7"
[6]
score="4600"
name="ADO"
place="6"
[5]
score="5500"
name="DSK"
place="5"
[4]
score="5500"
name="DIS"
place="4"
[3]
score="5900"
name="PPS"
place="3"
[2]
score="6100"
name="DSK"
place="2"
[1]
score="6800"
name="PSF"
place="1"
(side note: I know there's a few sloppy things in the code here and there, will be cleaning it all up once this is functioning.)