the w means write and the r means read but watch out because w means to overwite what was in that file and a means to write after what was already there
Printable View
the w means write and the r means read but watch out because w means to overwite what was in that file and a means to write after what was already there
He wants the "w" though, because he wants to write over the existing high score.Zitat:
Zitat von mark.sparky
i know i was just telling him in case he wanted to know.
Anway on to my problem. What is wrong with this code because the all the barricades appear at once and the score goes straight to the highest
Code:function firstLevel()
level1 = math.random( 1,60)
if level1 == 24 then
barricade[1].pic = true
barricade[2].pic = false
barricade[3].pic = false
barricade[4].pic = false
barricade[5].pic = false
barricade[6].pic = false
end
if level1 == 49 then
barricade[1].pic = false
barricade[2].pic = true
barricade[3].pic = false
barricade[4].pic = false
barricade[5].pic = false
barricade[6].pic = false
end
if level1 == 1 then
barricade[1].pic = false
barricade[2].pic = false
barricade[3].pic = true
barricade[4].pic = false
barricade[5].pic = false
barricade[6].pic = false
end
if level1 == 15 then
barricade[1].pic = false
barricade[2].pic = false
barricade[3].pic = false
barricade[4].pic = true
barricade[5].pic = false
barricade[6].pic = false
end
if level1 == 59 then
barricade[1].pic = false
barricade[2].pic = false
barricade[3].pic = false
barricade[4].pic = false
barricade[5].pic = true
barricade[6].pic = false
end
if level1 == 33 then
barricade[1].pic = true
barricade[2].pic = false
barricade[3].pic = false
barricade[4].pic = false
barricade[5].pic = false
barricade[6].pic = true
end
if barricade[1].pic == true then
barricade[1].lane = true
end
if barricade[1].lane == true then
screen:blit( barricade[1].x, barricade[1].y, barricade1)
barricade[1].x = barricade[1].x - 0.25
end
if barricade[1].x == 0 then
barricade[1].lane = false
end
if barricade[2].pic == true then
barricade[2].lane = true
end
if barricade[2].lane == true then
screen:blit( barricade[2].x, barricade[2].y, barricade1)
barricade[2].x = barricade[2].x - 0.25
end
if barricade[2].x == 0 then
barricade[2].lane = false
end
if barricade[3].pic == true then
barricade[3].lane = true
end
if barricade[3].lane == true then
screen:blit( barricade[3].x, barricade[3].y, barricade1)
barricade[3].x = barricade[3].x - 0.25
end
if barricade[3].x == 0 then
barricade[3].lane = false
end
if barricade[4].pic == true then
barricade[4].lane = true
end
if barricade[4].lane == true then
screen:blit( barricade[4].x, barricade[4].y, barricade1)
barricade[4].x = barricade[4].x - 0.25
end
if barricade[4].x == 0 then
barricade[4].lane = false
end
if barricade[5].pic == true then
barricade[5].lane = true
end
if barricade[5].lane == true then
screen:blit( barricade[5].x, barricade[5].y, barricade1)
barricade[5].x = barricade[5].x - 0.25
end
if barricade[5].x == 0 then
barricade[5].lane = false
end
if barricade[6].pic == true then
barricade[6].lane = true
end
if barricade[6].lane == true then
screen:blit( barricade[6].x, barricade[6].y, barricade1)
barricade[6].x = barricade[6].x - 0.25
end
if barricade[6].x == 0 then
barricade[6].lane = false
end
if lane == 0 and barricade[1].x <= (player[1].x + player[1].width) then
player[1].life = player[1].life - 1
barricade[1].x = 0
end
if lane == 1 and barricade[2].x <= (player[1].x + player[1].width) then
player[1].life = player[1].life - 1
barricade[1].x = 0
end
if lane == 2 and barricade[3].x <= (player[1].x + player[1].width) then
player[1].life = player[1].life - 1
barricade[1].x = 0
end
if lane == 3 and barricade[4].x <= (player[1].x + player[1].width) then
player[1].life = player[1].life - 1
barricade[1].x = 0
end
if lane == 4 and barricade[5].x <= (player[1].x + player[1].width) then
player[1].life = player[1].life - 1
barricade[1].x = 0
end
if lane == 5 and barricade[6].x <= (player[1].x + player[1].width) then
player[1].life = player[1].life - 1
barricade[1].x = 0
end
if lane ~= 0 and barricade[1].x <= (player[1].x + player[1].width) then
player[1].score = player[1].score + 2
player[1].lifescore = player[1].lifescore + 2
barricade[1].x = 0
if highscore < player[1].score then
highscore = highscore + 2
end
end
if lane ~= 1 and barricade[2].x <= (player[1].x + player[1].width) then
player[1].score = player[1].score + 2
player[1].lifescore = player[1].lifescore + 2
barricade[1].x = 0
if highscore < player[1].score then
highscore = highscore + 2
end
end
if lane ~= 2 and barricade[3].x <= (player[1].x + player[1].width) then
player[1].score = player[1].score + 2
player[1].lifescore = player[1].lifescore + 2
barricade[1].x = 0
if highscore < player[1].score then
highscore = highscore + 2
end
end
if lane ~= 3 and barricade[4].x <= (player[1].x + player[1].width) then
player[1].score = player[1].score + 2
player[1].lifescore = player[1].lifescore + 2
barricade[1].x = 0
if highscore < player[1].score then
highscore = highscore + 2
end
end
if lane ~= 4 and barricade[5].x <= (player[1].x + player[1].width) then
player[1].score = player[1].score + 2
player[1].lifescore = player[1].lifescore + 2
barricade[1].x = 0
if highscore < player[1].score then
highscore = highscore + 2
end
end
if lane ~= 5 and barricade[6].x <= (player[1].x + player[1].width) then
player[1].score = player[1].score + 2
player[1].lifescore = player[1].lifescore + 2
barricade[1].x = 0
if highscore < player[1].score then
highscore = highscore + 2
end
end
if player[1].lifescore == 40 then
player[1].life = player[1].life + 1
player[1].lifescore = 0
end
end
i get an error with this... i was so close to releasing the game...
the error message says cant compare number with string but they are both variables!!??Code:if TimeLeft < 1 then
levelTimer:stop()
screen:clear()
if score > theHighScore then --this line brings up error
writeHiScore()
end
screen:print(150,100,"Game Over, Your Score was: "..score,red)
end
this line works with thehighscore??:
screen:print(270,263,"Hi Score: "..theHighScore,red)
What's the error?Zitat:
Zitat von JaSo PsP
cant compare string with number but they are both variables? or, it doesnt recognice the hiscore in the txt document as a number? how can i sort this out?Zitat:
Zitat von Access_Denied
a string is usually a line of characters (a.b.c.d. ect...) Also where are you declaring those two variables? That could be the problem as well
You need if score < thehighscore then instead of if score > thehighscore then and also have you put
file = io.open("the highscore file","w")
file:write(thehighscore)
file:close()
in the code and just to tell you < is less than and > is greater than
these are the variables at the start. theres nothing wrong cos it can display them in the game:
-= Double Post =-Code:highscore = io.open("hiscore.txt","r")
theHighScore = highscore:read() --this is where it reads the file, it doesnt read it as a number
score = 0
yer, it cant read the info in the document as a number, help!Zitat:
Zitat von mark.sparky
u probably declared the value of either "score" or "theHighScore" as a string.
post the code where u declare the vars.