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; Post that part of code please. You need to input a "then" by a "="...
-
08-11-2007, 10:55 PM #7891lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Post that part of code please.
You need to input a "then" by a "="
-
08-11-2007, 11:11 PM #7892
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
-= Double Post =-red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
menustatus = 1
while true do
screen:clear(black)
pad = Controls.read()
if pad:up() then
menustatus = menustatus - 1
screen.waitVblankStart(4)
end
if pad:down() then
menustatus = menustatus + 1
screen.waitVblankStart(4)
end
color={white, white, white, white}
screen
rint(50,50,"Road To St. Louis", color[1])
screen
rint(50,60,"Exhibition", color[2])
screen
rint(50,70,"Options", color[3])
screen
rint(50,80,"Exit", color[4])
color[menustatus]=red
if menustatus == 1 then
if pad:cross() then
--insert game code here
end
end
if menustatus == 2 then
if pad:cross() then
--insert Exhibition here
end
end
if menustatus == 3 then
-- inserts options here
}
while true do
if up1() and then cursor=cursor-1 end
if down1() and then cursor=cursor+1 end
if cursor==0 then cursor=2 end
if cursor==3 then cursor=1 end
screen:clear(black)
list_options(8,8,options, ">",1,white,red,curso r)
screen:flip()
if cross1() or circle1() then
if cursor==1 then
--Insert Code Here
elseif cursor==2 then
--Insert Code Here
elseif cursor==3 then
--Insert Code Here
elseif cursor==4 then
--Insert Code Here
elseif cursor==5 then
--Insert Code Here
end
end
if menustatus == 4 then
if pad:cross() then
break
end
end
if menustatus <= 0 then
menustatus = 4
end
if menustatus => 5 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
end
Opps I forgot to remove some of the Ends to show what the file was like before, ill look at it soon.
-= Double Post =-
FixedGeändert von SportzOwner (08-11-2007 um 11:18 PM Uhr) Grund: Automerged Doublepost
-
08-11-2007, 11:23 PM #7893words 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
Um im trying to fix your code via formatting, yet I can't work anything out... Example - why the hell is there a random '}' in the middle there?

...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-12-2007, 12:17 AM #7894lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Dont you need the options?
-= Double Post =-Code:options = { "Option 1", "Option 2" }
Now that I look at it, Your combining that Menu Status snippet with the list_options example.Geändert von Anti-QuickJay (08-12-2007 um 12:25 AM Uhr) Grund: Automerged Doublepost
-
08-12-2007, 12:09 PM #7895
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
Opps i think thats suppose to be a end end there, i had another code in there, but removed it to show what it was like, that explains my newest error. :), i didn't look hard enough and it was 2 am.
-= Double Post =-
Opps i still had some of the extra code in there. From the options, and i removed half of it in the last code heres what it suppose to be.
-= Double Post =-red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
menustatus = 1
while true do
screen:clear(black)
pad = Controls.read()
if pad:up() then
menustatus = menustatus - 1
screen.waitVblankStart(4)
end
if pad:down() then
menustatus = menustatus + 1
screen.waitVblankStart(4)
end
color={white, white, white, white}
screen
rint(50,50,"Road To St. Louis", color[1])
screen
rint(50,60,"Exhibition", color[2])
screen
rint(50,70,"Options", color[3])
screen
rint(50,80,"Exit", color[4])
color[menustatus]=red
if menustatus == 1 then
if pad:cross() then
--insert game code here
end
end
if menustatus == 2 then
if pad:cross() then
--insert Exhibition here
end
end
if menustatus == 3 then
-- inserts options here
end
end
if menustatus == 4 then
if pad:cross() then
break
end
end
if menustatus <= 0 then
menustatus = 4
end
if menustatus => 5 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
end
Okay I think i fixed the error, its now on line 50, no loop near break on the above code
Line 50 area, i know it saying it can't break
if menustatus == 4 then
if pad:cross() then
break
end
endGeändert von SportzOwner (08-12-2007 um 12:16 PM Uhr) Grund: Automerged Doublepost
-
08-12-2007, 12:20 PM #7896lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Remove the break and put something like System.Quit() or os.exit
-
08-12-2007, 12:27 PM #7897QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
remove 1 endif menustatus == 3 then
-- inserts options here
end
end[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-12-2007, 12:53 PM #7898
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
1 end from all menu status?
and yes these are from the snippits, im trying them out, and i did have the options in it untill i moved it.
-= Double Post =-
Opps i left out the pad:cross out of the options
Now it should be right.red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
menustatus = 1
while true do
screen:clear(black)
pad = Controls.read()
if pad:up() then
menustatus = menustatus - 1
screen.waitVblankStart(4)
end
if pad:down() then
menustatus = menustatus + 1
screen.waitVblankStart(4)
end
color={white, white, white, white}
screen
rint(50,50,"Road To St. Louis", color[1])
screen
rint(50,60,"Exhibition", color[2])
screen
rint(50,70,"Options", color[3])
screen
rint(50,80,"Exit", color[4])
color[menustatus]=red
if menustatus == 1 then
if pad:cross() then
--insert game code here
end
end
if menustatus == 2 then
if pad:cross() then
--insert Exhibition here
end
end
if menustatus == 3 then
if pad:cross() then
-- inserts options here
end
end
if menustatus == 4 then
if pad:cross() then
System.Quit()
end
end
if menustatus <= 0 then
menustatus = 4
end
if menustatus => 5 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
endGeändert von SportzOwner (08-12-2007 um 01:08 PM Uhr) Grund: Automerged Doublepost
-
08-12-2007, 01:29 PM #7899lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Remove the
and add aCode:screen.waitVblankStart(4)
behind the last vblank at the end of your code.Code:oldpad = pad
-
08-12-2007, 01:57 PM #7900
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
Okay so we ended with
Ill go test it.red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
menustatus = 1
while true do
screen:clear(black)
pad = Controls.read()
if pad:up() then
menustatus = menustatus - 1
end
if pad:down() then
menustatus = menustatus + 1
end
color={white, white, white, white}
screen:print(50,50,"Road To St. Louis", color[1])
screen:print(50,60,"Exhib ition", color[2])
screen:print(50,70,"Optio ns", color[3])
screen:print(50,80,"Exit" , color[4])
color[menustatus]=red
if menustatus == 1 then
if pad:cross() then
--insert game code here
end
end
if menustatus == 2 then
if pad:cross() then
--insert Exhibition here
end
end
if menustatus == 3 then
if pad:cross() then
-- inserts options here
end
end
if menustatus == 4 then
if pad:cross() then
System.Quit()
end
end
if menustatus <= 0 then
menustatus = 4
end
if menustatus => 5 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
oldpad = pad
end
-= Double Post =-
That gave off another then expected near = error as that is line 56oldpad = padGeändert von SportzOwner (08-12-2007 um 01:59 PM Uhr) Grund: Automerged Doublepost
-
08-12-2007, 07:11 PM #7901
if you are using the oldpad technique, then in each keypress if statement you need to do something like:
as for that error it spat out at you i'm not sure why that shouldn't have worked. try putting at the top of your code somewhere:Code:if pad:up() and oldpad:up() ~= pad:up() then ...
i'm not sure if that will fix it or not, i'll do some tests to see if it will real quick thoughCode:oldpad = Controls.read()
-= Double Post =-
ok after thinking about it, i'm not sure why that [then expected near "="] error came up, you would still need that oldpad = Controls.read() at the top of your code somewhere so that it is declared as a controls.read() variable before it is used. otherwise, on the first loop through it wouldn't even be a variable yet.Geändert von emericaska8r (08-12-2007 um 07:15 PM Uhr) Grund: Automerged Doublepost
-
08-12-2007, 07:18 PM #7902
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
Same error, just now its on line 70 because of extra coding put in.
pad = Controls.read()
oldpad = pad
currstate="startup"
function printCentered(y, text, color)
local tl=string.len(text)
local xmod = 240-((tl*10)/2)
screen:print(xmod, y, text, color)
end
-----------------
dofile("colors.lua")--contains all color codes, make one yourself
-----------------
screen:clear()
printCentered(131,"Starti ng up...",white)
screen.waitVblankStart(3)
screen.flip()
-----------------------------------------
function mainmenu()
menustatus = 1
while true do
screen:clear(black)
if pad:up() and oldpad:up() ~= pad:up() then
menustatus = menustatus - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
menustatus = menustatus + 1
end
color={white, white, white, white}
screen:print(50,50,"Road To St. Louis", color[1])
screen:print(50,60,"Exhib ition", color[2])
screen:print(50,70,"Optio ns", color[3])
screen:print(50,80,"Exit" , color[4])
color[menustatus]=red
if menustatus == 1 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
--insert game code here
end
end
if menustatus == 2 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
--insert Exhibition here
end
end
if menustatus == 3 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
-- inserts options here
end
end
if menustatus == 4 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
System.Quit()
end
end
if menustatus <= 0 then
menustatus = 4
end
if menustatus => 5 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
end
end
---------------------------
screen:clear()
printCentered(131,"Press Start",white)
screen.waitVblankStart()
screen.flip()
if pad:start() and oldpad:start() ~= pad:start() then
currstate="menu"
end
end
----------------------------
if currstate = "menu" then
menu()
end
end
-
08-12-2007, 07:22 PM #7903
ok. that all worked, and i found out that your error was that you put
that needed to be ">=" ... here is a revised code of it allCode:if menustatus => 5 thenCode:red = Color.new(255,0,0) black = Color.new(0,0,0) white = Color.new(255,255,255) menustatus = 1 oldpad = Controls.read() while true do screen:clear(black) pad = Controls.read() if pad:up() and oldpad:up() ~= pad:up() then menustatus = menustatus - 1 end if pad:down() and oldpad:down() ~= pad:down() then menustatus = menustatus + 1 end color={white, white, white, white} screen:print(50,50,"Road To St. Louis", color[1]) screen:print(50,60,"Exhib ition", color[2]) screen:print(50,70,"Optio ns", color[3]) screen:print(50,80,"Exit" , color[4]) color[menustatus]=red if menustatus == 1 then if pad:cross() then --insert game code here end end if menustatus == 2 then if pad:cross() then --insert Exhibition here end end if menustatus == 3 then if pad:cross() then -- inserts options here end end if menustatus == 4 then if pad:cross() then System.Quit() end end if menustatus <= 0 then menustatus = 4 end if menustatus >= 5 then menustatus = 1 end screen.flip() screen.waitVblankStart() oldpad = pad end
-
08-12-2007, 07:27 PM #7904QJ Gamer Blue
- Registriert seit
- Jan 2007
- Ort
- U.S.
- Beiträge
- 405
- Points
- 7.014
- Level
- 55
- Downloads
- 0
- Uploads
- 0
I use "if pad:cross() and not oldpad:cross()"
Less words, works perfectly.
-
08-12-2007, 09:35 PM #7905
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
I put oldpad because somone told me to, earlier, ill test it without it later.
-
08-13-2007, 03:18 AM #7906words 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
Less words? This less words regardless of the number of buttons wanted:
Code:if oldpad ~= pad then if pad:cross() then -- X pressed once end end
...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-13-2007, 07:12 AM #7907
How would you properly:
Look for a file on memory stick, and do "Action A" If it exists, or do "Action B" if it does not?
-
08-13-2007, 07:42 AM #7908QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
file = io.open(ms0:/path)
if file then
-- action a
file:close()
else
-- action b
end[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-13-2007, 07:48 AM #7909
Zitat von myschoo
Cool. Thanks man, turns out i left something out of the file path, and thats why it wasn't working. :P
Thanks for the reply. :)Geändert von Mr_Shizzy (08-13-2007 um 08:51 AM Uhr)
-
08-13-2007, 06:09 PM #7910
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
Gah now i can't this to leave my image sportz.jpg, any help?
black = Color.new(0,0,0)
pad = Controls.read()
white = Color.new(255,255,255)
--------------
function printCentered(y,text,colo r)
local length = string.len(text)
local x = 240 - ((length*8)/2)
screen:print(x,y,text,col or)
end
--------------
function scaleImage(newX, newY, theImage)
resizedImage = Image.createEmpty(newX, newY)
for x = 1, newX do
for y = 1, newY do
resizedImage:blit(x,y , theImage,
math.floor(x*(theImage:wi dth()/newX)),
math.floor(y*(theImage:he ight()/newY)),1,1)
end
end
return resizedImage
end
--------------
screen:clear(black)
printCentered(131,"Starti ng up...",white)
screen.waitVblankStart(3)
screen.flip()
--------------
sportz = Image.load("sportz.jpg")
-------------
scaleImage(480,272, sportz) -- Resize image.
while true do
screen:blit(0,0, resizedImage) -- Show the resized image
screen.waitVblankStart(3)
screen.flip()
currstate="ready"
end
--------------
pad=Controls.read()
screen:clear(black)
if currstate=="ready" then
screen:clear()
printCentered(100,"Press Start",white)
printCentered(300,"Powere d by Sportz",white)
screen.waitVblankStart()
screen.flip()
if pad:start() then
dofile("menu.lua")
end
end
-
08-13-2007, 06:12 PM #7911lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
English please? I don't understand what that means.leave my image sportz.jpg
-
08-13-2007, 06:45 PM #7912
with this code here:
i beleive you have to do :Code:scaleImage(480,272, sportz) -- Resize image.
then when you blit the image, instead of trying to blit "resizedImage" you have to put "somevariable" or whatever name you chose.Code:somevariable = scaleImage(480,272, sportz)
this is because when you return a value in a funtion, you need a variable to return it to, so you do: variable = function()
-
08-13-2007, 09:38 PM #7913
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
It means that it stays stuck on my image sports.jpg, or it won't leave my img.
Zitat von Anti-QuickJay
-= Double Post =-
I added the variable into the screen blit, and fixed around it, but it still stays stuck on my image.Geändert von SportzOwner (08-13-2007 um 09:43 PM Uhr) Grund: Automerged Doublepost
-
08-13-2007, 11:10 PM #7914QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
resize the image manually! you are using functons from evilmana and u dont even know how do they work ... >_>
[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-14-2007, 07:09 AM #7915
well how big is sportz.jpg originally? because if it is bigger than 512x512 then it wouldn't load in the first place.
-
08-14-2007, 12:33 PM #7916
- Registriert seit
- Jul 2007
- Ort
- America
- Beiträge
- 30
- Points
- 3.273
- Level
- 35
- Downloads
- 0
- Uploads
- 0
The origenal is 600 x 150 pixels, it loads it just won't switch to current state ready, ill try to figure it out on my own.
-= Double Post =-
I fixed it.
Had the end, end something i neededblack = Color.new(0,0,0)
pad = Controls.read()
white = Color.new(255,255,255)
--------------
function printCentered(y,text,colo r)
local length = string.len(text)
local x = 240 - ((length*8)/2)
screen
rint(x,y,text,color)
end
--------------
function scaleImage(newX, newY, theImage)
resizedImage = Image.createEmpty(newX, newY)
for x = 1, newX do
for y = 1, newY do
resizedImage:blit(x,y , theImage,
math.floor(x*(theImage:wi dth()/newX)),
math.floor(y*(theImage:he ight()/newY)),1,1)
end
end
return resizedImage
end
--------------
screen:clear(black)
printCentered(131,"Starti ng up...",white)
screen.waitVblankStart(3)
screen.flip()
--------------
sportz = Image.load("sportz.jpg")
-------------
sportzimg = scaleImage(480,272, sportz) -- Resize image.
while true do
screen:blit(0,0, sportzimg, false) -- Show the resized image
screen.waitVblankStart(30 0)
screen.flip()
--------------
pad=Controls.read()
screen:clear(black)
screen:clear()
printCentered(100,"Press Start",white)
printCentered(200,"Powere d by Sportz",white)
if pad:start() then
dofile("menu.lua")
end
screen.waitVblankStart()
screen.flip()
endGeändert von SportzOwner (08-14-2007 um 12:53 PM Uhr) Grund: Automerged Doublepost
-
08-14-2007, 08:02 PM #7917
- Registriert seit
- Jun 2007
- Beiträge
- 11
- Points
- 3.225
- Level
- 35
- Downloads
- 0
- Uploads
- 0
best place to go if u want to learn about Lua coding http://luaplayer.org/forums/index.php?topic=20.0
-
08-15-2007, 02:51 PM #7918
hi this code here:
(by the way it relates to my game without showing it yet)Code:count = 5 white = Color.new(255,255,255) function display() screen:print(140, 248, count, white) end for count = 1, 5 do while true do screen:clear() pad = Controls.read() display() if pad:square() and oldpad:square() ~= pad:square() then oldpad = pad break end oldpad = pad screen.flip() screen.waitVblankStart() end end
basically i wanted a for loop that would decrease a variable, and show it using the display() function. I just wanted to know if anyone could tell me the specifics on why it never displays count decreasing.
i found ways around it, but just want to know why it doesn't.
-
08-15-2007, 05:29 PM #7919lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Thats a lie.
Zitat von johnjohnfroboy
Its http://www.lua.org/manual/5.1/
-
08-16-2007, 12:57 AM #7920.info

- Registriert seit
- Jun 2006
- Ort
- ACT, Australia
- Beiträge
- 1.674
- Points
- 15.395
- Level
- 80
- Downloads
- 0
- Uploads
- 0


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