well have you put a number in the highscore text
Printable View
well have you put a number in the highscore text
Im not great with lua but you opened the file with an "r" tag? Wont that mean you can only read?Zitat:
Zitat von JaSo PsP
NVM, read mark.sarpkys post.Zitat:
Zitat von JaSo PsP
here:
-= Double Post =-Code:levelTimer = Timer.new(100000)
levelTimer:start()
red = Color.new(255,0,0)
background = Image.load("cloud.png")
smiley = Image.load("smile.png")
sad = Image.load("sad.png")
math.randomseed(os.time())
rx = math.random(0,442)
ry = math.random(0,234)
highscore = io.open("hiscore.txt","r")
whighscore = io.open("hiscore.txt","w")
theHighScore = highscore:read()
boost = 2000
score = 0
x = 0
y = 5
TotalTimeLimit = 130
yes i have, it was 0 but i changed it to 10 and thats all thats there.Zitat:
Zitat von mark.sparky
cmon help me!!!
The problem here is that when you read from a file, its reading it in as a string, not a number. Therefore you cannot compare a number with the string.
so how can i save a high score?Zitat:
Zitat von head_54us
At the moment I am looking for a string to number/integer function in Lua (I really don't fancy writing one myself) but can't find any.
k, im gonna fishish off the game and post it without the hiscore thing.Zitat:
Zitat von head_54us
-= Double Post =-
what do i write to make the whole thing restart? well?
Note that this code is for a standalone project only. You MUST press start to exit otherwise the file doesn't not get saved:
Code:WHITE = Color.new(255, 255, 255)
highscore = io.open("hiscore.txt","r")
theHighScore = highscore:read("*number")
highscore:close()
currentScore = 0
while true do
PspPadState = Controls.read();
if PspPadState:start() then
break;
end
if PspPadState:circle() then
currentScore = currentScore + 1
end
screen:clear(WHITE)
screen:print(1,1, "High Score " .. theHighScore)
screen:print(1,9, "Current Score " .. currentScore)
screen.waitVblankStart();
screen.flip();
end
if currentScore > theHighScore then
highscore = io.open("hiscore.txt","w")
highscore:write(currentScore)
highscore:close()
end
it works but the mem stik light keeps flashing, when i exit the app after bout 10 seconds of flashing it has saved the score?Zitat:
Zitat von head_54us
-= Double Post =-
sorted it out with the flashing..