Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Zitat von Glynnder BTW, thats why the maximum fps you get see on a screen is 60 correct? Yes it ...
-
08-17-2006, 02:16 AM #3241QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Yes it is.
Zitat von Glynnder
-
08-17-2006, 02:16 AM #3242QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
i cant display it on the screen tho.. i dunno what the variable is called, i dont really understand the link
Zitat von head_54us
...Just Returned To The Scene...
-
08-17-2006, 02:20 AM #3243QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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.
-
08-17-2006, 02:21 AM #3244QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
thanx, so i use number of sec as the variable? and does it stop at 0?
Zitat von head_54us
...Just Returned To The Scene...
-
08-17-2006, 02:23 AM #3245QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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.
-
08-17-2006, 02:27 AM #3246QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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)...Just Returned To The Scene...
-
08-17-2006, 02:29 AM #3247QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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)
-
08-17-2006, 02:31 AM #3248QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
how the hell do i get it to count down? i got it to count up now...
Zitat von head_54us
...Just Returned To The Scene...
-
08-17-2006, 02:34 AM #3249QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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
-
08-17-2006, 02:38 AM #3250QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
total time limit has to be 200, 10000 makes the time go to 9999 and count down.
Zitat von head_54us
i wanted it at 100 and down
problem i solved myself :P...Just Returned To The Scene...
-
08-17-2006, 02:40 AM #3251QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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.
-
08-17-2006, 02:50 AM #3252QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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
Geändert von JaSo PsP (08-17-2006 um 02:50 AM Uhr) Grund: Automerged Doublepost
...Just Returned To The Scene...
-
08-17-2006, 07:27 AM #3253QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Scotland, UK
- Beiträge
- 571
- Points
- 7.057
- Level
- 55
- Downloads
- 0
- Uploads
- 0
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
-
08-17-2006, 07:32 AM #3254Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
wouldnd it be:
Zitat von mark.sparky
but i guess it depends.Code:if highscore > score then highscore = score end
--------------------------------------------------------------------------------------
-
08-17-2006, 07:34 AM #3255Rock Star

- Registriert seit
- Aug 2005
- Ort
- CT| FW: 4.01 M33-2
- Beiträge
- 11.844
- Points
- 70.899
- Level
- 100
- Downloads
- 0
- Uploads
- 0
No, because then if the high score was greater than the score, the high score would be changed to the lower score.
Zitat von Grimfate126

-
08-17-2006, 07:34 AM #3256QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Scotland, UK
- Beiträge
- 571
- Points
- 7.057
- Level
- 55
- Downloads
- 0
- Uploads
- 0
no because that would be
if highscore is less than score then
highscore equals score
end
which doesnt make any sense
-
08-17-2006, 07:45 AM #3257QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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 von Grimfate126
...Just Returned To The Scene...
-
08-17-2006, 07:55 AM #3258I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
write contents
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.
-
08-17-2006, 07:56 AM #3259QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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 von Access_Denied
ps: what does the w and r mean on the io open brackets?
hi score works nowGeändert von JaSo PsP (08-17-2006 um 08:12 AM Uhr) Grund: Automerged Doublepost
...Just Returned To The Scene...
-
08-17-2006, 08:15 AM #3260I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
The "w" means write and the "r" means read
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.
-
08-17-2006, 08:16 AM #3261QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Scotland, UK
- Beiträge
- 571
- Points
- 7.057
- Level
- 55
- Downloads
- 0
- Uploads
- 0
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
-
08-17-2006, 08:17 AM #3262I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
He wants the "w" though, because he wants to write over the existing high score.
Zitat von mark.sparky

-
08-17-2006, 08:21 AM #3263QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Scotland, UK
- Beiträge
- 571
- Points
- 7.057
- Level
- 55
- Downloads
- 0
- Uploads
- 0
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
-
08-17-2006, 08:43 AM #3264QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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)
...Just Returned To The Scene...
-
08-17-2006, 08:46 AM #3265I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
What's the error?
Zitat von JaSo PsP

-
08-17-2006, 08:48 AM #3266QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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 von Access_Denied
...Just Returned To The Scene...
-
08-17-2006, 08:51 AM #3267sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
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
-
08-17-2006, 08:52 AM #3268QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Scotland, UK
- Beiträge
- 571
- Points
- 7.057
- Level
- 55
- Downloads
- 0
- Uploads
- 0
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
-
08-17-2006, 08:57 AM #3269QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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 von mark.sparky
Geändert von JaSo PsP (08-17-2006 um 08:57 AM Uhr) Grund: Automerged Doublepost
...Just Returned To The Scene...
-
08-17-2006, 08:57 AM #3270Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
u probably declared the value of either "score" or "theHighScore" as a string.
post the code where u declare the vars.--------------------------------------------------------------------------------------


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum