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 jon frost. I'll try and look at it from here to make it better....
-
05-24-2006, 11:05 AM #2461
Ok, thanks jon frost. I'll try and look at it from here to make it better.
-
05-24-2006, 03:01 PM #2462
Zitat von EminentJonFrost
not sure. becuase i m using
Code:block = {} block[1] = { x = 34, y = 190 } for d = 2, 4 do block[d] = { x = block[d-1].x + 16, y = 150 } end
like the code bellow makes move up to be false if it touch the bottom of my 17x17 pixel box
but the problem is that if there is 3 boxs close with the same y axis but different x axis, the 1st at the right will work normally.Code:for c = 1, 4 do screen:blit(block[c].x, block[c].y, blockk)
---like in the code bellow, if the moving picture is at the left side of the box and bellow it, it becomes trueCode:if moving1 == true and x0 > block[c].x-14 and x0 < block[c].x+16 and y0+10 > block[c].y and y0 < block[c].y+17 then moving1 = false end
Code:if moving1 == false and x0 < block[c].x-13 and y0 > block[c].y and y0 < block[c].y+17 then moving1 = true end end
the 1st and 2nd of the left move up will be true because the 1st at the right is making it to be true
the thing i dont get it is to make it check if it have a box above the moving picture (that is x0 and y0)
so if there is a box above its false. if there is no box above its true for the moving picture to go upGeändert von natan333 (05-24-2006 um 03:11 PM Uhr)
Bequiet!!!
I'm learning cc©cc
-
05-24-2006, 03:15 PM #2463words 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
so then do what your saying... its just booling really

...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
-
05-25-2006, 02:51 PM #2464QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
I need some help.
Can someone explain me screen:drawLine to me VERY detailed? Because I need this to complete something that I'm making. Also, can somebody explain me screen:fillRect too? Thank you.
--PSPduhGeändert von PSPduh (05-25-2006 um 04:22 PM Uhr)
-
05-25-2006, 03:49 PM #2465QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
How do you call a variable from a table .. thats within a table?
What I mean by "how do I call it" is...well, ok, to call a variable from a table, you just do this:
so how would I call that same variable if its table were inside another table?Code:table = { variable1, variable2 } table.variable1 -- there, called the first variable from table "table".
Code:bigger_table = { table = { variable1, variable2} table2...blah blah }Geändert von EminentJonFrost (05-25-2006 um 04:35 PM Uhr)
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-25-2006, 03:59 PM #2466
Hey I was wondering what kind of software or whatever could create a .png image with a transparent background, so it wouldn't be all white, it would just be unnoticable. This is because I created one, yet when i saved it as .png my software said that it could save it in .png, yet it wouldn't retain all features. When i opend it again, it had a white, not transparent background. How would i do this?
-
05-25-2006, 04:06 PM #2467QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
The GIMP.
Zitat von emericaska8r
To find it, go to Google.
dont worry, its free.
Ok, you need to get a runtime environment before the actual painting app, but its in the same site, so its not a problem.
all right now, once its installed, open it.
open up a photo. (its comes in it own window.)
on the top it says: File Edit Select ... blah blah
go to "Layer"
scroll down to "Transparancy"
to the side, go to "color to alpha"
then you pick a color in your image that will become transparent.
oh yea, it does .png pics. (and LOTS more.)[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-25-2006, 04:46 PM #2468Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von EminentJonFrost
i dont think youre even allowed to do that. i would just make two seperate arrays/tables.--------------------------------------------------------------------------------------
-
05-25-2006, 07:51 PM #2469words 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
Yes you are allowed... Not in LUA though... nad it sounds to me like your making a class, which is in C(?)/C++ so far...
But you can always do a multilayered table/array... I dunno if LUA supports it but...
example[3][3] = ( '1', '2', '3'
'4', '5', '6'
'7', '8', '9'
;}; example
Its something like that... that is for a tic-tac-toe board... so i dunno if LUA can support even this, let alone classes...
sorry, no help here =(
...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
-
05-26-2006, 02:33 AM #2470QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
thanks for trying.
but I know its possible.
Luaplayer's own game "snake" has this piece of coding in it to prove it:
Code:... -- possible options for menu possibleOptions = { speed = { displayName = "Speed", values = { 1, 2, 3 } }, level = { displayName = "Level", values = { "grass", "desert" } }, music = { displayName = "Music", values = { "on", "off" } }, sound = { displayName = "Sound", values = { "on", "off" } } } ...[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-26-2006, 04:05 AM #2471
I think "example[3][1]" works (where [3] is the second table thats on the 3th place in the big table and [1] is the first value in the second table), but Im not completely sure.
Have you tried to just use: "bigtable.table1.valu e"? Maybe that works aswell.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-26-2006, 04:11 AM #2472QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
i thought about it, but no I havent tried that. I will right now...
edit - nevermind, I'm just gonna make a new table. I'll figure it out later.
One last thing, I have the enemy's "y" location set to math.random(272). making it appear randomly, but how come it appears at the same place everytime I start the game up?Geändert von EminentJonFrost (05-26-2006 um 04:34 AM Uhr)
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-26-2006, 06:24 AM #2473Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von EminentJonFrost
put this at the VERY top of you code:
it should give you different numbers now.Code:math.randomseed(os.time())
--------------------------------------------------------------------------------------
-
05-26-2006, 12:07 PM #2474QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
It worked!
But why?[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-26-2006, 01:07 PM #2475Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von EminentJonFrost
that function make the random numbers based on the time, which isnever the same. without it, the psp ram recalls the number it got last time, cause it gets kinda "lazy". i dont relly know how to exxplain it, but hey, it works!--------------------------------------------------------------------------------------
-
05-26-2006, 02:08 PM #2476QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
^^what he said it's especially great for luawindows
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
-
05-26-2006, 02:25 PM #2477QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
oh.
thanks for explaining it!
BTW, I think I found out how to call variables from tables that are inside tables.
"table name" [#] .(dot) "variable"
Code:example: a = { b, c = { d } } a[2].d[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-26-2006, 02:31 PM #2478QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
yes or like so:
table = {}
table[1] = {x = 5}
table[2] = {y = 6}
screen:blit(table[1].x,table[2].y,image)
i use mine this way(onle an example)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
-
05-26-2006, 02:34 PM #2479QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
that way looks easier. more organized, easier to find what you want.
Zitat von slicer4ever
I'll do it like that.[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-26-2006, 02:40 PM #2480QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
it makes things much more easier as you said especially to understand everything
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
-
05-26-2006, 03:23 PM #2481Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von EminentJonFrost
it would be eaiser to just do:
you dont need to create 2 tables.Code:table = {} table[1] = { x = 5, y = 6 } screen:blit(table[1].x, talbe[1].y, image)--------------------------------------------------------------------------------------
-
05-26-2006, 07:05 PM #2482
Yea, I downloaded The Gimp, yet when I try to save it with that transparent background it says because of .png capabilites, the layer must be merged, and then it doesn't save it with the invisible background? Any ideas? ???????
-
05-26-2006, 07:06 PM #2483TheMarioKartersGuest
If you're having problems with transparent backgrounds, PM me the images, i'll do it.
Zitat von emericaska8r
-
05-26-2006, 07:29 PM #2484
- Registriert seit
- Nov 2005
- Ort
- Minnesota, USA.
- Beiträge
- 36
- Points
- 4.492
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I'll explain them as best I can.
Zitat von PSPduh
screen:drawLine
The syntax for screen:drawLine is as follows:
The x0 represents the starting "x" (horizontal) coordinates for a line.Code:screen:drawLine(x0, y0, x1, y1, color)
The y0 represents the starting "y" (vertical) coordinates for a line.
The x1 represents the ending "x" (horizontal) coordinates for a line.
The y1 represents the ending "y" (vertical) coordinates for a line.
The color represents the color of the line.
EXAMPLE:
If I wanted to display a red line starting at the top left corner of the screen, and ending at the bottom right corner of the screen, I would use the following linesof code:
Code:red = Color.new(255,0,0) x0 = 0 y0 = 0 x1 = 480 y1 = 272 while true do screen:drawLine(x0, y0, x1, y1, red) screen.waitVblankStart() screen.flip() end
screen:fillRect
The syntax for screen:fillRect is as follows:
The x represents the "x" (horizontal) coordinates for the top left-hand corner of the rectangle that you want to fill with a color.Code:screen:fillRect(x, y, width, height, color)
The y represents the "y" (vertical) coordinates for the top left-hand corner of the rectangle that you want to fill with a color.
The width represents the width (in pixels) of the rectangle that you want to fill with a color.
The height represents the height (in pixels) of the rectangle that you want to fill with a color.
The color represents the color that the rectangle will be filled with.
EXAMPLE:
If I wanted to fill a rectangle with the color red that starts at the top left-hand corner of the screen, and extends 200 pixels in both directions (vertical and horizontal), I would use the following lines of code:
Code:red = Color.new(255,0,0) x = 0 y = 0 width = 200 height = 200 while true do screen:fillRect(x, y, width, height, red) screen.waitVblankStart() screen.flip() end
Hope that cleared things up a bit. :icon_smil
-
05-27-2006, 04:29 AM #2485
Does anybody know if its faster to blit a whole image at once (so one big image) or two small slices? I need every bit of speed to be able to blit all the units.
If a unit moves, I need to delete the unit first and then blit it at the new position. I can delete the whole unit and blit it at the new place. OR I can delete only the part where it isnt anymore. But if it moves diagonaly it has to delete two slices (eg upper- and leftside).
I know its better to blit one big image then alot of smaller ones that form an image the same size. But im not sure if its the same if the smaller images have a smaller surface than the big one.
I hope its clear I tried my best.
BTW Why am I a PREMIUM Member suddenly? Thx to who ever made me one though!Geändert von Altair (05-27-2006 um 05:07 AM Uhr)
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-27-2006, 05:30 AM #2486QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Thank you so much! :Punk: I'm copying that into notepad so I wont forget it.
Zitat von Jeffery
EDIT: Is there a way to make a curved line? And no I can't use a preset one in an image, for the app I'm making.Geändert von PSPduh (05-27-2006 um 06:11 AM Uhr)
-
05-27-2006, 06:28 AM #2487
- Registriert seit
- Nov 2005
- Ort
- Minnesota, USA.
- Beiträge
- 36
- Points
- 4.492
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I've kinda wondered how to do that myself, and I'll give it a try and see if I can come up with something. The only possible way that I can think of right now would be to draw every pixel in the curved line that you would want to create. Of course, that would take up a ton of lines of code.
-
05-27-2006, 06:36 AM #2488
It doesn't have to be a ton of code, depends on the curve. I just think it would go really slow, because it has to blit the curve pixel by pixel.
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-27-2006, 06:46 AM #2489QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
I found this in the lua snippet thread in the dev's dungeon:
Even though it would draw a circle, at least it is curved. But maybe I could use a for loop to draw the curved line, so it wouldn't take up lines and lines of code. That's what the for loop is there for, to do a lot in a little lines of code.
Zitat von MagicianFB
EDIT: About screen:drawLine, do I need to use x0 y0 x1 y1? Because once you set them to what their equal to, then you can't change it. So can I do this:
Can I use different variables besides x0 y0 x1 y1? <<<< Thats what I really mean.Code:screen:drawLine(10,10,90,100,red)
Geändert von PSPduh (05-27-2006 um 07:11 AM Uhr)
-
05-27-2006, 07:49 AM #2490
- Registriert seit
- Nov 2005
- Ort
- Minnesota, USA.
- Beiträge
- 36
- Points
- 4.492
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Yep, you can use different variables or no variables at all (just the actual numbers).


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