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; Hey-- I recently started learning lua...have never even worked with Luaplayer before though.. So I got a quick (idiotic) question..Which ...
-
05-06-2006, 06:04 PM #2101
Hey-- I recently started learning lua...have never even worked with Luaplayer before though.. So I got a quick (idiotic) question..Which will soon be followed by more..
What is Lowser?
Geändert von PSPXavier (05-06-2006 um 06:10 PM Uhr)
-
05-06-2006, 06:08 PM #2102
Wow. I am an idiot. Thanks for your help. :)
Zitat von PSPduh
-
05-06-2006, 07:19 PM #2103Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
lowser is like the XMB for lua. when you start up LUA, the list of games/folders you see as a whole is called lowser.
Zitat von PSPXavier
--------------------------------------------------------------------------------------
-
05-06-2006, 07:23 PM #2104
Ahh-- that's what I thought..But I wasn't sure, and somehow couldn't find much info.
Thank!Geändert von PSPXavier (05-06-2006 um 07:36 PM Uhr)
-
05-06-2006, 07:25 PM #2105
IS there a Again function like
Ex:
if pad:cross() then
screen:blit(0,0,Backgroun d)
if pad:cross again then
screen:blit(0,0,Backgroun dtwo)
is that possible and if yes do he have to make the function or it exist already?
-
05-06-2006, 07:30 PM #2106
- Registriert seit
- Mar 2006
- Beiträge
- 21
- Points
- 4.214
- Level
- 41
- Downloads
- 0
- Uploads
- 0
hey......i just started makeing my First game in LUA
I NEED HELP...
i need a tutorial or somthing to learn:
HOW TO MAKE A ramdom miser and MATCHER
EXAMPLE:
say i make a random dice roll and i get a 5 then i want to be able to click on the number 5 on a number chart and then if right it will keep going and if wronge it will start over and keep ur highscore..
HOW Could i DO this
P.S HELP PLEASE THANKS
-
05-06-2006, 07:32 PM #2107
For tutorial go to:
Evilmana.com
You mean a random function?
-
05-06-2006, 07:33 PM #2108Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
no, there isnt a again function, but you could do this:
Zitat von ZereoX
1. add all your backgrounds to an array:
2. then add this:Code:backgrounds = {} backgrounds[1] = Image.load("background1.png") backgrounds[2] = Image.load("background2.png") ... and so on for all backgrounds.
3. now, your code:Code:currentbackground = 0
try that.Code:if pad:cross() then currentbackground = currentbackground + 1 screen:blit(0,0,backgrounds[currentbackground]) end
--------------------------------------------------------------------------------------
-
05-06-2006, 07:36 PM #2109
I'm having some trouble installing lower v0.12 on Luaplayer v.16. Could someone tell me how?
Thanks
-
05-06-2006, 07:43 PM #2110
it whas an EXAMPLE my real problem is that i can't add a third card to my table
whitout making it it appear when i press hit first time making the second card appears the third one appers for 2 second andthen dissapear when i press hit agin it appear then dissapear i have to hold it down how can i do so that when i press hit only the second card appears and when i press hit again only the third card appears and stay.
here is a part of my code:
Code:if pad:cross() and Command == 1 then Select:play() Drawcard = 1 end if Drawcard == 1 then drawCard() Points = Points + Pointstwo end
-
05-07-2006, 07:26 AM #2111QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 55
- Points
- 4.899
- Level
- 44
- Downloads
- 0
- Uploads
- 0
ok guys im making my first game ever, and it will be released as a beta as soon as this bug is fixed. ok so in the game, when you start it theres a menu. it says press x to begin. but you need to hold x the whole time while playing then game. so thats the problem. also theres a shop that does the same thing, you have to hold square the whole time. and also when you go to begin level 1, it just flashes the screen for a split second and then goes away. plz help
-
05-07-2006, 07:37 AM #2112
Post your code il look at it.
-
05-07-2006, 07:43 AM #2113QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 55
- Points
- 4.899
- Level
- 44
- Downloads
- 0
- Uploads
- 0
green = Color.new(0,255,0)
red = Color.new(255,0,0)
blue = Color.new(0,0,255)
white = Color.new(255,255,255)
inpaintshop = Image.load("inpaintshop.p ng")
player = Image.load("player.png")
menu = Image.load("menu.png")
inpaintshop = Image.load("inpaintshop.p ng")
playern2o = Image.load("playern2o.png ")
roadlevel1 = Image.load("roadlevel1.pn g")
road = Image.load("road.png")
upcurb = Image.load("uppercurb.png ")
inshop = Image.load("inshop.png")
lowcurb = Image.load("lowercurb.png ")
trash = Image.load("trash.png")
firstgas = Image.load("1stgasstation .png")
cash = {}
cash.money = 200
mid = Image.load("middle.png")
playerorange = Image.load("playerorange. png")
playerred = Image.load("playerred.png ")
playerredn2o = Image.load("playerredn2o. png")
playerorangen2o = Image.load("playerorangen 2o.png")
selectingdiff = { hl = Image.createEmpty(145,15) , x = 114,y = 33 }
selectingdiff.hl:clear(wh ite)
timer = Timer.new()
time = timer:time()
nitros = {}
nitros.y = 15
health = {}
health.y = 15
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
Player = { }
Player[1] = { x = 216, y = 197 }
Player.nitros = 50
Player.health = 50
screen.flip()
gamestate = { w = "game"}
while true do
pad = Controls.read()
-- menu
gamestate.w = "menu"
screen:blit(0,0,menu,fals e)
screen
rint(100,150,"Press 'X' to play",red)
screen
rint(100,160,"Press 'O' to quit",red)
if pad:cross() and gamestate.w == "menu" then
gamestate.w = "game"
pad = Controls.read()
oldpad = Controls.read()
screen:clear()
screen:blit(0,0,firstgas, false)
screen:fillRect(15,15,Pla yer.nitros,nitros.y,blue)
screen:fillRect(72,15,Pla yer.health,health.y,red)
screen:blit(Player[1].x,Player[1].y,player)
screen
rint(250,10,"Player.x: " .. Player[1].x,red)
screen
rint(250,20,"Player.y: " .. Player[1].y,red)
screen
rint(15,37,"n2o: " .. Player.nitros,blue)
screen
rint(72,37,"HP: " .. Player.health,red)
screen
rint(123,37,"Cash: " .. cash.money,green)
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 4
end
if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 4
end
if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 4
end
if pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 4
end
if pad:r() then
screen:blit(Player[1].x,Player[1].y,playern2o)
end
if pad:r() and pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 10
end
if pad:r() and pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 10
end
if pad:r() and pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 10
end
if pad:r() and pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 10
end
if pad:r() and Player.nitros > 0 then
Player.nitros = Player.nitros - 1
end
if Player.health == 0 then
screen:clear()
screen
rint(25,200,"You ran out of Health, game over. Press Start to Exit", red)
end
if Player.health > 50 then
Player.health = 50
end
if Player[1].x <= 272 and Player[1].y <= 57 then
screen
rint(100,200, "Press 'X' to fill up on HP and n2o.", red)
end
if pad:cross() and Player[1].x <= 472 and Player[1].y <= 41 then
Player.health = Player.health + 20
end
if pad:cross() and Player[1].x <= 472 and Player[1].y <= 41 then
Player.nitros = Player.nitros + 20
end
if Player.nitros > 50 then
Player.nitros = 50
end
if Player.health < 10 then
screen
rint(240,265,"In risk losing your honor and dieing at the same time!",red)
end
if Player[1].x <= 44 and Player[1].y >= 141 then
screen
rint(100,200,"Press 'O' to begin Level 1", red)
end
if Player[1].x >= 348 and Player[1].y <= 57 then
screen
rint(100,200,"Press '[_]' to shop", red)
end
-- fix nitros bug
if Player.nitros == 0 and pad:r() and pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x + 6
screen:blit(Player[1].x,Player[1].y,player)
end
if Player.nitros == 0 and pad:r() and pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x - 6
screen:blit(Player[1].x,Player[1].y,player)
end
if Player.nitros == 0 and pad:down() and pad:r() and Player[1].y < screenheight then
Player[1].y = Player[1].y - 6
screen:blit(Player[1].x,Player[1].y,player)
end
if Player.nitros == 0 and pad:up() and pad:r() and Player[1].y > 0 then
Player[1].y = Player[1].y + 6
screen:blit(Player[1].x,Player[1].y,player)
end
if pad:square() and Player[1].x >= 348 and Player[1].y <= 57 then
gamestate.w = "inshop"
screen:clear()
screen:blit(0,0,inshop,fa lse)
screen
rint(114,33,"How may I help you today?",red)
screen
rint(114,53,"Press 'X' for Health Items",red)
screen
rint(114,63,"Press 'O' for Nitros Items",blue)
screen
rint(114,73,"Press '[]' for Car Paint and Tuning",green)
end
if pad:square() and gamestate.w == "inshop" then
gamestate.w = "inpaintshop"
screen:clear()
screen:blit(0,0,inpaintsh op,false)
end
if pad:square() and gamestate.w == "inpaintshop" and cash.money >= 100 then
gamestate.w = "playerred"
cash.money = cash.money - 100
screen:blit(Player[1].x,Player[1].y,playerred)
if pad:r() and pad:left() and gamestate.w == "playerred" and Player[1].x > 0 then
Player[1].x = Player[1].x - 10
end
if pad:r() and pad:right() and gamestate.w == "playerred" and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 10
end
if pad:r() and pad:down() and gamestate.w == "playerred" and Player[1].y < screenheight then
Player[1].y = Player[1].y + 10
end
if pad:r() and pad:up() and gamestate.w == "playerred" and Player[1].y > 0 then
Player[1].y = Player[1].y - 10
end
else
if pad:square() and gamestate.w == "inpaintshop" and cash.money < 100 then
screen:clear(blue)
screen
rint(100,150,"Not enough cash",red)
screen.waitVblankStart(12 0)
gamestate.w = "game"
end
end
if pad:circle() and Player[1].x <= 44 and Player[1].y >= 149 then
gamestate.w = "level1"
screen:clear(blue)
Player[1].x = 898 -- this is messed up
Player[1].y = 900 -- this to
screen
rint(100,200,"Remember to drive safely, you don't want to die!! Press 'X' to begin",red)
end
end
if gamestate.w == "menu" and pad:circle() then
break end
screen.flip()
screen.waitVblankStart()
end
-
05-07-2006, 07:49 AM #2114
you have to do somthing like this
if pad:cross() and gamestate.w == "menu" then
gamestate.w = "game"
end
If gamestate.w == "game" then
EX
startgame)
end
other EX:
if pad:cross() anf Mainmenu == Menu then
Mainmenu = game
end
if Mainmenu == game the
(start the game)
endGeändert von ZereoX (05-07-2006 um 07:53 AM Uhr)
-
05-07-2006, 08:25 AM #2115
- Registriert seit
- Jul 2005
- Beiträge
- 36
- Points
- 4.622
- Level
- 43
- Downloads
- 0
- Uploads
- 0
I'm currently exploring the LUA world, and I was wondering if there is a command/a way to jump to certain bits of code in your program?
-
05-07-2006, 08:27 AM #2116QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 55
- Points
- 4.899
- Level
- 44
- Downloads
- 0
- Uploads
- 0
that didnt work...
-
05-07-2006, 08:36 AM #2117
try removing your code from " like
gamestate.w = "game"
gamestate.w = game cause whn its in " its like typing a word
-
05-07-2006, 09:00 AM #2118QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 55
- Points
- 4.899
- Level
- 44
- Downloads
- 0
- Uploads
- 0
that didnt work either... should i have the menu code outside the main loop, all by it self, or in another seperate loop then the game loop?
-
05-07-2006, 09:20 AM #2119
actualy in my game my menu is on a other .lua file i just youse the command:
if pad:cross() and menustatus == 0 then
Select: play() dofile("game.lua")
end
My menu code:
IM not the best so you shounld aks Grimfate126 or Sousanator or somone else.Code:-- Colors white = Color.new(255, 255, 255) red = Color.new(255, 0, 0) -- Image load Title = Image.load("images/TitleScreen.png") Selector = Image.load("images/Selector.png") Select = Sound.load("sounds/Select.wav",false) --Variable menustatus = 0 Music.volume(128) while true do pad = Controls.read() screen:blit(0,0,Title) screen:print(225, 110, "START", white) screen:print(225, 120, "CREDITS", white) screen:print(225, 130, "EXIT", white) 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 if menustatus > 2 then menustatus = 0 end if menustatus < 0 then menustatus = 2 end if menustatus == 0 then screen:print(225, 110, "START", red) screen:blit(200,110,Selector) else if menustatus == 1 then screen:print(225, 120, "CREDITS", red) screen:blit(200,120,Selector) else if menustatus == 2 then screen:print(225, 130, "EXIT", red) screen:blit(200,130,Selector) end end end if pad:cross() and menustatus == 0 then Select:play() dofile("game.lua") end if pad:cross() and menustatus == 1 then Select:play() dofile("credits.lua") end if pad:cross() and menustatus == 2 then Select:play() break end end screen.waitVblankStart() screen.flip() oldpad = pad endGeändert von ZereoX (05-07-2006 um 09:24 AM Uhr)
-
05-07-2006, 10:58 AM #2120QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
eh?
Zitat von Wacko`
by the way you ask your question, i can tell you need to learn a little more..
jump to certain bits of your code..
well, there are these commands called "Functions". Functions are basically user-created codes.
Like say you want some photos to show in a slide show-esque manner when you press a button. You make a function that does that.
That answer your question?Code:function slide_show() -- Note: there cannot be a space in the function name. hence, "slide_show" instead of "slide show". screen:blit(x, y, photo1) screen.flip() screen.waitVblankStart(10) screen:blit(x, y, photo2) screen.flip() screen.waitVblankStart(10) screen:blit(x, y, photo3) screen.flip() screen.waitVblankStart(10) end
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-07-2006, 12:51 PM #2121
Nope there aren't any "label" and "goto" commands. I was looking for those too at first, but you'll have to do with functions. Works just as good.
Zitat von Wacko`
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
05-07-2006, 01:07 PM #2122QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
hmm...I'm the one that needs to learn more.
Zitat von Altair
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-07-2006, 04:08 PM #2123
ok, back from my lua coding, here a problem, ive been using io.open to wright settings, but the problem , is that it overwright all the file.So i added the rest of the code to the wright process , but there no Enters... only 1 line and another thing is on that setting file i got a line:
curentcar = "car/driver.txt"
well... guess what:
file:write("curcar = "car/driver.txt"")
i cant put that!
what shall i do?
-
05-07-2006, 04:12 PM #2124QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
i cant help you there...your ahead of me now. Writing and reading files. I'm learning that myself.
Zitat von agashka
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-07-2006, 04:36 PM #2125
thats what i tried but well... i thing im gonna see my bookmark and seach for something usefull
-
05-07-2006, 04:41 PM #2126QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- The Migrant Fleet
- Beiträge
- 908
- Points
- 9.678
- Level
- 66
- Downloads
- 0
- Uploads
- 0
ok heres what you do
Zitat von agashka
Pay attention to the bold print
there are more functions like that.. visit www.evilmana.com for more tuts on that kind of stuffCode://to overwrite the whole file// file = io.open("yourfile.txt", "w") file:write("yourtext") file:close() //to add to the file// file = io.open("yourfile.txt", "a") file:write("yourtext") file:close() // to read a file// file = io.open("yourfile.txt", "r") file:read() file:close()
-
05-07-2006, 04:42 PM #2127TheMarioKartersGuest
Ahh, that's pretty neat. Thanks for that. :)
Zitat von montrob
-
05-07-2006, 04:43 PM #2128QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- The Migrant Fleet
- Beiträge
- 908
- Points
- 9.678
- Level
- 66
- Downloads
- 0
- Uploads
- 0
welcome..
Zitat von TheMarioKarters
-
05-07-2006, 04:52 PM #2129QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
How would you print a variable to a file? Is it that you have to concentrate it with the ..? Because if i were ever to make a game and want to have highscore, I would write it to another file. Example, if i have a gmae and it has a highscore, I want to write that to another file. How would I do that? (I know i asked the same question 20 times....)
-
05-07-2006, 05:01 PM #2130QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- The Migrant Fleet
- Beiträge
- 908
- Points
- 9.678
- Level
- 66
- Downloads
- 0
- Uploads
- 0
just a basic way of doing it
Zitat von PSPduh
Code:-- code here file = io.open("yourfile.txt", "w") if currentscore >= hiscore then file:write("currentscore") file:close()


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