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 it has some annoying features like if you type "(", you get "( )". I never use that. ...
-
01-21-2007, 07:07 AM #5191QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Yeah. But it has some annoying features like if you type "(", you get "( )". I never use that.
And I got some errors determining available memory... I guess that has something to do with the fact that I'm on a pc:)
-
01-21-2007, 07:11 AM #5192QJ Gamer Green
- Registriert seit
- Aug 2005
- Ort
- a
- Beiträge
- 545
- Points
- 12.085
- Level
- 72
- Downloads
- 0
- Uploads
- 0
I agree te "( )" thing is a bit annoying, but it doesn't bother me that much, maybe post a suggection in the LuaDevKit thread/
Zitat von PSPhakkor
-
01-21-2007, 07:35 AM #5193QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No, that is incorrect. The file that you 'write' to in the Lua script
Zitat von PSPhakkor
Needs to be opened in a different text editor for you to see the line breaks.Code:newFile = io.open( "THIS FILE.txt", "w" )
[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]
-
01-21-2007, 08:12 AM #5194Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
ok what's wrong with this statement ?
if (Player.x + playerWidth > Cheese.x) and (Player.x < Cheese.x + Cheese.width) and (Player.y + playerHeight > Cheese.y) and (Player.y < Cheese.y + Cheese.height) then
score = score + 1 and Cheese.x = math.random(5,420) and Cheese.y = math.random(5,100)
end
-
01-21-2007, 08:29 AM #5195QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
This
Zitat von eldiablov
Why is there lots of ANDs in this line of code?Code:score = score + 1 and Cheese.x = math.random(5,420) and Cheese.y = math.random(5,100)
Shouldn't it be:
Code:score = score + 1 Cheese.x = math.random(5,420) Cheese.y = math.random(5,100)
[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]
-
01-21-2007, 08:47 AM #5196Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
omg i feel so dumb but thank you anyway. My game is now ready for it's alpha release.

-= Double Post =-
Wait one more thing os.exit() is valid in luaplayer 0.19 ?
everytime i execute that command it just crashesGeändert von eldiablov (01-21-2007 um 08:47 AM Uhr) Grund: Automerged Doublepost
-
01-21-2007, 08:49 AM #5197QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
WOW I feel like an idiot too!!!
Zitat von yaustar
eldiablov, you're not alone. Congrats on your game's release! Feels so good, doesn't it?
yaustar, thanks so much for helping me solve the problem. Thanks, thanks, thank you!
Another question now(I feel like I'm overusing this thread): Is it possible to use an array of functions? Like
Code:function table[1]() body end function table[2]() body end
-
01-21-2007, 09:02 AM #5198Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
yeah it feels great. I just hope people think its quite alright as a first release.
link to release thread : http://forums.qj.net/f-psp-developme...v01-91371.html
i appreciate everybodys comments
-
01-21-2007, 09:10 AM #5199QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Yes, bear with me here since this is from memory:
Zitat von PSPhakkor
Code:function HelloWorld() screen:print( 1, 1, "Hello World", green ) end function GoodbyeWorld() screen:print( 1, 1, "Goodbye World", green ) end functionArray = {} functionArray.function1 = HelloWorld functionArray.function2 = GoodbyeWorld -- To use it functionArray.function1()[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]
-
01-21-2007, 10:56 AM #5200QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Ah, I see. I have to use the variable then a period then the "second" variable name. I never really learned that but I think I get it form looking at some code. Thanks, yet again yaustar!
Eldiablov, I'm gonna check out your game as soon as I get my psp. It better be good!
-
01-21-2007, 11:33 AM #5201QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Read up on tables in Lua before doing anything. http://lua-users.org/wiki/TablesTutorial
Zitat von PSPhakkor
[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]
-
01-21-2007, 07:41 PM #5202words 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
Tables are quite interseting. Their arrays, structures and classes combined. Quite the change going from C/C++ to Lua...

...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
-
01-22-2007, 09:12 AM #5203QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
Question: Whats the name of the app that lets you edit/create lua scripts like on the computer, except its all on PSP?
I've seen it before, I've even used it so I know it exists, but deleted it when I upgraded to 2.71 (back when it wasnt cracked) to play Monster Hunter knowingly abandoning homebrew.[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
01-22-2007, 09:52 AM #5204Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Im just trying to make a little tag game here and Im getting an error.
error: snake.lua:82: bad argument #2 to 'print' (string expected, got nil)
Spoiler for My code:
It works just fine when I remove the line that prints the variable it to the screen. But if I leave itI get that error.If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
01-22-2007, 02:06 PM #5205QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Here's what I think you have wrong:
right here when you declared the 'it' variable:You had 'it' set equal to a p1, which the PSP thinks is supposed to be a variable, but there's no value it can find for a variable named 'p1' or 'p2' as the case may be. Therefore, it sets 'it' equal to 'nil', and then when you tried to print 'p1' to the screen, you gave the PSP a nil value to print to the screen.Code:--whos it it = nil wit = math.random(0,1) if wit == 0 then it = p1 elseif wit == 1 then it = p2
The way to fix this is actually give 'p1' (or p2) a value before declaring 'it' equal to 'p1' (or p2).
Or you could set 'it' equal to a different value. There are a few ways to fix it, I think you'll figure it out. just use what I wrote above
-
01-22-2007, 02:09 PM #5206Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
in this line:
Zitat von GuitarGod1134
'it' is NOT a string. i string has quotes around it. how to solve this? two ways:Code:screen:print(0,0,it,red)
1. wherever you assign a value to 'it', put it in quotes. (like: "p2" instead of just p2)
2. use an if statement:
-= Double Post =-Code:if it == p1 then screen:print(0,0,"p1",red) elseif it == p2 then screen:print(0,0,"p2",red) end
im going to have to disagree with that. in lua, when you do that, it still keeps it for reference. in C/C++ however, that may give you problems.
Zitat von PSPhakkor
Geändert von Grimfate126 (01-22-2007 um 02:09 PM Uhr) Grund: Automerged Doublepost
--------------------------------------------------------------------------------------
-
01-22-2007, 02:12 PM #5207Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Ok thanks guys. one more thing. im on the lua player functions website and I see this
Bool System.powerIsPowerOnline ()
and it says bool first. so does that mean this is a valid statement
if System.powerIsPowerOnline () == true then
bla
end
?If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
01-22-2007, 02:16 PM #5208Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
i think so, but this will probably work:
Zitat von GuitarGod1134
because a bool returns a true or false value so it would be the same as saying:Code:if System.powerIsPowerOnline() then bla end
Code:if (true) then ... end OR if (false) then ... end
--------------------------------------------------------------------------------------
-
01-22-2007, 02:22 PM #5209Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
I keep getting an unexpected symbol "=" at line 5. Im just making this to get a feel for some psp exclusive lua player functions but im not sure im doing thsi right because the website did not provide examples.
Spoiler for QuickLook:
-= Double Post =-
Ok Ill try that. thxGeändert von GuitarGod1134 (01-22-2007 um 02:22 PM Uhr) Grund: Automerged Doublepost
If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
01-22-2007, 02:45 PM #5210QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
No problem.
You new problem is due to the fact that most programming languages, Lua included, when asked to assign a value to a variable, will assign the variable to the left of the equals sign the value of the variable or constant on the right. You are trying to set System.powerGetBatteryLif ePercent() to the value stored in batper, which is not possible. Simple solution: switch batper and System.powerGetBatteryLif ePercent() around. Be aware that you will have to do the same thing on the next line
-
01-22-2007, 03:51 PM #5211QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Also, you do not need to put if something == true then, you can just put if something then
And instead of if something == false then you can do if not something then
-= Double Post =-
PSPPDA is the most commonly known one.
Zitat von EminentJonFrost
Geändert von TacticalPinguin (01-22-2007 um 03:51 PM Uhr) Grund: Automerged Doublepost
-
01-22-2007, 07:04 PM #5212QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
When I try to use the '#' operator, to determine the number of elements on a table, I can get toe game to work in LDK, but on a psp, there are errors whenever it gets to that point in the code. Does anyone know if that operator is usable on a psp? Or do I have something else wrong?
any similar issues with modulus (%) also?
-
01-22-2007, 08:09 PM #5213words 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
PSPhakkor - Switching from C to LUA, i expected the modulus to be % as well, but its actually just: math.mod(number,modulo)
TP - Theres nothing wrong with using
== true
or
== false
There good programming habits, for JUST starting as when just starting, your cramming alot of info in your head, and one thing is bound to slip and be forgotten, thus making your code foreign to you (atleast that one line with no == true or == false)
Its just more typing (and soon youll find that to be a pain :S)
...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
-
01-22-2007, 09:21 PM #5214QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
I NEVER said it's bad or anything I just said it is not required.
Zitat von SG57
And if you dont believe me, ask super on this one. Making it a habit to use the shortest method makes for small scripts.
Also, to get the number of items in a table:
blah = table.getn(nameoftablewit houtquotes)
blah will be a number equal to the number of items in the table.
-
01-22-2007, 11:25 PM #5215QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Sydney, Australia
- Beiträge
- 117
- Points
- 4.210
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I'm having the same problem as PSPHakkor, the # command seems to work fine in LuaDevKit, but on the PSP it gives me an error at the first point that # lies. I managed to change one so the command no longer involved # but then it just shows an error at the next #. Any ideas ?
-
01-22-2007, 11:34 PM #5216words 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
TP - I never said you did say you said it was wrong. (lololol wow... migrain)
Its just the way you put it - you made it seem like he was doing somethign wrong... Atleast thats how I interpreted your post... But to be honest, at his skill level (no offense, im just implying by your post on what experience you are at in programming) that 100 bytes (not kilo... just bytes) extra file size in return for a risk free understandability (atleast for hte whole == true or == false thing)
The Bressman - LDK uses WLP. Current version of WLP is = to PSP Lua Player v2.0 (or wahtever it is, its just a 2... like 2.0, 0.2, just something as a 2). Update your luaplayer would be my suggestion.
...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
-
01-23-2007, 06:37 AM #5217QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Alright.
ANyways for you people having troubles with the number thingie, to get the number of items in a table use this:
blah = table.getn(nameoftablewit houtquotes)
blah will now be a number equal to the number of items in the table.
-
01-23-2007, 12:05 PM #5218Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Getting something really wierd here. Trying to implement the get remaining memory function but it gives me this
error : index.lua:38: 'end' expected (to close 'while' at line 10) near (eof)'
Spoiler for Code:
Now I looked at this error and did an experiment and added an end after the end and it creates a .stackdump file in the root of my stick and says that system on line 11 is a nil value along with a bunch of hexidecimals.If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
01-23-2007, 12:18 PM #5219
the line that you have this doesn't have an end for the if statement.Code:if System.powerIsLowBattery() then screen:print(200,110,"You need to get your charger!",red)
-
01-23-2007, 12:21 PM #5220Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
omg i missed that lol thx
If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!


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