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; Ok thanks i will try this - but this only checks if the file exists, right? I'm trying to make ...
-
08-03-2007, 03:48 PM #7861.info

- Registriert seit
- Jun 2006
- Ort
- ACT, Australia
- Beiträge
- 1.674
- Points
- 15.395
- Level
- 80
- Downloads
- 0
- Uploads
- 0
Ok thanks i will try this - but this only checks if the file exists, right? I'm trying to make sure that the image can actually be used (ie. PNG's over 512x512)
-
08-03-2007, 04:57 PM #7862QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
i never did this before, but looking at this list, i'd say this is how to do it:
Zitat von Yongobongo
please correct if i am wrong thoughCode:test = Image.load("test.png") testX = test.width() testY = test.height() if testX*testY >= 512*512 then [blah blah] end
-
08-03-2007, 05:21 PM #7863
if the image can't be loaded then using Image.load on it will cause the script to break and show the error message, but from what I understand what Yongo wants to do is check to see if an image can be loaded in order to avoid having Image.load break the script
There are two ways that I can see for doing this. The first would be to do research on the format of the .png header and write a function that could open it as a data file to read the image dimensions and other stuff from the header. The second would be to get into the lua player source and either add a new function to check if the image can be loaded, or else change the Image.load function to prevent it from throwing the error
-
08-03-2007, 10:50 PM #7864
O.k. I've put the code to recall the random numbers after the correct/incorrect message is shown. Now there is a random bug where I only press the button once, but I get about 2-5 incorrect/correct messages. E.G. I could press left once but the screen shows correct then correct then incorrect then correct again.
PS The code is the same except after scren.flip() i've added RanNumber = math.random(1,11)
PPS If anyone doesn't know what code i'm talking about go to page 784. It isn't hard to find. ;)
-
08-04-2007, 06:06 AM #7865QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Your problem is that the button is being pressed for more than one loop. You could use timers, and pause it after a question, or you could use this:
Code:oldpad = Controls.read() while true do pad = Controls.read() if (pad:left() ~= oldpad:left()) and pad:left() then bla bla bla end oldpad = pad end
P.S. Can anyone point me to a non-pixel based, circle-rectangle collision algorithm that works with a diagonal rectangle? It would save me some time.
-
08-04-2007, 11:59 AM #7866
I've tried putting in what you suggested but it doesn't make a difference.
Zitat von Nielkie
[EDIT]
I've decided to remake the game from scratch. I've keep getting bug after bug after bug and it's completely useless.
[EDIT]
I've redone the code. I now have an error saying bad argument #1 to 'len' (string expected, got nil). Any ideas how to fix this?
Code:math.randomseed(os.time()); NUM_QUESTIONS = 12 NUM_ANSWERS = 12 question = {} question[1] = { name = "What countries did Vikings originate from?", answer = {"A: Germany, England and Iceland","B: Greenland, Germany and Iceland","C: Denmark, Sweden and Norway","D: Iceland, Sweden, Norway"}, correctAnswer = 3 } question[2] = { name = "Why did the Vikings originally travel to other countries?", answer = {"A: To trade","B: To plunder","C: To kill","D: To sieze power"}, correctAnswer = 1 } question[3] = { name = "Vikings had a reputation for being what in battle?", answer = {"A: Couragous","B: Random","C: Strong","D: Skilled"}, correctAnswer = 4 } question[4] = { name = "What weapons were used by the Vikings?", answer = {"A: Bows, Rifles and Swords","B: Sword, Double-Axe and Spear","C: Cannons, Arrows and Bows","D: Sword, Arrows and Canons"}, correctAnswer = 2 } question[5] = { name = "What was the common name of the plague in medieval Europe?", answer = {"A: Black Plague","B: Dark Plague","C: Black Death","D: Bubonic Death"}, correctAnswer = 3 } question[6] = { name = "How long did the Hundred Years' War last?", answer = {"A: 100","B: 116","C: 84","D: 136"}, correctAnswer = 2 } question[7] = { name = "What spread the Bubonic Plague?", answer = {"A: Rats","B: Ticks","C: Fleas","D: Beavers"}, correctAnswer = 3 } question[8] = { name = "What objects were Vikings buried in?", answer = {"A: Their Ships","B: Graves","C: Crypts","D: Their Homes"}, correctAnswer = 1 } question[9] = { name = "What was another name for Vikings", answer = {"A: Plunderers","B: Norsemen","C: Wolfmen","D: They didn't have other names"}, correctAnswer = 2 } question[10] = { name = "What countries did Vikings originate from?", answer = {"A: Denmark, Sweden and Norway","B: Greenland, Iceland and Norway","C: Iceland, Germany and Norway","D: Germany, England and Iceland"}, correctAnswer = 1 } question[11] = { name = "Knights fought on what?", answer = {"A: Slaves","B: Cows","C: Horses","D: Their Feet"}, correctAnswer = 3 } question[12] = { name = "What 4 empires existed prior to the Dark Ages?", answer = {"A: Roman, Persian, English and American","B: Roman, Guptan, Persian and Barbarian","C: Japanese, Chinese, Guptan and Roman","D: Roman, Guptan, Persian and Chinese"}, correctAnswer = 4 } function printCentered(y,text,color) local length = string.len(text) local x = 240 - ((length*8)/2) screen:print(x,y,text,color) end currentQuestion = math.random(1, NUM_QUESTIONS) correct = 0 incorrect = 0 oldQuestion = 0 oldpad = Controls.read() while true do pad = Controls.read() if oldpad ~= pad then if pad:left() then if question[currentQuestion].correctAnswer == 1 then correct = correct + 1 else incorrect = incorrect + 1 end oldQuestion = currentQuestion while currentQuestion == oldQuestion do currentQuestion = math.random(1,12) end elseif pad:right() then if question[currentQuestion].correctAnswer == 2 then correct = correct + 1 else incorrect = incorrect + 1 end oldQuestion = currentQuestion while currentQuestion == oldQuestion do currentQuestion = math.random(1,12) end elseif pad:square() then if question[currentQuestion].correctAnswer == 3 then correct = correct + 1 else incorrect = incorrect + 1 end oldQuestion = currentQuestion while currentQuestion == oldQuestion do currentQuestion = math.random(1,12) end elseif pad:circle() then if question[currentQuestion].correctAnswer == 4 then correct = correct + 1 else incorrect = incorrect + 1 end oldQuestion = currentQuestion while currentQuestion == oldQuestion do currentQuestion = math.random(1,12) end end end oldpad = pad screen:clear() if correct + incorrect == 50 then break end printCentered(140,question[currentQuestion].name, Color.new(255,255,255)) for i=1,NUM_ANSWERS do printCentered(160 + i*15,question[currentQuestion].answer[i], Color.new(200,200,200)) end printCentered(10,"Correct: " .. correct .. " Incorrect: " .. incorrect, Color.new(255,255,255)) screen.waitVblankStart() screen.flip() endGeändert von drag_93 (08-05-2007 um 09:54 PM Uhr)
-
08-06-2007, 09:17 PM #7867
- Registriert seit
- Aug 2007
- Beiträge
- 1
- Points
- 3.059
- Level
- 34
- Downloads
- 0
- Uploads
- 0
I made lua program, now I want to know How I can make EBOOT from my lua program. It isn't very funny to start lua player every time, before starts my program.
I am sorry for my bad english.
-
08-06-2007, 09:53 PM #7868
To compile an eboot you need cygwin (linux emulator for windows) and psptoolchain. However, because you used Lua as a programming language, you can't compile it into an eboot file.
Zitat von ISO-B
-
08-06-2007, 10:11 PM #7869QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
@drag_93: NUM_ANSWERS should be 4.
P.S. Save some space:
@ISO-B: See http://www.forums.evilmana.com/index.php?topic=861.0Code:if oldpad ~= pad then if pad:left() then answer = 1 elseif pad:right() then answer = 2 elseif pad:square() then answer = 3 elseif pad:circle() then answer = 4 end end if question[currentQuestion].correctAnswer == answer then correct = correct + 1 oldQuestion = currentQuestion while currentQuestion == oldQuestion do currentQuestion = math.random(1,12) end answer = 0 elseif answer ~= 0 then incorrect = incorrect + 1 oldQuestion = currentQuestion while currentQuestion == oldQuestion do currentQuestion = math.random(1,12) end answer = 0 endGeändert von Nielkie (08-06-2007 um 10:23 PM Uhr)
-
08-07-2007, 02:42 AM #7870QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
You can make an EBOOT file that runs LUA scripts. Not sure how though.
Zitat von drag_93
...Just Returned To The Scene...
-
08-07-2007, 06:32 AM #7871words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Theres a few ways. If you know C, you can program a 'lua player' that has converted all of the lua scrip to Lua commands within the app so it's completely unknown as you'd have to reverse engineer the EBOOT. the other method is embedding the Lua script iwthin the eboot which has been done but is still readable via opening the EBOOT. Not sure what oyu want to compile it for however.

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
08-07-2007, 07:06 AM #7872QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
but then again, if you have no clue what you are doing really, you could do this (the easiest method i believe there is):
delete applications folder and everything in it. go to system, delete library folder. copy and paste everything from your game in the main luaplayer folder. rename the folders to whatever you want "name" and "name%" and there you go. :)
theres an app that allows you to modify the eboot, but i dont know it.
as long as the eboot remains like it is, it'll come up as 'luaplayer' in the xmb but it will actually be your creation.
-
08-07-2007, 07:37 AM #7873
yes eminent is right, thats the easiest way. what you need to change what the eboot says and looks like is PSPBrew i think, i will check real quick and then send a link here
-= Double Post =-
okay it is, here is the linkGeändert von emericaska8r (08-07-2007 um 07:40 AM Uhr) Grund: Automerged Doublepost
-
08-07-2007, 08:36 AM #7874QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Co. Dublin, Eire
- Beiträge
- 137
- Points
- 4.371
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I have a problem with my menu.
Basically i have an image with three options on it, and i have an image for an arrow to display which one is highlighted.
I can and have the code for just the arrow to move between each option by pressing up/down, but i want to go a bit more advanced. i want the arrow to move slightly from side to side like
in first half second
->
2nd:
. ->
3rd
... -> [ignoring the full stops]
and back then and repeat that.
so i made a nother integer , arrow1 (one signifying that it's highlighting the 1st option) and thin int can be 1,2 or 3 which displays it moving.
Only problem is it doesnt work, the menu gets glitchy and gets linely in places
I've only tried it for the first option, i hope to have arrow2 and 3 ints if i can get the 1st one to workPHP-Code:
oldpad = Controls.read()
screen:clear()
menu = Image.load("menu.png")
arrow = Image.load("arrow.jpg")
intmenu = 1
while true do
pad = Controls.read()
if pad:down() and oldpad:down() ~= pad:down() then
intmenu = intmenu + 1
end
if pad:up() and oldpad:up() ~= pad:up() then
intmenu = intmenu - 1
end
if intmenu >= 4 then
intmenu = 1
end
if intmenu <= 0 then
intmenu = 3
end
if intmenu == 1 then
arrow1 = 1
screen.waitVblankStart(3)
arrow1 = arrow1 + 1
if arrow1 >= 4 then
arrow1 = 1
end
if arrow1 <= 0 then
arrow1 = 3
end
if arrow1 == 1 then
screen:clear()
screen:blit(0, 0, menu)
screen:blit(3, 105, arrow)
end
if arrow1 == 2 then
screen:clear()
screen:blit(2, 105, arrow)
end
if arrow1 == 3 then
screen:clear()
screen:blit(1, 105, arrow)
end
screen:flip()
if pad:cross() then
dofile("character.lua")
end
end
if intmenu == 2 then
screen:clear()
screen:blit(0, 0, menu)
screen:blit(3, 172, arrow)
if pad:cross() then
dofile("credits.lua")
end
end
if intmenu == 3 then
screen:clear()
screen:blit(0, 0, menu)
screen:blit(3, 240, arrow)
if pad:cross() then
dofile("credits.lua")
end
end
screen:flip()
oldpad = pad
end
I have a feeling that i have a blit in the wrong places but tried different ways and didnt work properly
Anyone see a problem(s)??Geändert von DtotheK (08-07-2007 um 08:56 AM Uhr)
-
08-07-2007, 01:57 PM #7875Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
i havent really looked too much into the code, but try defining arrow1 outside all if statements. (and loops.) instead of in a while statement, like it is now.
--------------------------------------------------------------------------------------
-
08-07-2007, 10:39 PM #7876Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Way to many screen:clear() calls, only use one right at the start of your loop and just make sure you build your screen image in the correct order. also you shouldn't have to make new variables for the cursor movement... use the same one. Try to find the algorithms in everything you do, keeps your code a lot cleaner and easier to debug. For instance
Zitat von DtotheK
anyways, you get the jist (written out of memory so I appologize for any slight syntax errors). If you keep it all in tables it makes it alot easier to unload when switching between game modes to free up memory.Code:menu = {} menu.selection = 1 menu.max = 3 menu.rowHeight = 70 menu.cursor = image.load(<IMAGE>) menu.cursorSwayMax = 5 menu.cursorSway = 0 while true do screen:clear() pad = Controls.read() if pad:up() then menu.selection = menu.selection - 1 if menu.selection <= 0 then menu.selection = menu.max end if end if if pad:down() then menu.selection = menu.selection + 1 if menu.selection > menu.max then menu.selection = 1 end if end if if menu.cursorSwayMax > 0 then menu.cursorSway = menu.cursorSway + 1 else menu.cursorSway = menu.cursorSway - 1 end if if menu.cursorSway == menu.cursorSwayMax then menu.cursorSwayMax = menu.cursorSwayMax * -1 end if screen:blit(10 - menu.cursorSway, menu.rowHeight*menu.selection, menu.cursor) screen.flip() endGeändert von KleptoOne (08-07-2007 um 10:54 PM Uhr)
-
08-08-2007, 12:41 PM #7877QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Co. Dublin, Eire
- Beiträge
- 137
- Points
- 4.371
- Level
- 42
- Downloads
- 0
- Uploads
- 0
yes! works and looks great! just a few lines needed slight changing, and i'll change the control detection thing cause when you hold down/up down it flys through the options like mad. and i'll stick in the actual backround of the menu.
Thankyou !!!
i'll post up the code when i fix it up incase anyone wants it.
-= Double Post =-
here it is, works perfectly!
just have to match up the heights of option and arrow
and what to do when menu.selection = 1,2 and 3!
:Punk:PHP-Code:oldpad = Controls.read()
menu = {}
menu.selection = 1
menu.max = 3
menu.rowHeight = 70
menu.cursor = Image.load("arrow.jpg")
menu.back = Image.load("menu.png")
menu.cursorSwayMax = 5
menu.cursorSway = 0
while true do
screen:clear()
while true do
pad = Controls.read()
if pad:up() and oldpad:up() ~= pad:up() then
menu.selection = menu.selection - 1
end
if menu.selection <= 0 then
menu.selection = menu.max
end
if pad:down() and oldpad:down() ~= pad:down() then
menu.selection = menu.selection + 1
end
if menu.selection > menu.max then
menu.selection = 1
end
if menu.cursorSwayMax > 0 then
menu.cursorSway = menu.cursorSway + 1
else
menu.cursorSway = menu.cursorSway - 1
end
if menu.cursorSway == menu.cursorSwayMax then
menu.cursorSwayMax = menu.cursorSwayMax * -1
end
screen:blit(0, 0, menu.back)
screen:blit(10 - menu.cursorSway, menu.rowHeight*menu.selection, menu.cursor)
screen.flip()
oldpad = pad
end
end
Geändert von DtotheK (08-08-2007 um 12:55 PM Uhr) Grund: Automerged Doublepost
-
08-08-2007, 05:38 PM #7878
does anyone know if there is a do-while loop in lua? if so how would you construct it. i have been looking and couldn't find it so i figured i'd ask here.
-
08-08-2007, 10:53 PM #7879Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Zitat von emericaska8r
Learn basic lua syntax here:Code:repeat <code> until condition
Program in Lua
-
08-09-2007, 03:39 AM #7880QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
DtotheK:
whats the real point of this:
while true do
screen:clear()
while true do
pad = Controls.read()
??????????????????? o_O[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
08-09-2007, 03:46 AM #7881Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
to the point i would like to know how i would go about creating my own font or getting one that is curretly available could someone please help if they know
thanks------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
08-09-2007, 07:40 AM #7882
at the top of this page it will tell you how to make or load an existing font. Then, to use this font use:
Code:screen:fontPrint( font, x, y, string, color )
-
08-09-2007, 08:46 AM #7883QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
but its very slow... you will see yourself ;)
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
08-09-2007, 08:50 AM #7884QJ Gamer Blue
- Registriert seit
- Jan 2007
- Ort
- U.S.
- Beiträge
- 405
- Points
- 7.014
- Level
- 55
- Downloads
- 0
- Uploads
- 0
http://www.pspro.co.uk/forums/index.php/topic,55.0.html
For True Type Fonts.
-
08-09-2007, 11:13 AM #7885Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
thanks that helped a load
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
08-09-2007, 11:40 AM #7886QJ Gamer Blue
- Registriert seit
- Jan 2007
- Ort
- U.S.
- Beiträge
- 405
- Points
- 7.014
- Level
- 55
- Downloads
- 0
- Uploads
- 0
No problem (if that was directed to me).
-
08-09-2007, 03:18 PM #7887QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Co. Dublin, Eire
- Beiträge
- 137
- Points
- 4.371
- Level
- 42
- Downloads
- 0
- Uploads
- 0
i dunno bout the first 2 lines , they were in the code for the swaying arrows i gas given, and i never removed them, but it works fine with them so i just left them in for no reason...
Zitat von myschoo
and the 2 last lines as far as i knew are necessary to keep checking what controls are pressed, and are in all the tutorials i have read as far as i remember..... and the code works with them there!
but now that you question them...
-
08-09-2007, 05:32 PM #7888Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
They were not in the original code. Go back a page and read carefully, it should be
Zitat von DtotheK
The way it is now, you are actually never calling screen:clear() but your background is hiding your old screen every cycle so it still works fine, but if you were to break the inner loop (for program exit as an example) you'll be stuck in an infinite black screen loop, so be careful.Code:while true do screen:clear() pad = Controls.read() ...rest of code
-
08-10-2007, 08:32 AM #7889QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Co. Dublin, Eire
- Beiträge
- 137
- Points
- 4.371
- Level
- 42
- Downloads
- 0
- Uploads
- 0
My bad, got mixed up when i added in all the oldpad stuff...
Zitat von KleptoOne
will do, thanks for pointing that out!
Zitat von KleptoOne
-
08-11-2007, 10:47 PM #7890
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
I got a error for somthing like
Any help im running luaplayer for windows on windows 98, and im just trying to run a simple menu, Any HelpC:/luaplayer> luaplayer script.lua:58 error then expected near "="


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