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 dan369 Any suggestions? Though will it be free? If so any good free website places? Then i get ...
-
05-29-2008, 06:34 AM #8671Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
after a quick conversation with my friend, you would use a php script that was on your site to write the score to a file, then you would get the scores from the file returned to the psp
Zitat von dan369
you can host your own website on your home pc but if you dont want o do that then you should probably get a freewebs website, using html upload made, not the freewebs site builder, that way you can upload an index page and the php score updater and tell the psp to access those files
------ 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).
-
05-29-2008, 07:02 AM #8672Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
I give up, Thats way too hard for me. I tried it but Nope, i cant do it
-= Double Post =-
I need some new help now lol.
so i want the choose 4 u to select ur ow music. I got an file browser set up, and would like some way that u press X it would dofile the game then play the song.
Then once that song has finished play the next, OR is there a way to search mso:/music and put the songs in an list then play them one by one?Geändert von dan369 (05-29-2008 um 02:56 PM Uhr) Grund: Automerged Doublepost
-
05-29-2008, 03:36 PM #8673QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Ok, I have a quick question, and I don't even know if you can do this in lua, I've seen it done on a couple of C apps, so we will see. What I want to do is like in Daedalus, where all you do is drop a ROM(or in my case, a pack of folders filled with lua scripts) and on the game selection screen it atomatically shows the names of the folders, and executes it. Another example of this is PSPRevolution, themes/songs. Thanx a lot.
-
05-29-2008, 03:53 PM #8674
check the lowser lua file in luaplayer0.16 or 0.20
Zitat von PSProgramer
My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
05-29-2008, 04:46 PM #8675
hi im working on a multi player game and trying to use ad hoc.. well the problem im having is when i send a value like the players x position to the second psp i am unable to use it as a number value only as a string value any suggestions?
this is my first time using ad hoc functions so excuse the noobishness
an example would be like lets say i have the value x2 (second players x position)
and i send it like this
Adhoc.send(X2)
and receive it like this
p2 = Adhoc.recv()
and i want
X2 = X2 - p2
but i get the error that p2 is a string value :/
Edit: i was looking for a lua multi player game to use as a reference but was unable to find any :/ i could only find those lua adhoc messengers witch dont help much as they only send textGeändert von waywardson (05-29-2008 um 06:00 PM Uhr)
-
05-29-2008, 06:36 PM #8676QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
waywardson - p2 = tonumber(p2) also make the adhoc data be sent every second or third (60x per second is pointless and uses tons of power) loop and then make it be a single transfer string with ALL the info you wanna swap and then make the program disassemble that one sent string into the different values. Cramming 5 variables into one string, sending that, and then disassembling the string into its variables is MUCH faster than sending 5 pieces of data and also is less prone to transfer errors from receiving the wrong send etc.
everybody else - learn some basic programming concepts and then use a filebrowser base to make what youre after
also lol 12^2 posts
-
05-29-2008, 06:40 PM #8677
thanks turtlespwn that makes sense :P
-
05-29-2008, 06:45 PM #8678QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
yup. im too lazy to code anything for a few weeks but I'll gladly assist with concepts/how to accomplish tasks/telling people theyre idiots/helping people improve their programs
also, you might consider making your program do a threeloop rotating system, something like this:
Loop1: Receive adhoc transfer variables, do math calculations for pad input etc
Loop2: Do math, redraw/rerender stuff to screen
Loop3: Do math, send adhoc transfer variables
This will make it so that there is a little bit of time from when each psp sends its data to when the other PSP tries to receive it. It RUNS at 60fps, the wifi runs staggered 2/3 frames, and the rendering is run in the other nonwifi frame. This should help you evade any big efficiency problems (although provided you keep your game simple this is a bit overkill provided it runs fairly efficiently but its neat to play around with conceots)
-
05-29-2008, 07:10 PM #8679
hi turtlespwn.. if its not too much of a hassle could u write a little example of how i would manipulate the object on he second psp... not a whole script just the sending and receiving parts :P
i understand the concept but am still having a little trouble
-
05-29-2008, 07:18 PM #8680QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Both PSPs would run the same code. I'm currently multitasking too much to get my mind straight on actual code but here's some concept code:
or something like that. i dunno play with it and see what you get. maybe you need to recv at the same time you send, im not sure how exactly the adhoc implementation functions. anyways you shouldnt have seperate code for each psp, they should be identical (for obvious reasons)Code:while true blah blah insert tons of string manipulation here to compact data that gets sent to one string send data do math screen.waitVblankStart() -- basically that makes this first part the first of the three frame cycle do math render stuff (screen:clear() screen:blit(blah) screen:print(blah) screen.flip()) screen.waitVblankStart() -- makes this the second part of the threeloop cycle receiveddate = Adhoc.recv() blah blah insert tons of string manipulation here to break received string into different variables such as otherPlayerX otherPlayerY otherPlayerH etc do math end
-
05-29-2008, 07:24 PM #8681
thanks
-
05-30-2008, 03:08 AM #8682Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
dan i extremeley strongly advise you to use states, not to dofile everything
Zitat von dan369
you can get the list of files from the music directory, remove the "." and the "..", and then the list will be of the music files, you could then remove directories if you want to make it easier and then loop through the songs in that list after each one finishes keeping a variable that holds the number of the current song, when the song finished if it is the last one in the list then it should rotate and go back to number 1
the reason not to dofile things is that if you sorted all the musig out and then dofile the game, where will the code for the music be ? it will be in the other script that isnt in memory any more.
so use states that is the answer, and then make a function to sort the music, and another to play it, then just put it inside the loop for your game
thanks
[email protected]------ 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).
-
05-30-2008, 01:34 PM #8683QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Hey, FatBOYCG, I don't mean to nag or anything, but have you looked at the P.M. I sent you??? thanx
-
06-01-2008, 09:03 AM #8684
Lua Error
Hey, recently i've started developing a game in lua. When I run the game on luaplayer for windows it works fine. When I run it on luaplayer for the psp it gives an error:
index.lua:24: attempt to index global 'OpenThat' <a nil value>.
I think that's the part where i write to a txt file. I don't know why it's giving this error because it worked fine on luaplayer for windows.
Here is the code:
TheRandom = 0
LoadGame,message = loadfile("game.lua")
LinkGreen = Color.new(0,255,0)
GoronRed = Color.new(200,0,0)
ZoraBlue = Color.new(65,105,225)
LightTemple = Color.new(205,173,0)
TheBackSpace = Image.createEmpty(480,272 )
TheBackSpace:clear(GoronR ed)
TheOldPad = Controls.read()
math.randomseed(os.time() )
while true do
OpenThat = io.open("ms0/PSP/GAME150/luaplayer/Applications/Test/Number.txt","w")
ThePad = Controls.read()
screen:clear()
screen:blit(0,0,TheBackSp ace)
screen: print(115,130, "The Time To Stop The Time Is: " .. TheRandom, LinkGreen)
screen: print(130,150, "Press (X) To Get Your Number" , ZoraBlue)
screen: print(155,170, "Press (Start) To Play" , LinkGreen)
if ThePad:cross() and TheOldPad:cross() ~= ThePad:cross() then
TheRandom = math.random(3,15)
end
if ThePad:select() then
OpenThat:write(TheRandom) -- the 24th line(error) --
OpenThat:close()
LoadGame()
end
screen.flip()
screen.waitVblankStart()
TheOldPad = ThePad
end
If anyone finds out why please tell me.
Thanks
-
06-01-2008, 09:09 AM #8685QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
As we said at Evilmana: http://www.forums.evilmana.com/index.php?topic=1413.0
Zitat von tombradyisgod12
It is because it can't find the location/file. This is because your file path is wrong.[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]
-
06-01-2008, 09:18 AM #8686
Yeah, I tried everything that everyone told me. Unfortunately nothing worked. I am sure that I'm pointing to the correct file. I'm trying to see if anyone else has a different solution to my problem.
Thanks for the help.
-
06-01-2008, 09:49 AM #8687Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Have you tried changing the whole thing?
By this i mean Have an Single folder in GAME called MyGame, Copy the eboot, files etc then Change the Path to
What Luaplayer Are you using?Code:OpenThat = io.open ("ms0:/PSP/GAME/MyGame/Number.txt", "w")
-
06-01-2008, 10:04 AM #8688Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
im knackered after going on a 50 mile bike journey and even i managed to spot the error
its ms0:/ soCode:OpenThat = io.open("ms0/PSP/GAME150/luaplayer/Applications/Test/Number.txt","w")
and why do you need to use a full path if you are in the test directory then useCode:OpenThat = io.open("ms0:/PSP/GAME150/luaplayer/Applications/Test/Number.txt","w")
EDIT:Code:OpenThat = io.open("./Number.txt", "w")
this works perfectly
and now im going bedCode:TheRandom = 0 LoadGame, message = loadfile("game.lua") LinkGreen = Color.new(0,255,0) GoronRed = Color.new(200,0,0) ZoraBlue = Color.new(65,105,225) LightTemple = Color.new(205,173,0) TheBackSpace = Image.createEmpty(480, 272) TheBackSpace:clear(GoronRed) math.randomseed(os.time()) while true do pad = Controls.read() screen:clear() screen:blit(0, 0, TheBackSpace) screen:print(115, 130, "The Time To Stop The Time Is: " .. TheRandom, LinkGreen) screen:print(130, 150, "Press (X) To Get Your Number", ZoraBlue) screen:print(155, 170, "Press (Start) To Play", LinkGreen) if pad:cross() and not oldpad:cross() then TheRandom = math.random(3, 15) end if pad:select() and not oldpad:select() then OpenThat = io.open("./Number.txt", "w") OpenThat:write(TheRandom) OpenThat:close() LoadGame() end screen.waitVblankStart() screen.flip() oldpad = pad end
EDIT 2:
the reason you had the error is because you tried to open the file every loop which could be hundreds / thousands of times a secondGeändert von FaT3oYCG (06-01-2008 um 08:44 PM Uhr)
------ 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).
-
06-02-2008, 03:43 AM #8689
It works now! Thanks a lot for the help Fat3oYCG, and yaustar. Now I have one more problem with the following lua file. Game.lua. I loaded it in my other file. It's telling me that I am trying to use arithmetics on a variable called our line and that it's a nil value. Once again it worked on luaplayer for windows but not on the PSP. Here's the code:
keyPressed = 0
LinkGreen = Color.new(0,255,0)
GoronRed = Color.new(200,0,0)
TheBackSpace = Image.createEmpty(480,272 )
TheBackSpace:clear(GoronR ed)
TheBackSpace2 = Image.createEmpty(480,272 )
TheBackSpace2:clear(LinkG reen)
CountUp = Timer.new()
CountUp2 = Timer.new()
CountUp3 = Timer.new()
CountUp:start()
CountUp2:start()
CountUp3:start()
while true do
ThePad = Controls.read()
if (keyPressed == 1) or (ThePad:circle() and keyPressed == 0) then
CountUp3:stop()
file = io.open("./Points.txt","w")
file2 = io.open("./Points.txt","r")
file3 = io.open("./Number.txt", "r")
file:write(TheTimeToPress )
file:close()
screen:blit(0,0,TheBackSp ace2)
screen: print(175,130,"Your Time: " .. TheTimeToPress,GoronRed)
ourline1 = file2:read()
ourline2 = file3:read()
screen: print(165,150,"You Scored: " .. math.abs(ourline1 - ourline2 * 1000,GoronRed)
keyPressed = 1
file2:close()
file3:close()
elseif keyPressed == 0 then
TheTimeNow = CountUp:time()
TheTimeToDisplay = CountUp2:time()
TheTimeToPress = CountUp3:time()
screen:blit(0,0,TheBackSp ace)
screen: print(220,120,"" .. TheTimeNow,LinkGreen)
if TheTimeToDisplay > 2000 then
screen: print(165,120,"Press ( ) To Stop",LinkGreen)
end
if TheTimeNow > 2000 then
CountUp:reset()
end
end
screen.flip()
screen.waitVblankStart()
end
If there is anything that can be done please tell me.
Thanks.
-
06-02-2008, 03:43 AM #8690
By the way the error is for the variable ourline1.
-
06-02-2008, 04:30 AM #8691QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
1. Use code tags
2. Indent your code
3. Tell us what line number
4. You can't open a file in write mode and then open it in read mode
5. Stop using windows luaplayer as your primary testing platform, don't ask why it'll just end up in a huge argument that wastes everybody's time (essentially - you're scripting for the PSP so why aren't you testing on it?)
-
06-02-2008, 06:02 AM #8692Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
wtf people seem to be useless with the luaplayer io functions and they are simple
open the file
read / write to the file
close the file
not
open one file
open another
and another
write
read
write
close
close
close
that is bad coding
e.g. to read a file
to write to a fileCode:file = io.open("file.txt", "r") data = file:read("*a") file:close()
Code:file = io.open("file.txt", "w") file:write("my text") file:close()Geändert von FaT3oYCG (06-02-2008 um 06:47 AM Uhr)
------ 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).
-
06-02-2008, 06:13 AM #8693
Thanks again FaT30YCG. everything works fine now. I didn't realize that I had to close my file each time before I read or write again.
-
06-05-2008, 09:30 AM #8694QJ Gamer Green
- Registriert seit
- May 2008
- Beiträge
- 246
- Points
- 3.810
- Level
- 39
- Downloads
- 0
- Uploads
- 0
Can some1 give me a good tutorial of some copy and move commands in lua? (i'm kind of a newbie).
Overwriting is automatic right? (when copying/moving).
Also, let's say I want to copy from a to b (a is ms b is flash3), and flash3 didn't had enough place, I assume an error would pop.
Can I customize the error?
-
06-05-2008, 02:24 PM #8695QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Dont assume anything when programming, always check for foreseeable errors beforehand. And why are you using Lua to write to flash3?
-
06-05-2008, 02:56 PM #8696QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
@TurtlesPwn
Question| C VS LUA
@CoMbiNa
http://lua-users.org/wiki/IoLibraryTutorial
-
06-05-2008, 04:26 PM #8697QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Nielkie, I saw that thread, I just think that if you're not willing to devote enough time to learn C and make a more stable reliable program to modify the flash of my PSP, then I'm not willing to devote enough of my confidence and trust to your program. I'm sure many others have a similar opinion.
-
06-05-2008, 09:10 PM #8698QJ Gamer Green
- Registriert seit
- May 2008
- Beiträge
- 246
- Points
- 3.810
- Level
- 39
- Downloads
- 0
- Uploads
- 0
What? I'm just making a game saves dumper from savedata into flash3
-
06-06-2008, 01:39 AM #8699QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Quick question that has been bugging me: Is there any advantage using x * (math.pi / 180) over math.rad(x) ?
Also, is there any difference between math.pi and Gu.PI ?
-
06-06-2008, 05:14 AM #8700QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Using the manual math would be a (very tiny and rather insignificant) bit faster because it doesnt have to call a function which does the math but instead simply do the math. I've never used math.pi, just GU.pi, but I doubt there's any difference because Shine probably realized theyre the same thing and internally set them equal. Just wondering, what are you using radians for? Often people convert back and forth between radians and degrees a lot more than they need to instead of simply thinking in radians and when youre doing what radians are used with (trig) which already uses a bit of CPU, it's stupid to waste some on such things.


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