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; To those who are just starting out and wnat to integrate pressurized movement of your sprite or object or player ...
-
04-21-2007, 12:26 PM #7021words 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
To those who are just starting out and wnat to integrate pressurized movement of your sprite or object or player or w/e, heres a simple way:
Code:-- before your main loop, where you define variables sensitivity = 50 -- how far away from the center of hte analog stick should the sprite/w/e start moving maxspeed = 5 -- when the analog stick is fully extended in one direction, this is the speed the sprite/w/e will be moving -- in your main loop for where player movement is polled from the psp pad pad = Controls.read() if pad:analogX() < -sensitivity or pad:analogX() > sensitivity then sprite.x += analogX()/(128/maxspeed) end if pad:analogY() < -sensitivity or pad:analogY() > sensitivity then sprite.y += analogY()/(128/maxspeed) 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
-
04-21-2007, 01:21 PM #7022
good snippet there sg. Edit: there is no += in lua. For people looking at the snippet it should be sprite.x = sprite.x + analogX()/(128/maxspeed)
-- same with the y also.
I have a question. If i have a function that i only use like once (a main menu funtion) can during I make this function nil (clear it from memory) to make play in my game faster? Because i was thinking that if a function was big, having it stored in memory and not being used would slow the game. Does anyone know if this would speed it up? If so how?
would it just be like:?Code:function something() --blah end something() = nil
-
04-21-2007, 01:24 PM #7023
well i prefer to do it as oop cos that is the correct way to do a game. else..you must haave alot of thigs and functions to manage your things in the game.. soo .. as in the starfield example up ther. i asing each objet star. to an array and acces to each object property soo simple..."think in the stars as enemys on a space shoter"... but wy the second one is given me an error,, i wont move a simple sprite,
i will move an object, in the analog angle direction..(that i have solved.) can some one say wy that nil thing.
by the way tnks KleptoOne of taking care of my code. and.. yeaa that code line is somthing to link the classes. iwas reading a oop lua tutorial and that is the way they do, im used to oop in c++,blitzmax, stuff, but ther is a learning point in the life of a programer when must learn more languages and each one have his way.
sorry of my englis. im not uk not nortamerica :P
-
04-21-2007, 01:30 PM #7024QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
ok this is bothering me again, in my collision i have it where when two objects collide then it restarts the game using dofile("br.lua"). How do i have it where when the to same objects collide but the player image is different it would cancel the dofile("br.lua")?
-
04-21-2007, 02:23 PM #7025
haaaa forget about that oop, i "figure out" jaja .. all i did is copy the estructore of the starts i did, and now is woeking... i start to think lua has his spirits :P...
-
04-21-2007, 02:33 PM #7026
Hey sg i tryed to use your example you gave and then changed what the other guy said to but it still doesn't work i get Error: main.lua:28: attempt to call global 'anaogY' (a nil val
i am not sure what to do. What ever i try i get this error.
-
04-21-2007, 02:42 PM #7027QJ Gamer Green
- Registriert seit
- Jun 2005
- Ort
- Fascination Street
- Beiträge
- 7.215
- Points
- 43.021
- Level
- 100
- Downloads
- 0
- Uploads
- 0
For Bob: youresam: put "pad:" before analogY()
[SIZE=2][FONT=Verdana][SIZE=3][U][B]3 YEAR VETERAN[/B][/U][/SIZE][SIZE=3][FONT=Arial Black]
[/FONT][/SIZE][/FONT][/SIZE]Thanks to the following whose ever made me a sig/av.
[U][I][FONT=Impact]
[/FONT][/I][/U]
-
04-21-2007, 03:01 PM #7028QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- Tokoroa, New Zealand
- Beiträge
- 103
- Points
- 4.412
- Level
- 42
- Downloads
- 0
- Uploads
- 0
And spell analogY correctly. Lol.
-
04-21-2007, 03:12 PM #7029
oh sorry it is spelled right on my psp i get that error on analogX also though.
-
04-21-2007, 06:01 PM #7030words 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, use this as a base (this has the fixed += thing, also, make sure you replace 'pad' with whatever your feeding the current control states into (in this case, 'pad')
That works dandy... If all else fails, copy some of your code here.Code:-- before your main loop, where you define variables sensitivity = 50 -- how far away from the center of hte analog stick should the sprite/w/e start moving maxspeed = 5 -- when the analog stick is fully extended in one direction, this is the speed the sprite/w/e will be moving -- in your main loop for where player movement is polled from the psp pad pad = Controls.read() if pad:analogX() < -sensitivity or pad:analogX() > sensitivity then sprite.x = sprite.x + analogX()/(128/maxspeed) end if pad:analogY() < -sensitivity or pad:analogY() > sensitivity then sprite.y = sprite.y + analogY()/(128/maxspeed) 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
-
04-21-2007, 06:31 PM #7031
(cleared my post because i found something out myself) :)
-
04-21-2007, 06:38 PM #7032QJ Gamer Green
- Registriert seit
- Oct 2005
- Beiträge
- 543
- Points
- 6.721
- Level
- 53
- Downloads
- 0
- Uploads
- 0
youresam: SG57 you nub, test out your code before you tell another nub that it works. Had you actually read the message I relayed earlier, you would notice that you forgot to put pad: before analogX()and analogY()
Zitat von SG57
HELP ME HAIRY LEG!!!!
I have a 1.5 (downgraded) US PSP
[code]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( P | S | P | - | P | r | o | g | r | a | m | m | i | n | g )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
_ _ _ _ _
/ \ / \ / \ / \ / \
( A | d | m | i | n )
\_/ \_/ \_/ \_/ \_/ [/code]
-
04-21-2007, 06:47 PM #7033
??? wtf he did put pad: in front!
-
04-21-2007, 06:53 PM #7034QJ Gamer Green
- Registriert seit
- Oct 2005
- Beiträge
- 543
- Points
- 6.721
- Level
- 53
- Downloads
- 0
- Uploads
- 0
youresam: look after the if statements
Zitat von emericaska8r
HELP ME HAIRY LEG!!!!
I have a 1.5 (downgraded) US PSP
[code]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( P | S | P | - | P | r | o | g | r | a | m | m | i | n | g )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
_ _ _ _ _
/ \ / \ / \ / \ / \
( A | d | m | i | n )
\_/ \_/ \_/ \_/ \_/ [/code]
-
04-21-2007, 07:37 PM #7035words 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
To youresam - You and your ****y attitude... Im almost positive its what got you banned (before you created the dupe account mocking Fanjita... you should be ashamed...). Ive been working with OSlib for the past week, and to poll for analogvalue, :
True, i forgot the pad: before each analogX/Y, so thanks for clearing that up :P (i didnt test the snippet, as Lua is no longer useful to me...Code:osl_pad->analogX(); osl_pad->analogY();
, also - the person using the snippet shouldve seen the line number pointing to the line missing the pad: ;))
New, tested version ;) lol
Code:-- before your main loop, where you define variables sensitivity = 50 -- how far away from the center of hte analog stick should the sprite/w/e start moving maxspeed = 5 -- when the analog stick is fully extended in one direction, this is the speed the sprite/w/e will be moving -- in your main loop for where player movement is polled from the psp pad pad = Controls.read() if pad:analogX() < -sensitivity or pad:analogX() > sensitivity then sprite.x = sprite.x + pad:analogX()/(128/maxspeed) end if pad:analogY() < -sensitivity or pad:analogY() > sensitivity then sprite.y = sprite.y + pad:analogY()/(128/maxspeed) 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
-
04-21-2007, 09:40 PM #7036
I got the analog working guys thanks for the help. It took a few trys. I had to adopt it to work with my code a little bit.
Thanks Bob Hoil
-
04-21-2007, 09:59 PM #7037QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- Tokoroa, New Zealand
- Beiträge
- 103
- Points
- 4.412
- Level
- 42
- Downloads
- 0
- Uploads
- 0
What does the table.concat function do?
EDIT: Forgot to say "Please".
-
04-21-2007, 10:03 PM #7038lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
It concatenates all strings of a list.
-
04-21-2007, 10:10 PM #7039QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- Tokoroa, New Zealand
- Beiträge
- 103
- Points
- 4.412
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Ok sweet thanks. Firefox 2 is giving me a lot of trouble and it sometimes stops pages from loading. At the moment Evilmana and lua.org are both stopped.
-
04-21-2007, 10:14 PM #7040lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
lua.org is where you can find your answer also.
http://www.lua.org/pil/11.6.html
-
04-21-2007, 10:16 PM #7041QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- Tokoroa, New Zealand
- Beiträge
- 103
- Points
- 4.412
- Level
- 42
- Downloads
- 0
- Uploads
- 0
lua.org isn't loading at the moment. Damn Firefox 2.
-
04-21-2007, 10:27 PM #7042words 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
First thing that pops up on google:
http://www.lua.org/pil/11.6.html
Firefox 2? im on firefox, works fine
...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
-
04-21-2007, 11:01 PM #7043QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- Tokoroa, New Zealand
- Beiträge
- 103
- Points
- 4.412
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Server not found
Firefox can't find the server at www.lua.org.
* Check the address for typing errors such as
ww.example.com instead of
www.example.com
* If you are unable to load any pages, check your computer's network
connection.
* If your computer or network is protected by a firewall or proxy, make sure
that Firefox is permitted to access the Web.
Thats what comes up every time when it decides to stop me from connecting to a site. It may be because I'm on Vista.
It's weird. About one in five pages won't load and it is always the server not found error.
-
04-21-2007, 11:32 PM #7044QJ 300th Hot Club Member

- Registriert seit
- Mar 2006
- Ort
- Im not to sure.... Psp Firmware: 3.10 OE-A
- Beiträge
- 1.670
- Points
- 14.700
- Level
- 78
- Downloads
- 0
- Uploads
- 0
youresam says: right click your network connection and hit repair, my guess is you cannot connect to your DNS server properly
-
04-21-2007, 11:59 PM #7045QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- Tokoroa, New Zealand
- Beiträge
- 103
- Points
- 4.412
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Windows has confirmed that this computer is currently experiencing a network connectivity problem
Windows found a problem that cannot be repaired automatically
Contact your Internet service provider or network administrator for help or click here for information about things you can try to help resolve this problem.
Hmmm seems you were right but I tried to correct the problem and none of the options applied to the problem I have.
Oh well I can put up with it I suppose.
PS: This was my 100th post
-
04-22-2007, 04:01 AM #7046QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- Relative
- Beiträge
- 135
- Points
- 3.679
- Level
- 38
- Downloads
- 0
- Uploads
- 0
OK this is probably something stupid but it is really annoying me. :Argh:
I'm trying to get the color of a pixel in a empty created image(I will put stuff on it later), and that works fine until I put it in a for loop and use the iterator as an argument in pixel()
If I try to run the above code I get: "error: script.lua:5: An argument was incorrect"Code:image = Image.createEmpty(50,50) for i = 0, 50 do color = image:pixel(0, i) Colors = color:colors() if Colors.r ~= nil or Colors.r ~= 0 then screen:print(10,10*i,Colors.r,Color.new(255,255,255)) end end screen:flip() screen.waitVblankStart(1000)
I tried using the same code only using Image.load() instead of Image.createEmpty() and it works fine, I even cleared the image with color and drew on it, just to make sure it isn't giving me problems because it's empty, but still I get the same error.
I know this is probably some tiny mistake so just rid me of my misery. TIA :Jump:
-
04-22-2007, 05:09 AM #7047
the image is 50x50 pixels, however because the coord system starts at 0, the for loop should only go to 49
-
04-22-2007, 09:10 AM #7048QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
ok this is bothering me again, in my collision i have it where when two objects collide then it restarts the game using dofile("br.lua"). How do i have it where when the to same objects collide but the player image is different it would cancel the dofile("br.lua")?
-
04-22-2007, 09:24 AM #7049words 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
Urameshi - You arent getting an answer, as your very specific. If you designed your code structure correctly, an if statemetn checking for collision between the two objects restarts the script, then another for when a different two objects collide does soemthing else. Honestly, i havent a clue what to tell you

...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
-
04-22-2007, 09:47 AM #7050QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
well.... thanks anyways


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