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 Yongobongo Can someone help me? I have an error when using dofile() and then loading the same file ...
-
01-28-2007, 03:42 PM #5371QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
yes, print some of your code here and ill try to help ya out
Zitat von Yongobongo

@Anti QJ... Very good point....but still....:)
I got a Question myself...
How would you make your game "pause" if say.. Start was pressed? This has been puzzling me for a while now..
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-28-2007, 03:43 PM #5372QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I guess I worded it wrongly because I was talking about his problem of the music playing slowly and laggy.
Zitat von GuitarGod1134
And actually another possible problem that I just thought of is that if you have your Music.playfile in your while true loop, then it will play over and over without getting a chance to finish
-
01-28-2007, 03:48 PM #5373Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
then he can put the music.playfile in a if statement.
If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
01-28-2007, 03:55 PM #5374QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Zitat von BlackShark
I reccomend making the pause menu a whole different function because then this stops the rest of the game from playing. In that function, you can load and blit some images, a cursor, have some options (continue game, restart game, return to menu, etc.) . if you dont know how to go about doing this, I reccomend using a variable like this:Code:if Controls.read:start() then pausemenu()
I also have a question of my own: How do I blit an image to the screen without disturbing whatever is already there, such as without the screen:clear()?Code:if pad:up() then x=x+1 end if pad:down() then x=x-1 end if x=1 then (code for cursor at position 1) if pad:cross() then (code for what to do it x is pressed when cursor is at position 1) end end if x==2 then...
When I just do it without the screen:clear() then the screen flickers for some reason. But the new image does not flicker. Only the old one.
using screen:save(...) takes up too much time and it's impractical. So is there a better way to do it?
-
01-28-2007, 04:49 PM #5375QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- In a cave according to SG57 lol
- Beiträge
- 273
- Points
- 4.917
- Level
- 44
- Downloads
- 0
- Uploads
- 0
Another question hehe
So I have the variable Player and Object. How can I make it so when the Player collides with the Object it does something? I tried EvilMana's tutorial on collision and it didn't work becuase it didn't use images. Here's the source.
http://shark-flash.com/ryan/lua.rar
Thanks :)
-
01-28-2007, 05:01 PM #5376words 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
BlackShark - Here's a basic, complete Pong game, with pause menu Ive just wrote up, so you get an example.
(why am i being so generous? i havent wrote a pong game in ages...)
Took ~8 minutes - [sarcasm]enjoy[/sarcasm]Code:Player = {} Player[1] = { x=10,y=86,score=0,image=Image.createEmpty(20,50) } Player[2] = { x=450,y=86,score=0,image=Image.createEmpty(20,50) } Ball = { x=235,y=131,xs=3,ys=3,image=Image.createEmpty(10,10) } Player[1].image:clear(Color.new(0,0,255)) Player[2].image:clear(Color.new(0,255,0)) Ball.image:clear(Color.new(255,255,255)) paused = false oldpad = Controls.read() while true do screen:clear() pad = Controls.read() -- toggle pause screen on/off if pad:start() and oldpad:start() ~= pad:start() then paused = not paused end if paused then screen:fillRect(210,125,53,20,Color.new(255,255,255)) screen:print(214,131,"Paused",Color.new(0,0,0)) -- place other code here, for controls and whatnot... else -- game mechanics go here... for pong there simple as pi Ball.x = Ball.x + Ball.xs -- Ball.x += horizontal vector speed Ball.y = Ball.y + Ball.ys -- Ball.y += vertical vector speed if Ball.y < 0 then Ball.ys = 5 elseif Ball.y + 10 > 272 then Ball.ys = -5 end if Ball.x <= 30 and Ball.y >= Player[1].y and Ball.y + 10 <= Player[1].y + 50 then Ball.xs = 5 end if Ball.x+10 >= 450 and Ball.y >= Player[2].y and Ball.y + 10 <= Player[2].y + 50 then Ball.xs = -5 end if Ball.x < 0 then Ball.xs = 5 Player[2].score = Player[2].score + 1 elseif Ball.x + 10 > 480 then Ball.xs = -5 Player[1].score = Player[1].score + 1 end if pad:up() and Player[1].y > 0 then Player[1].y = Player[1].y - 5 elseif pad:down() and Player[1].y + 50 < 272 then Player[1].y = Player[1].y + 5 end if pad:triangle() and Player[2].y > 0 then Player[2].y = Player[2].y - 5 elseif pad:cross() and Player[2].y + 50 < 272 then Player[2].y = Player[2].y + 5 end end -- Main Drawing screen:blit(Ball.x,Ball.y,Ball.image) screen:blit(Player[1].x,Player[1].y,Player[1].image) screen:blit(Player[2].x,Player[2].y,Player[2].image) screen:print(0,0, "Player 1's Score: " .. Player[1].score .. " Player 2's Score: " .. Player[2].score,Color.new(255,0,255)) oldpad = pad screen.waitVblankStart() -- constant 60 FPS screen.flip() end
ZOMG!!!! CAN I GET DEV STATUS NOW?!?
-= Double Post =-
Zero - EvilMana is gay. They are sooooo specific that all the code there teaches you is how to copy & paste... Try somethign like this:
http://forums.qj.net/f-psp-developme...xes-53916.html
I wrote that ages ago... And i demonstrated it using 2 printed label text things (aka - no images as you suggested)Geändert von SG57 (01-28-2007 um 05:01 PM Uhr) Grund: Automerged Doublepost

...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
-
01-28-2007, 05:07 PM #5377QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- In a cave according to SG57 lol
- Beiträge
- 273
- Points
- 4.917
- Level
- 44
- Downloads
- 0
- Uploads
- 0
I actually meant collision with images XD
Zitat von SG57
-
01-28-2007, 05:10 PM #5378words 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
Ok, than simply provide the width/height parameters with the width and height of your iamges. Simply logic goes a long way...

...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
-
01-28-2007, 06:20 PM #5379QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Cool, thanks SG.
Zitat von SG57
What are you implying :/Code:ZOMG!!!! CAN I GET DEV STATUS NOW?!?
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-28-2007, 06:56 PM #5380words 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
That pong games shouldnt get someone a developer status, especially since there are 1 billion of them open source on the internet... What i just typed up and posted was a fully functional pong game... It has score and everything. Technically, it is a game - but the difficulty it took to make it was not worth a Developer title.

...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
-
01-28-2007, 07:10 PM #5381QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
O Ok, i agree with that :), as My sig sais, Im trying to EARN dev status, and i don't think i should do it with PvP Pong :), again, thanks
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-28-2007, 08:21 PM #5382QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- In a cave according to SG57 lol
- Beiträge
- 273
- Points
- 4.917
- Level
- 44
- Downloads
- 0
- Uploads
- 0
The only problem is I don't know where in the world to put the code
Zitat von SG57
-
01-28-2007, 08:25 PM #5383QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- 6ft. Down Underground........Oh and guess what my avatar is
- Beiträge
- 387
- Points
- 4.918
- Level
- 44
- Downloads
- 0
- Uploads
- 0
post ur code and ill tell u
Zitat von ZeroMega
-
01-28-2007, 08:26 PM #5384QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- In a cave according to SG57 lol
- Beiträge
- 273
- Points
- 4.917
- Level
- 44
- Downloads
- 0
- Uploads
- 0
http://shark-flash.com/ryan/lua.rar
Zitat von the undead
Usually if I see some things visually I get a basic understanding of it, just like when I was doing script in Flash.
-
01-28-2007, 08:43 PM #5385words 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
I need to know WHAT you want to happen... But this is the just of it:
Youll need to go get my function from the link i posted and paste it in your code, than you may use this...Code:function TestCollsions() if Collision(Player[1].x,Player[1].y,playerWidth,playerHeight,object[1].x,object[1].y,objectWidth,objectHeight) then -- wahtever you want to happen when they collide end end
Oh and note - to your main while true do loop, add somewhere i nthere 'TestCollisions()'
...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
-
01-28-2007, 08:56 PM #5386QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- In a cave according to SG57 lol
- Beiträge
- 273
- Points
- 4.917
- Level
- 44
- Downloads
- 0
- Uploads
- 0
Still not getting it lol
-
01-28-2007, 10:12 PM #5387Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
And you can put the word object in the parenthasees (spelling ) that way you dont have to rewrite the collision detection for say your player touching zombies and your player touching skeletons like this
Zitat von SG57
now when you call your functionCode:function TestCollsions(object) if Collision(Player[1].x,Player[1].y,playerWidth,playerHeight,object[1].x,object[1].y,object.width,object.height) then -- wahtever you want to happen when they collide end end
[code]
while true do
screen:clear()
TestCollisions(zombies)
TestCOllisions(skeletons) --see no more object, putting those thier replaces all objects with zombies and skeletons. also remember to declare playerWidth, playerHeight, objectWidth, objectHeight as they are variables not functions so they need values assigned to them. To obtain this you can either open up paint and find thier height and stuff or use skeleton:height() or skeleton:height() but the variable skeleton must be the image being loaded not your coordinates, for coordinates i usually just add a c ie skeletonc.x yata yata.If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
01-29-2007, 12:53 AM #5388QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Damn, SG, for some reason its not working for mine, heres part of the code..
Spoiler for code:
I also have
paused = false
defined above the main loop, still no luck, any suggestions....NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-29-2007, 02:26 AM #5389words 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
Uh, ya... Optimize your code in 3 ways...
1. Use the pause menu toggling method i did in my little game
2. Indent your code so it's actually understandable without mind boggling mental indentation (if you actually want me to give you an answer tonight, than do this first)Code:-- globally state this in your while true do loop if pad:start() and pad:start() ~= oldpad:start() then paused = not paused end
3. Inline some of your code for optimization (above code snippet is inlined the pause toggling), and optimize things here and there such as this:
Right now your using unneeded arguments in some if statements. By optimizing them like above, you save in file size (and processign time as welll, as the interpreter doesnt need to read in as much data) so in the end its a good habit all around.Code:if paused then screen:print(0,0,"Right now the game is Paused") else screen:print(0,0,"Right now the game is NOT Paused") 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
-
01-29-2007, 09:54 AM #5390QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
I tried it that way, No luck
thats why i change it, i just tryed that way again, still no luck.
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-29-2007, 10:17 AM #5391QJ Gamer Green
- Registriert seit
- Aug 2006
- Ort
- London
- Beiträge
- 165
- Points
- 5.400
- Level
- 47
- Downloads
- 0
- Uploads
- 0
I've finished my Pong game! Thanks to everyone for their help.
Next: Breakout!
-
01-29-2007, 10:41 AM #5392Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Hey peeps just a quick question. Say if i wanted my player to rotate on a left angle when the left pad was pressed how would i code this? I've never used angles.
-
01-29-2007, 10:53 AM #5393QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Are you intending to rotate the image?
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-29-2007, 10:54 AM #5394Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Yes that's what i had in mind
-
01-29-2007, 11:50 AM #5395QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Then you need to use the GU or vector graphics as any other method will be too slow to use in real time gameplay unless you have strips of your character walking in every direction.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-29-2007, 11:55 AM #5396Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
looks like i need to get learning. Links ? i thought gu was only for 3d ?
-
01-29-2007, 01:39 PM #5397QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Nice if you need any help send me a PM or something :P
Zitat von Blake1
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-29-2007, 03:27 PM #5398
need help
i am just getting into coding LUA and am finding myself confused. i am just learning so im trying to keep it simple but i need help. i am trying to display text that says "Bricking" for one second and have that replaced by text that says "Bricking." and "Bricking.." then "Bricking..." and then repeat itself but i cant figure out how, can someone help?
-
01-29-2007, 03:32 PM #5399QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
mmm, ya know..I already made a prank bricker :) (look in my sig)
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-29-2007, 03:55 PM #5400
yeah, but i just want to code simple text for now. i have
blue = Color.new(0, 0, 255)
screen
rint(200, 130, "Bricking", blue)
screen.flip()
while true do
screen.waitVblankStart(60 )
screen
rint(200, 130, "Bricking.", blue)
screen.flip()
while true do
screen.waitVblankStart(60 )
screen
rint(200, 130, "Bricking..", blue)
screen.flip()
while true do
screen.waitVblankStart(60 )
screen
rint(200, 130, "Bricking...", blue)
screen.flip()
end
but it doesnt work, any advice?


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