Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Can't read txt file

Author
Message
beredentod
6
Years of Service
User Offline
Joined: 24th Aug 2018
Playing:
Posted: 24th Aug 2018 17:22
Hello!

I'm working on a simple arcade game in App Game Kit. I've been struggling with saving and loading data from txt file for over a week.
Here's my code:
#constant HIGHSCORE_FILE$ = "data.txt"

Function Read_High_Score()

if not GetFileExists(HIGHSCORE_FILE$) then NewHighscoreFile()
local filein as integer
filein = OpenToRead(HIGHSCORE_FILE$)
highscore = val(ReadLine(filein))
CloseFile(filein)
Endfunction

Function Write_High_Score()

Local fileout as Integer
highscore = score
fileout = OpenToWrite(HIGHSCORE_FILE$,0)
WriteLine(fileout, str(highscore))
Closefile(fileout)

Endfunction

Function NewHighscoreFile()
Local fileout as Integer
fileout = OpenToWrite(HIGHSCORE_FILE$,0)
WriteLine(fileout, str(0))
Closefile(fileout)
EndFunction

I work on Linux.
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 25th Aug 2018 19:59
I do not see you passing highscore to the function. Is it Global somewhere? Did you possibly misspell it somewhere? Maybe it is defined as Global hihgscore or some other misspelling, and when you use highscore =100 it is now using a local version (default when a variable hasn't been declared). I like to use#option_explicit at the top of the source which forces you to declare all variable before use, catching any possible misspellings.

Login to post a reply

Server time is: 2024-11-23 18:10:14
Your offset time is: 2024-11-23 18:10:14