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; yeah... but if the AI is slower then the player then he would most likely never catch the player. So ...
-
07-17-2006, 11:19 AM #2821sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
yeah... but if the AI is slower then the player then he would most likely never catch the player. So you need to incorporate a part in which the enemy predicts where the player is going so it can catch up. (btw, this is what I'm trying to learn to do, the prediction part).
-
07-17-2006, 11:22 AM #2822QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Illinois
- Beiträge
- 897
- Points
- 8.215
- Level
- 61
- Downloads
- 0
- Uploads
- 0
http://www.sendspace.com/file/4jg6xl
Can someone PLEASE take a look at my code. There is a problem with putting the animation on the screen. I haven't been able to work on my game for several days now because I can't get the animation to work.
-
07-17-2006, 11:46 AM #2823I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Maybe you want to give us the part that's giving you trouble. That way we don't have to look at the entire code.

-
07-17-2006, 01:03 PM #2824QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Illinois
- Beiträge
- 897
- Points
- 8.215
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Here is the code that is giving me trouble.
Code:-- Set Default Image link = linkfaced -- Get Default Image Height And Width link:width() link:height() -- Get Screen Height And Width screenwidth = 480 - link:width() screenheight = 272 - link:width() -- Player Info player = {} player.x = 220 player.y = 110 player.moving = "no" player.facing = "down" player.pad = "none" -- Link Walking Down Animation Table linkwalkingd = {} linkwalkingd[1] = linkwalkingd1 linkwalkingd[2] = linkwalkingd2 linkwalkingd[3] = linkwalkingd3 linkwalkingd[4] = linkwalkingd4 linkwalkingd[5] = linkwalkingd5 linkwalkingd[6] = linkwalkingd6 linkwalkingd[7] = linkwalkingd7 linkwalkingd[8] = linkwalkingd8 -- Display Default Image screen:clear() screen:blit(player.x, player.y, link) screen.flip() screen:clear() -- Set loop count loopCount = 0 loopCounts = 0 -- Make Player Move Down if pad:down() and player.y < screenheight then player.y = player.y + 2 player.moving = "yes" player.facing = "down" player.pad = "down" link = linkfaced end -- Link Walking Down Animation Loop if player.moving == "yes" and player.facing == "down" then if loopCount >= 0 and loopCount < 2 then link = linkwalkingd[1] elseif loopCount >= 2 and loopCount < 4 then link = linkwalkingd[2] elseif loopCount >= 4 and loopCount < 6 then link = linkwalkingd[3] elseif loopCount >= 6 and loopCount < 8 then link = linkwalkingd[4] elseif loopCount >= 8 and loopCount < 10 then link = linkwalkingd[5] elseif loopCount >= 10 and loopCount < 12 then link = linkwalkingd[6] elseif loopCount >= 12 and loopCount < 14 then link = linkwalkingd[7] elseif loopCount >= 14 and loopCount < 16 then link = linkwalkingd[8] end if loopCount + 1 >= 16 then loopCount = 0 else loopCount = loopCount + 1 end endGeändert von cwirsing (07-17-2006 um 04:27 PM Uhr)
-
07-17-2006, 01:42 PM #2825
i want it so that my character shoots a bullet and it hits him. I also need to now how to get a bullet that comes from my characters gun in his hand.
-
07-17-2006, 01:52 PM #2826sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
ok, Bob, you asking us for us to just give you code and yout putting it together,. Try going to evilmana.com and read the tuts their. Then come back and tell me if you know how to do all this ;)
-
07-17-2006, 01:59 PM #2827
i typed up the intro screen and everything but all of the tutorials don't explain very well i have tried that i could only get some of the code i typed to wrok even though it looked right by comparing.
-
07-17-2006, 02:24 PM #2828sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
probably because the tuts are for his game, do not copy, paste. You have to fit it to your own code. Post your code and let me see how much you have as of now.
-
07-17-2006, 02:39 PM #2829
well right now access denied is helping me so i will see how it goes first before i post my code.
-
07-17-2006, 06:40 PM #2830
i need help making my basic menu and so if you can help here is what i have: i know im missing something oh and all iget is flickering when i run it as in the thing i want white is white yet when i push up or down it flickers and doesn't exavtly go to the one under or over the one that is selected so yeah please help
Code:red = Color.new(255, 0, 0) white = Color.new(255, 255, 255) p1 = Image.load ("p1.png") block = Image.load("block.png") menu = 0 while true do pad = Controls.read() if pad:down() then menu = menu + 1 end if pad:up() then menu = menu - 1 end if menu < 0 then menu = 2 end if menu > 2 then menu = 0 end if menu == 0 then screen:print(200, 60, "Start", white) screen:print(200, 80, "Options", red) screen:print(200, 100, "Quit", red) screen:flip() end if menu == 1 then screen:print(200, 60, "Start", red) screen:print(200, 80, "Options", white) screen:print(200, 100, "Quit", red) screen:flip() end if menu == 2 then screen:print(200, 60, "Start", red) screen:print(200, 80, "Options", red) screen:print(200, 100, "Quit", white) screen:flip() end if pad:start() then break end end
-
07-17-2006, 06:50 PM #2831I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
First of all, you don't need to add screen.flip() after every menu option. Second, you need to add this to the end.
Also add this line above your "while true do"Code:screen.waitVblankStart() screen.flip()
and add this under the "screen.flip()"Code:oldpad = Controls.read()
and every time you have a "if pad" statement, change it to this:Code:oldpad = pad
This will make it so it doesn't cycle through the options so fast.Code:if pad:button() and oldpad:button() ~= pad:button then blah blah blah end

-
07-17-2006, 07:12 PM #2832
allright ill try it out
Double Post Merge
thanks a lot man that worked
-
07-17-2006, 07:16 PM #2833I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Also, try these changes. The things I changed are in red.
By making these changes you are just cleaning up your code by having less lines.Code:red = Color.new(255, 0, 0) white = Color.new(255, 255, 255) p1 = Image.load ("p1.png") block = Image.load("block.png") menu = 0 while true do screen:clear()-- you can't forget to add this to every program pad = Controls.read() screen:print(200,60,"Start",red) screen:print(200,80,"Options",red) screen:print(200,100,"Quit",red) if pad:down() then menu = menu + 1 end if pad:up() then menu = menu - 1 end if menu < 0 then menu = 2 end if menu > 2 then menu = 0 end if menu == 0 then screen:print(200, 60, "Start", white) end if menu == 1 then screen:print(200, 80, "Options", white) end if menu == 2 then screen:print(200, 100, "Quit", white) end if pad:start() then break end end
-
07-17-2006, 07:32 PM #2834
hey thanks again oh and about the screen clear why do you need to put it cuase ive seen it used a lot like that and don't understand why you need it so if you could explain thatwouls be great and thanks again!
-
07-17-2006, 07:42 PM #2835I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Because if you didn't have the screen:clear(), everything would be pasted on top of each other. Say you had a game, where a blue block moves around the screen. If you didn't have the screen:clear(), when the block moved thier would be a trail behind it. Take it out of your program and see what happens.
BTW- Screen:clear() always clears the screen black, but if you want a blue background or something, you could use this:
or you could use a picture for a background:Code:screen:clear(blue)
Code:screen:clear(Picture you want)

-
07-17-2006, 08:03 PM #2836
oh allright that makes sense thanks for the explanation and advice
-
07-17-2006, 08:43 PM #2837I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
No problem. :)

-
07-17-2006, 10:39 PM #2838Developer

- Registriert seit
- Feb 2006
- Ort
- Tauranga, New Zealand
- Beiträge
- 355
- Points
- 5.162
- Level
- 46
- Downloads
- 0
- Uploads
- 0
There doesn't appear to be anything wrong with the code you've shown (although I may be missing something). A problem is going on somewhere else, and that is with the "linkfaced" variable. But I have no idea what that variable is set to, so I can't help.
Zitat von cwirsing

-
07-21-2006, 02:22 AM #2839QJ Gamer Bronze
- Registriert seit
- Feb 2006
- Ort
- Earth, UK
- Beiträge
- 457
- Points
- 5.924
- Level
- 49
- Downloads
- 0
- Uploads
- 0
where can i find lua tuturails on using the psps wifi?
thanks in advance<<Put A message Here>>
<<Just made another rubbish website visit it here.>>
-
07-21-2006, 05:47 AM #2840
the only way to use wifi with LUA right now is with netlib. There's no tut for it, but there is a very easy example with it. Ah whatever I'll write a very short tut:
what you need:
- netlib2.0
The file itself is called "netlib.lua". Put it in the same folder as your app (this isn't necessairy, you can also put it somewhere else, the path in the "dofile()" command will just change).
First the stuff that should be before your main loop (also remember to turn on the wifi with "Wlan.init()" and connect to the internet using "Wlan.useConnectionConfig (connection)", where "connection" is the number of the connection you want to use. For example: with Wlan.useConnectionConfig( 1) you would connect to your first connection):
1) In your app you have to import it by saying "dofile("netlib.lua") ".
2) After that you have to connect to the server with this "netconnect()"
3) Now before you can send and receive date, you have to create a variable on the server where you can send and receive your data to. You do this with the following command: netreg(id), where id is the name you want the variable to have.
(This command also makes sure the server sends the valua of the variable, whenever the valua of it changes)
Now comes the part that should be in the main loop itself
4) Now you have created a variable on the server you can send data to it by using "netsend(id, data, attribute)", where "id" is the name of the variable, data is the data in a string format (this means you have to turn tables and numbers and other formats into a string first) and where "attribute" is the way you want the data to be put in the variable. The attribute can either be "w" or "a". "w" means write and you will replace data, "a" means append and you will add the new data to the data that was already in the variable.
5) To receive data, you would say "netrecv()". This will receive all incoming data.
6) You don't have the value of the variable yet though. For that you need to use "netvalue(id)", where "id" is again the name of the variable. You need to put this after the "netrecv()" command.
After the main loop, you will need to delete the variable and close the connection:
7) To delete the variable on the server: netunreg(id), where "id" is the name of the variable
8) To close the connection to the server: netclose()
9) To close wifi: Wlan.term()
As an example I have put the example of yoursam (the author of this app) here:
As you can see he uses netget(id) instead of netrecv() and netvalue(id). Eventhough its possible, its way slower (so he said to me). He still uses it because he only needs to get the data once and not continues (I think?). If you want to get the data every loop its better to use netrecv() and netvalue(id).Code:--[[ netlib example by youresam ]] dofile("netlib.lua") -- netlib Wlan.init() print("Connecting to "..Wlan.getConnectionConfigs()[1].."...") Wlan.useConnectionConfig(1) print("Connecting to netlib server...") netconnect() -- connect to netlib server print("Setting up AMW for 'netlibtest' (wont do anything in this example..)") netreg("netlibtest") print("Sending 'helloworld' to 'netlibtest'") netsend("netlibtest","helloworld","w") -- id:netlibtest data:helloworld mode:write print("Getting 'netlibtest'...(Press start to quit)") netget("netlibtest") while true do netrecv() --recieve all incoming data buffer = netvalue("netlibtest") --what is the value of the id 'netlibtest'? if buffer ~= "" then --if it exists... print(buffer) break end if Controls.read():start() then break end end netunreg("netlibtest") --ALWAYS unregister a variable when your done netclose() --close the netlib connection Wlan.term() print("Program finished, hold start to exit.")
Hope it's clear enough (and right. If not please correct me anyone). I didn't explain the mail, sms and call functions. I just explained the basic sending and receiving.Geändert von Altair (07-21-2006 um 05:52 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]
-
07-21-2006, 06:10 AM #2841sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
Damn, thats really good! You should create a seperate thread with this tut in it, so it isnt lost withini all these pages.
Zitat von Altair
-
07-21-2006, 07:06 AM #2842I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
I agree. BTW- shouldn't have this thread been stickied by now?

-
07-21-2006, 07:10 AM #2843QJ Gamer Bronze
- Registriert seit
- Feb 2006
- Ort
- Earth, UK
- Beiträge
- 457
- Points
- 5.924
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Hi
Can anyone tell me if and how you can use the psp ad hoc mode on lua?
Ps. Thanks Altair for answering my previous question<<Put A message Here>>
<<Just made another rubbish website visit it here.>>
-
07-21-2006, 07:17 AM #2844sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
It was, but now its linked to in a stickied.
Zitat von Access_Denied
-
07-21-2006, 07:20 AM #2845I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
That's pretty stupid.
Yes, JoeDaStudd, you can use ad-hoc in LUA. I don't know how though.
-
07-21-2006, 07:54 AM #2846
Thx, if you all think so, i guess I will make a seperate thread about it.
@Acces denied: since when is ad-hoc supported with LUA? Do you maybe have a link or something? That would be really great if it's possible. I do know somebody said it would be really easy, but he said he didn't have the time to do it, so im not to sure on his credibility.LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
07-21-2006, 08:06 AM #2847sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
yeah you sould create a thread for it.
-
07-21-2006, 08:28 AM #2848I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Maybe it isn't supported in LUA. I always thought it was. Guess I better check my info.
Zitat von Altair
Did a google search and found out it isn't.
-
07-21-2006, 09:10 AM #2849QJ Gamer Blue
- Registriert seit
- Feb 2006
- Beiträge
- 81
- Points
- 4.631
- Level
- 43
- Downloads
- 0
- Uploads
- 0
can someone tell me how can i rotate and zoom an image in realtime in lua?what are the functions i have to use?cuz im kinda new to lua and trying to port a game i made in flash.tnx :)
-
07-21-2006, 10:19 AM #2850Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
this is from the lua snippets thread:
Zitat von fuxer
this will rotate an image by a cretain agle:
Code:function rotateImage(theImage, angle) screen:blit(0,0,theImage) angle = angle*(6 + (1/3))/360 for x = 1, theImage:width() do for y = 1, theImage:height() do tX = math.cos(angle)*(x-theImage:width()) - math.sin(angle) * (y-theImage:height()) tY = math.sin(angle)*(x-theImage:width()) + math.cos(angle) * (y-theImage:height()) screen:fillRect(tX + 240, tY + 136, 2, 2, screen:pixel(x, y)) end end end
--------------------------------------------------------------------------------------


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