Yes it is.Zitat:
Zitat von Glynnder
Printable View
Yes it is.Zitat:
Zitat von Glynnder
i cant display it on the screen tho.. i dunno what the variable is called, i dont really understand the linkZitat:
Zitat von head_54us
Blah = Timer.new() -- Creates a new timer object called Blah. Starts from 0
Blah:start() -- Starts the timer
NumberOfMs = Blah:time() -- Gets the number of milliseconds from the timer since the timer started + the start value
NumberOfSec = math.floor(NumberOfMs /1000) -- Converts from Ms to Secs rounded down.
thanx, so i use number of sec as the variable? and does it stop at 0?Zitat:
Zitat von head_54us
Don't copy and paste that code into your program. I only wrote it to describe how to call and use the functions. You have to apply that knowledge to your code.
timer dont count down:
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)
boost = 1000
score = 0
x = 0
y = 5
NumberOfMs = levelTimer:time()
NumberOfSec = math.floor(NumberOfMs/1000)
function booster()
if boost < 1 then
boost = 0
end
boost = boost - 1
end
function CheckBoxCollisionHack()
if ((x + 36) > rx) and (x < (rx + 36)) then
if ((y + 36) > ry) and (y < (ry + 36)) then
return true
end
end
return false
end
while true do
screen:clear()
screen:blit(0,0,background)
screen:print(0,263,"Press X for SPEED BOOST",red)
screen:print(0,0,"Boost Left: "..boost ,red)
screen:print(0,7,"Time: "..NumberOfSec,red)
screen:blit(x, y, smiley)
screen:blit(rx, ry, sad)
They count up. These two lines are also incorrect in terms of where you put them in your code
Code:NumberOfMs = levelTimer:time()
NumberOfSec = math.floor(NumberOfMs/1000)
how the hell do i get it to count down? i got it to count up now...Zitat:
Zitat von head_54us
Seriously, these are really simple abstract problems that you should be able to solve yourself.Code:TotalTimeLimit = 100000
-- Later on in your code
NumberOfMs = levelTimer:time()
NumberOfSec = math.floor(NumberOfMs/1000)
TimeLeft = TotalTimeLimit - NumberOfSecs
total time limit has to be 200, 10000 makes the time go to 9999 and count down.Zitat:
Zitat von head_54us
i wanted it at 100 and down
problem i solved myself :P
That's because you start the timer right at the start of your code, by the time the time left has started, the PSP has already spent 1sec loading in graphics and getting to the main loop.
Edit: Oh you meant you wanted 100 seconds. Nevermind then.
now i need to make the hi score save if its higher than the current hi score, how does this work?
-= Double Post =-
also, whats wrong with this:
g2g for lunch now.. ill check back here l8r for answers.Code:if TimeLeft < 1 then
screen:clear
screen:print(200,135,"Game Over, Your score was: "..score,red)
end
jaso you need a parentheses after the screen:clear so it looks like this screen:clear() and for the hi-score do something like this
if highscore < score then
highscore = score
end
wouldnd it be:Zitat:
Zitat von mark.sparky
but i guess it depends.Code:if highscore > score then
highscore = score
end
No, because then if the high score was greater than the score, the high score would be changed to the lower score.Zitat:
Zitat von Grimfate126
no because that would be
if highscore is less than score then
highscore equals score
end
which doesnt make any sense
it still wouldnt save it, when i reset the game, the high score will go down to nil, i want it so it writes the high score to a file. also how would i read the contents of that file? (anyone who helps me will go down on a list of all the people that have helped me and they will get some credit for the finished game)Zitat:
Zitat von Grimfate126
write contentsZitat:
Zitat von JaSo PsP
score = io.open("score.txt","w")
score:write(highscore)
score:close()
read
highscore = io.open("score.txt","r")
thehighscore = highscore:read()
highscore:close()
With the read function, the variable "thehighscore" is you high score read from the file.
this works by the way:
-= Double Post =-Code:if TimeLeft < 1 then
levelTimer:stop()
screen:clear()
screen:print(200,100,"Game Over, Your Score was: "..score,red)
end
thanx, this game is so near completion. ill submit it soon.Zitat:
Zitat von Access_Denied
ps: what does the w and r mean on the io open brackets?
hi score works now
The "w" means write and the "r" means readZitat:
Zitat von JaSo PsP
Go to evilmana.com and look at thier tutorial on reading and writing files. It'll give you a whole list of functions like that.
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.
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..