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; i think there is already a squares port, named squarez look at the "top rated homebrew for 1.5 and OE" ...
-
07-19-2007, 11:14 AM #7741QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 758
- Points
- 8.665
- Level
- 62
- Downloads
- 0
- Uploads
- 0
i think there is already a squares port, named squarez
look at the "top rated homebrew for 1.5 and OE" in the homebrew discussion forum
that first one isn't too hard, all you need to do is get the bat to chase the mouse, collision function for cheese, and some other things
that may seem hard now, but you'll think it's easy soon enough
also, make sure you go all the way to the pong tutorial
and look at the "snippets" too, they're like mini-tutorials
-
07-19-2007, 11:17 AM #7742
Yes there is a port of squares, but not squares 2 so that was what I was thinking, and for the bat mouse thing, can I use this http://www.evilmana.com/tutorials/co...ase_player.php
Zitat von michaelp
It makes sense, i was looking at that and i got reminded of the flash game and thought that it would be an easy port with some jpg files and stuff (maybe a week or twos worth?)
-
07-19-2007, 11:51 AM #7743QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 758
- Points
- 8.665
- Level
- 62
- Downloads
- 0
- Uploads
- 0
you can, but you will have to say that you did in the readme to prevent yourself from being flamed
-
07-19-2007, 12:15 PM #7744
yea of course and maybe a credits section that says where I got it - back to the tutorials lol
Zitat von michaelp
Geändert von Gam3freQ (07-19-2007 um 04:09 PM Uhr)
-
07-19-2007, 02:34 PM #7745
Here's a function that uses the GU for a fast resizing/flipping of images:
the argument "scale" is a multiplier for the size of the image, I.E. 0.5 is half size, 2 is double size, etc... If you leave this out the scale will default to 1Code:function Gu.blit(x, y, image, scale, flip) if not scale or type(scale) == "string" then flip = scale scale = 1 end if flip then if flip == "H" then x_start = image:width() y_start = 0 x_end = 0 y_end = image:height() elseif flip == "V" then x_start = 0 y_start = image:height() x_end = image:width() y_end = 0 elseif flip == "HV" then x_start = image:width() y_start = image:height() x_end = 0 y_end = 0 end else x_start = 0 y_start = 0 x_end = image:width() y_end = image:height() end width = (image:width()*scale)+x height = (image:height()*scale)+y temp = { {x_start, y_start, x, y, 0}, {x_end, y_end, width, height, 0} } Gu.enable(Gu.TEXTURE_2D) Gu.texImage(image) Gum.drawArray(Gu.SPRITES, Gu.TEXTURE_32BITF+Gu.VERTEX_32BITF+Gu.TRANSFORM_2D, temp) end
the argument "flip" is a string, "H" flips horizontally, "V" flips it vertically, "HV" will flip it both ways.
Because this uses the GU, you need to use Gu.start3d() and Gu.end3d(), also remember that you can't use the regular screen:blit function while the GU is running or lua player will crash.
and, here's an example script for how to use it:
To rotate an image to any angle, see this old post I made on Evilmana for an example:Code:img = Image.load("image.png") pad = Controls.read() screen:clear() Gu.start3d() Gu.blit( 20, 20, img, 0.5, "H") Gu.blit(100, 10, img, 1.5, "HV") Gu.blit(300, 10, img, "V") Gu.end3d() screen:flip() while not pad:start() do pad = Controls.read() end
http://www.forums.evilmana.com/index.php?topic=676.0
-
07-19-2007, 03:18 PM #7746Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
yes its to work out yourself, rather easy to be honest and i know only the BBB has you call it :P
-
07-19-2007, 04:11 PM #7747
I figured it out lol. now I am on tutorial 10 wow never expected it to take so long just to get the hang of lua lol
Zitat von mraellis
Geändert von Gam3freQ (07-19-2007 um 04:32 PM Uhr)
-
07-19-2007, 05:16 PM #7748Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
its weird, i am into and not into it... i keep doing what one of the other guys said about redoing it then leaving it then coming back. so even with completing all the evil mana tuts i don't know every done there to explain to people but if you was to make a simple project I'd probably understand a fair bit of the source. i need to buckle down and learn lua proper instead of toying with it.
thanks to you making this post ( which i kinda thought omg post in the lua thread help you idiot at first to (( sorry :P )) ) now I'm gonna try actually learning proper
p.s I've just hit tut 5 you was on ;)
-
07-19-2007, 05:48 PM #7749QJ Gamer Green
- Registriert seit
- Jul 2005
- Ort
- Belgium
- Beiträge
- 594
- Points
- 7.599
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Thank you meric for your help, :)
I am not going to use it tho becaus the currentproject I am working on is a game with a faux3D engine. And this script, even if this is not "real" 3D, it still uses the GU to render in a 3D space, and a big part of the game uses blit so I would have to change to much in my sourcecode.
Still, thank you for the help, it's better to know this now for future projects :)
-
07-19-2007, 06:00 PM #7750Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Ok I've been doing the evil mana tutorials. I've kinda hit a snag at number 6 and cant work out why..
here's the code.
-- ******* Tables ********
oldpad = Controls.read()
green = Color.new(0,255,0)
red = Color.new (255,0,0)
blue = Color.new (0,0,255)
currentEnemy = 1
Enemy = { }
Enemy[1] = { type = "gargoyle", health = 100 }
Enemy[2] = { type = "vampire", health = 100 }
Enemy[3] = { type = "goomba", health = 100 }
Enemy[4] = { type = "ghost", health = 100 }
Enemy[5] = { type = "zombie", health = 100 }
Player = { }
Player[1] = { weapon = "sword", health = 100 }
Player[2] = { weapon = "knife", health = 100 }
-- *****Main Loop******
while true do
pad = Controls.read()
screen:clear()
screen
rint(5,10,"Player 1 Health: " .. Player[1].health,red)
screen
rint(5,20,"Player 1 Weapon: " .. Player[1].weapon,blue)
screen
rint(250,10,"Enemy Health: " .. Enemy[currentEnemy].health,green)
screen
rint(250,20,"Enemy Type: " .. Enemy[currentEnemy].type,green)
if currentEnemy == 5 and Enemy[currentEnemy].health == 0 then
screen
rint(50,100,"All enemies are dead",red)
end
if Enemy[currentEnemy].health == 0 and currentEnemy <= 4 then
currentEnemy = currentEnemy + 1
end
if pad:cross() and oldpad:cross() ~= pad:cross() and Enemy[currentEnemy].health > 0 then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
screen.waitVblankStart()
screen.flip()
oldpad = pad
end
------------------------------------------------
cant work out how to put it in one of them code boxes... someone tell me how and i'll edit it ;)
anyway the error is at line 24 which i made that area bold.. cant see the prob though.
thx in advance.
-
07-19-2007, 06:18 PM #7751
well I thought it would get less helps and it would be harder to track whether my question were answered in a thread which is over a hundred posts
Zitat von mraellis
p.s. i'm on 10
-
07-19-2007, 06:21 PM #7752Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
i guess. i asked a question there just though... kinda got stuck slightly on number 6... cant see why though it looks fine.
-
07-19-2007, 06:57 PM #7753
Well, with the resize/flipping function, you can use it with the regular blit, you just need to set it up correctly. Take my example script from my previous post, if you edit it like this it will work:
See, as long as you put the regular screen:blit outside the Gu start and end statements, you can mix the screen:blit and gu.blit without breaking the code. In fact, if you put the start and end statements inside the gu.blit function itself then you don't have to worry about it. The only reason I didn't do that is because using Gu.start3d() and Gu.end3d() causes a very small delay. The delay isn't anything to worry about if you only use them once per program cycle, however if you put them in the Gu.Blit function itself and then every call to Gu.Blit would then add to the delay.Code:img = Image.load("image.png") pad = Controls.read() screen:clear() screen:blit(100,100,img) Gu.start3d() Gu.blit( 20, 20, img, 0.5, "H") Gu.blit(100, 10, img, 1.5, "HV") Gu.blit(300, 10, img, "V") Gu.end3d() screen:flip() screen:blit(200,200,img) while not pad:start() do pad = Controls.read() end
-
07-19-2007, 08:50 PM #7754
want me to help lol i got through that perfectly here is my source code
Zitat von mraellis
p.s. i'm on 12 now! Also, have you created any lua applications? if you have, did they make the front page or dl.qj.net? Even if they didn't, I bet they were something useful or a demo of some sort unless you didn't make any yet.Code:System.usbDiskModeActivate() white = Color.new(255, 255, 255) currentEnemy = 1 oldpad = Controls.read() Enemy = { } Enemy[1] = { type = "gargoyle", health = 100 } Enemy[2] = { type = "vampire", health = 100 } Enemy[3] = { type = "goomba", health = 100 } Enemy[4] = { type = "ghost", health = 100 } Enemy[5] = { type = "zombie", health = 100 } Player = { } Player[1] = { weapon = "sword", health = 100 } Player[2] = { weapon = "knife", health = 100 } while true do pad = Controls.read() screen:clear() screen:print(5,10,"Player 1 Health: " .. Player[1].health,white) screen:print(5,20,"Player 1 Weapon: " .. Player[1].weapon,white) screen:print(250,10,"Enemy Health: " .. Enemy[currentEnemy].health,white) screen:print(250,20,"Enemy Type: " .. Enemy[currentEnemy].type,white) if currentEnemy == 5 and Enemy[currentEnemy].health == 0 then screen:print(50,100,"All enemies are dead",white) end if Enemy[currentEnemy].health == 0 and currentEnemy <= 4 then currentEnemy = currentEnemy + 1 end if pad:cross() and oldpad:cross() ~= pad:cross() and Enemy[currentEnemy].health > 0 then Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5 end screen.waitVblankStart() screen.flip() oldpad = pad end
p.p.s: I will be using this thread for help again when I start to develop the Bat and mouse port/clone, and I am calling it RODM, or Run or Die, Mouse, since it isn't always a mouse that is chasing you, and I might add a cat for the fun of it lol
HELP! i AM STUCK ON PONG! I CAN'T GET THE BALL TO MOVE!Geändert von Gam3freQ (07-19-2007 um 09:33 PM Uhr)
-
07-19-2007, 10:59 PM #7755words 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
This is why you should format your code ;)
Zitat von mraellis
Look at line 42 right there and compare.Code:-- ******* Tables ******** oldpad = Controls.read() green = Color.new(0,255,0) red = Color.new (255,0,0) blue = Color.new (0,0,255) currentEnemy = 1 Enemy = { } Enemy[1] = { type = "gargoyle", health = 100 } Enemy[2] = { type = "vampire", health = 100 } Enemy[3] = { type = "goomba", health = 100 } Enemy[4] = { type = "ghost", health = 100 } Enemy[5] = { type = "zombie", health = 100 } Player = { } Player[1] = { weapon = "sword", health = 100 } Player[2] = { weapon = "knife", health = 100 } -- *****Main Loop****** while true do pad = Controls.read() screen:clear() screenrint(5,10,"Player 1 Health: " .. Player[1].health,red) screenrint(5,20,"Player 1 Weapon: " .. Player[1].weapon,blue) screenrint(250,10,"Enem y Health: " .. Enemy[currentEnemy].health,green) screenrint(250,20,"Enem y Type: " .. Enemy[currentEnemy].type,green) if currentEnemy == 5 and Enemy[currentEnemy].health == 0 then screenrint(50,100,"All enemies are dead",red) end if Enemy[currentEnemy].health == 0 and currentEnemy <= 4 then currentEnemy = currentEnemy + 1 end if pad:cross() and oldpad:cross() ~= pad:cross() and Enemy[currentEnemy].health > 0 then Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5 end screen.waitVblankStart() screen.flip() oldpad = pad end
Also, this goes to everyone sorta, I need a GFX artiist very soon. You'll be given access to builds and input shall be taken from you (bugs, improvments, etc.). I only need menu GFX, pause menu GFX and a few misc. things (logo, muzzle flash, smoke particle, fire particle ,etc.). All the main game graphics are 3d models, textured/animatedl, so I don't need help there. If you are interested PM me. Note, you must have ite alot of spare time I suppose. You'll be given atleast 5 days to do the work given to you. Also, if anyone knows where this sort of reqest should go, please tell me.
...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
-
07-19-2007, 11:07 PM #7756QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
i smell something sweet coming from sg=-)
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
07-20-2007, 04:15 AM #7757Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
thanks a lot AdjutantReflex.
i missed a end at the end :P
i'll try to make the code look neater in future so its not so messy and easyier to find faults like that.
-
07-20-2007, 04:22 AM #7758Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
i'm on 7 now thanks to AdjutantReflex

thx for the source but i'd already checked other thread first, i missed that second to last end before the screen flip
as for the p.s well i kinda created a program months ago. never released it though and dunno where it is now on the number of hd's i have with my rubbish on. it was very basic but it worked
it was a insult device where if you press x it insulted you by reading a random insult from a .txt file. and if you pressed o then it said something nice about you. i used it to get the psp to insult mates and then say nice stuff about me to make them think it liked me but not them LOL. wish i knew where it was i might release it for other people to play with.
p.s i cant help you with pong "yet" ;) post your code up though for others or me if i can spot something simple you missed.
p.p.s i'm gonna look into this game i'm sure you posted the link on a earlier page... if i like the look of it could we maybe work together?
edit----
okay I've just looked at it. seems rather simple. the AI isn't exactly up to much. its set to home in on where you are at all times and with each cheese you get its speed goes up by 1 and it basically freezes if you get a clock. that actually sounds mostly simple to code but with a little bit of challenge at the same time. only thing that shocked me was the blood when the mouse died :O anyway so it'd go something like;
load colours, load cat/bat/mouse images, load your vars set up that the enemy basically follows you but if you get a clock it stops for 10 secs, you score a point with each cheese you get and then the cheese appears at random anywhere on screen ( now thats the bit that sounds a little challenging cus i don't know about making stuff appear at random places. ) then finish it off and thats the basic game enless you add more stuff to improve it. quick fun game which is rather easy to code. i'd like to help if possible? maybe a team effort? upto you. will check thread later.Geändert von Mraellis (07-20-2007 um 04:39 AM Uhr)
-
07-20-2007, 04:51 AM #7759QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 758
- Points
- 8.665
- Level
- 62
- Downloads
- 0
- Uploads
- 0
did you make the ballMovement() function?
and if you did, did you make sure to put it in your main loop?
-
07-20-2007, 05:57 AM #7760Developer 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 put your code in a code box type [CO.DE] at the beginning and [/CO.DE] at the end without the dot in the middle and this happens
the same for quote and other stuff aswellCode:this is in a code box
------ 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).
-
07-20-2007, 09:18 AM #7761Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Code:Thx a lot :)
-
07-20-2007, 10:43 AM #7762Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
i got bored so made a list of stuff you'd need to make it.
its not complete though.
.wav
chomping noise
splatting noise
Boom noise
whacking noise
squeaking noise
heavy object falling noise
gun shooting noise
.png
mouse looking 8 directions
mouse splatting against screen facing you
mouse splatted on ground with blood
nuclear bomb
cheese
squashed mouse
100 ton weight
shotgun
5 different backgrounds
bat
bat swinging
crosshairs
ashes of mouse
explosion
map border per bg
-
07-20-2007, 07:49 PM #7763
whoa very nice function, i could never figure out gu. i have a question though, won't this is only accept certain sizes?
Zitat von Merick
-
07-21-2007, 03:20 AM #7764
take a look at the code for the function:
"temp" is the model table used by the Gu, and the x_start, y_start, x_end, y_end variables in the table represent the 4 corners of the image you are using, and which corner goes into which variable is determined by the "flip" argument. If you were to use standard u,v coords for these (I.E., numbers between 0 and 1) then you would get messed up graphics if you were using an image with some odd size, however here I'm using the actual image width and height which should let you use any size image without problem.Code:function Gu.blit(x, y, image, scale, flip) if not scale or type(scale) == "string" then flip = scale scale = 1 end if flip then if flip == "H" then x_start = image:width() y_start = 0 x_end = 0 y_end = image:height() elseif flip == "V" then x_start = 0 y_start = image:height() x_end = image:width() y_end = 0 elseif flip == "HV" then x_start = image:width() y_start = image:height() x_end = 0 y_end = 0 end else x_start = 0 y_start = 0 x_end = image:width() y_end = image:height() end width = (image:width()*scale)+x height = (image:height()*scale)+y temp = { {x_start, y_start, x, y, 0}, {x_end, y_end, width, height, 0} } Gu.enable(Gu.TEXTURE_2D) Gu.texImage(image) Gum.drawArray(Gu.SPRITES, Gu.TEXTURE_32BITF+Gu.VERTEX_32BITF+Gu.TRANSFORM_2D, temp) end
Also in the "temp" table there are two variables, "width" and "height" which are calculated by this formula:
width = (image:width()*scale)+x
height = (image:height()*scale)+y
This changes the size that the image is drawn at by multiplying the image height and width by the scale argument, so if you have a 50x100 image and use 1.5 for the scale, then the image will be drawn at 75x150, or with a scale of 0.2 it will be drawn at 10x20.
Basically, what I'm saying is that with this there's no limits on the size of the images you can use (as long as it's at a size that lua player can normally load of coarse), or the size that you can draw them at.
-
07-21-2007, 08:29 AM #7765
wow, nice work!
edit:
oh wait one more question, the x and y coordinates are in real pixels right? so if i wanted it to be flush in the top left i would have to use -240,136 correct? and is there anyway to put this back into an image var, say blit from the screen to an image?
-
07-21-2007, 02:17 PM #7766
With the Gu, the function Gum.translate changes the coordinate system from 2d to 3d, but because Gu.blit doesn't call Gum.translate it uses the same 2d coordinate system as the regular blit.
So, to put an image at the top left, use 0,0.
As for putting it into an image, for some reason using img:blit(0,0, screen) does not capture anything that was drawn with the Gu.
However, although I haven't tried it, I believe that if you use screen:save("screen.png") to save a screenshot to an image file, then you can load that image and use it like you would any other
And actually, this isn't entirely my own code. The core of this was based on something Cools posted on the evilmana board, I just figured out how to use it with odd-sized image dimensions and added in the options for flipping the images.
-
07-21-2007, 11:20 PM #7767
yes That makes sense but I can't finish the pong tutorial because The ball doesn't move, and I havn't worked on it for days, so you want to just make a LUA PROGRAMMING TEAM for us 2 and start on RODM?
Zitat von mraellis
-
07-21-2007, 11:54 PM #7768QJ Gamer Bronze
- Registriert seit
- Dec 2006
- Beiträge
- 654
- Points
- 5.934
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Hey were are u two getting ur lua tutorials? I think ima start learning lua too :) Well i already started before.. just stopped cus there was only 2 tutorials on psp-programming
-
07-22-2007, 12:29 AM #7769QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- United Kingdom
- Beiträge
- 63
- Points
- 4.509
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Check out Evilmana
-
07-22-2007, 04:08 AM #7770Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
evilmana.com thats where we're learning.
gam3freq continued into pm.
-= Double Post =-
just a update to you guys we've teamed up and started on the project and we're gonna be silent now for a bit :)Geändert von Mraellis (07-22-2007 um 03:00 PM Uhr) Grund: Automerged Doublepost


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