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; That still won't work. The problem is that when you press R, it will trigger the functionality inside the R ...
-
11-23-2006, 02:25 PM #4201QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
That still won't work. The problem is that when you press R, it will trigger the functionality inside the R keypress every frame that R is pressed down for which is why it is flashing the images and changing number so quickly since it is extremely difficult to press and release a button within a 2 frames (1/30 th of a second).
You have to check the difference between a key press, a key release and when a key is being held down.
Clue: There is an unused variable there which can be used to help with this.
-
11-23-2006, 03:39 PM #4202Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Well according to head 54us I dont have to test it because it still wont work. Omg head54us what is this a mystery or something lol. Hm..... Is it oldpad?... or maybe randomnr is being used wrong? Do I have to create a new variable or is this variable already in there somewhere? Also I present to you another problem.
or is itif Bullet[1].x + Bullet[1].y == Alien[1].x = Alien[1].y then
bla
end
--would that work right as my collision detection for a dude shooting an alien and the bullet hitting the alien or am i dont something wrong cause i blanked out on the collision detection i had it right (i thought) but it didnt look right. anyone have any examples?
if Bullet[1].x == Alien[1].x and Bullet[1].y == Alien[1].y then
bla
endGeändert von GuitarGod1134 (11-23-2006 um 03:52 PM Uhr)
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!
-
11-23-2006, 04:48 PM #4203The Unique Developer

- Registriert seit
- Oct 2006
- Ort
- Canada
- Beiträge
- 1.059
- Points
- 7.101
- Level
- 55
- Downloads
- 0
- Uploads
- 0
I think the second one and just try the code I gave you :) please ?
Malloc.Us Network Administrator
Decryption of the Encrypted
You are the unseen, the unstoppable and in power of your code. The God of your software.
-
11-23-2006, 04:52 PM #4204Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
ok give me a sec
EDIT: Well this is a mystery still to all of us because no it still does not work. If you dont believe me you can run it yourself just ask me for the pics. But it gives me the same problem while i hold down R it keeps changing the value and bliting the random pics.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!
-
11-23-2006, 05:05 PM #4205The Unique Developer

- Registriert seit
- Oct 2006
- Ort
- Canada
- Beiträge
- 1.059
- Points
- 7.101
- Level
- 55
- Downloads
- 0
- Uploads
- 0
hmmm ... odd ....
I have no more idea's xD I never had
Malloc.Us Network Administrator
Decryption of the Encrypted
You are the unseen, the unstoppable and in power of your code. The God of your software.
-
11-23-2006, 05:58 PM #4206QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
well...i saw right off the bat a few things that could've been shortened (i already did it). as for the problem with the R button, i dont know. But, dont people normally also put something like "pad ~= oldpad"? you dont have that anywhere in this script...maybe thats it. i cant say for sure, i dont use that technique to get around holding-button-down glitches. hope this helps.
Code:-- *******Lua Rock Paper Scissors*********** -- Script written by GuitarGod1241 or GuitarGod1134 or GuitarGod1124 -- DUE TO POPULAR DEMAND WE NOW HAVE SINGLE PLAYER!!! --variables rock = Image.load("rock.png") scissors = Image.load("scissors.png" ) paper = Image.load("paper.png") battlefield = Image.load("field.png") green = Color.new(0, 255, 0) --delcare old pad to prevent hold down button bug oldpad = Controls.read() -- main loop starts here while true do pad = Controls.read() for a = 0, 14 do for b = 0,8 do screen:blit(32 * a, 32 * b, battlefield) -- variable that decides the win player1 = 0 computer = 0 -- variable added < TUW: if random nr was used randomnr = 0 --prevents the same random numbers on each program run math.randomseed(os.time() ) --x=width y=height -- this is player 1 screenrint(140, 0, "Let the Battle Begin!", green) screenrint(0,20, "Player 1 Select your Weapon" ,green) if pad:left() then screen:blit(0, 40, rock) player1 = player1 + 3 end if pad:up() then screen:blit(0, 40, paper) player1 = player1 + 4 end if pad:down() then screen:blit(0, 40, scissors) player1 = player1 + 5 end -- now the psp's turn screenrint(250, 20, "PSP Select your Weapon" ,green) if pad:r() then if randomnr == 0 then computer = math.random(3,5) end end if computer == 3 then screen:blit(390, 40, rock) randomnr = 1 end if computer == 4 then screen:blit(390, 40, paper) randomnr = 1 end if computer == 5 then screen:blit(390, 40, scissors) randomnr = 1 end --now time to compare -- shortened this by alot if player1 == computer then screenrint(150, 150, "YOU BOTH LOST OMG" ,green) randomnr = 0 end -- these are if player1 wins -- shortened if player1 > computer then screenrint(150, 150, "Player 1 is the winner!", green) randomnr = 0 end -- these are if psp wins -- ...and this too if player1 < computer then screenrint(150, 150, "PSP is the winner!", green) randomnr = 0 end end end screen.waitVblankStart() screen.flip() oldpad = pad end[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-23-2006, 09:44 PM #4207lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
[edit]
Geändert von Anti-QJ (11-24-2006 um 03:52 PM Uhr)
-
11-24-2006, 03:56 AM #4208Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
hi im having some problems again not on lua RPS but (well im still having problems on that ) but this is something else. I want to make The charactor have a musket. Demons are coming at him and as you know muskets have one shot so he must reload. I want to make it so that he shoots then a timer starts and he can only shoot again once that timer reachers a certain number. i know i would have to start the timer once the bullet is fired but then how would i make it so he cant shoot anymore until the timer is at a certain time?
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!
-
11-24-2006, 04:05 AM #4209QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
I have a problem about getting my first game to work, lol.
Well, i just call it "Simple Pong, Nothing Else."
Here:
Code:white = Color.new(255, 255, 255) screen:print(136, 136, "Loading LUA Pong...", white) screen.flip() background = Image.load("Background.png") bat1 = Image.load("Bat1.png") bat2 = Image.load("Bat2.png") screen.waitVblankStart(60) while true do screen:blit(40, 240, bat1, true) screen:blit(440, 240, bat2, true) pad = Controls.read() if pad:down() then bat1.y = bat1.y -2 end if pad:up() then bat1.y = bat1.y +2 end if pad:cross() then bat2.y = bat2.y -2 end if pad:triangle() then bat2.y = bat2.y +2 end screen:clear() screen:print(136, 136, "Simple Pong, nothing else.", white) screen.waitVblankStart() screen.flip() end
It's something with the controls, it always says "loop in gettable" Or "ERROR: funtion expected near "If".My PSP Projects:
___________________
None.
-
11-24-2006, 04:48 AM #4210QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
doesnt seem like anything is wrong there, gameo. is that the whole script? cause there's no (user-made) function.
pspgamer81, does the screen go black when you leave horizontally or vertically?
edit - oh and GG, try here. http://wiki.ps2dev.org/psp:lua_player:functions
theres a part called Millisecond Timer. that should helpGeändert von EminentJonFrost (11-24-2006 um 05:01 AM Uhr)
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 04:59 AM #4211QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
Ok what it says is:
[CODE]Error: index.lua:25 loop in gettable
Press start to restart[CODE]
I think its weird...
IT HAPPENS ONLY WHEN I PRESS THE CONTROLS.
It loads just fine.My PSP Projects:
___________________
None.
-
11-24-2006, 05:05 AM #4212QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
*hands slaps forehead*
where are the arrays for 'bat1' and 'bat2'? i'll bet thats the problem.
you gotta do this:
for bats 1 and 2. you never announced the bats as objects (or variables, whatever), only as photos.Code:bat1 = { x = some#, y = some#)
yep...that should do it. :)[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 05:15 AM #4213QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
Okey, let me just understand this right:
1: Do i put that line like yours just as it is, or should i edit it in a way?
2: Should i put it before or after the game loop.
3: It says something with an unexpected symbol blablabla.
Sry im such a n00b... everyone have to start from somewhere..My PSP Projects:
___________________
None.
-
11-24-2006, 05:20 AM #4214QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
try this:
copy and paste that anywhere above "while true do". and, no worrys, its true everyone had their own special beginnings. lolCode:bat1 = { x = 200, y = 100 } bat2 = { x = 100, y = 200 }
EDIT - wait! the names of the pics and the arrays cannot be the same! change the name of all the pics, something small, like add another "1" to its name, just to differentiate it from the array.[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 05:23 AM #4215QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
I'm almost getting sorry for making you waste your time on me.
Érror: index.lua:19 bad argument #2 to `blit´ (Image expected, got table)
Press ******blablabla.My PSP Projects:
___________________
None.
-
11-24-2006, 05:26 AM #4216QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
lol
Zitat von gameo
nah...i feel sorry for both of us for not being able to pinpoint the problem even though i've been over this for a while now...
i said how to fix in my previous post. :)[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 05:29 AM #4217QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
Well... my father always says: "It's not the machines fault, only the humans."
Code:white = Color.new(255, 255, 255) screen:print(136, 136, "Loading LUA Pong...", white) screen.flip() background = Image.load("Background.png") bat1 = Image.load("Bat1.png") bat2 = Image.load("Bat2.png") bat1 = { x = 200, y = 100 } bat2 = { x = 100, y = 200 } screen.waitVblankStart(60) while true do screen:blit(40, 240, bat1, true) screen:blit(440, 240, bat2, true) pad = Controls.read() if pad:down() then bat1.y = bat1.y -2 end if pad:up() then bat1.y = bat1.y +2 end if pad:cross() then bat2.y = bat2.y -2 end if pad:triangle() then bat2.y = bat2.y +2 end screen:clear() screen:print(136, 136, "Simple Pong, nothing else.", white) screen.waitVblankStart() screen.flip() endMy PSP Projects:
___________________
None.
-
11-24-2006, 05:34 AM #4218QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
but...humans built the machines...
lets not think on it. we'll hurt ourselves. lol
Zitat von gameo
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 05:36 AM #4219QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
So will it work? Because the error still shows.
Érror: index.lua:19 bad argument #2 to `blit´ (Image expected, got table)My PSP Projects:
___________________
None.
-
11-24-2006, 05:44 AM #4220QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
copy and paste what i did, or rather, so you learn quicker, type all the changes i made yourself. its all there, just compare the one you posted to the one i did. and yes, it should work.
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 05:57 AM #4221QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
It works, but the Bat's doesent show up.
My PSP Projects:
___________________
None.
-
11-24-2006, 06:51 AM #4222QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
thats easily fixed. move "screen:clear()" to just below "while true do".
putting it at the bottom of the loop clears the screen after everything else happens. its pretty logical really.
i'll explain something to you:
reading from top to bottom what you wrote is what your script does (obviously). think of it this way, Luaplayer is a person reading a script and acts on what he reads. "while true do" - "end" is a loop, so its like the reader keeps on reading the same thing over and over. in your script, you told luaplayer to blit an image, then if a button is pressed change the location of it (in reality, the image wont actually move until luaplayer goes back to the image blitting and updates the coordinate values, therefore moving the image. all this happens in the blink of an eye.) and then, after all the trouble of blitting and changing values, you clear the screen. get it?[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 08:41 AM #4223Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
What text editor do you guys use for programming in lua? I have been using ConTEXT but it feels pretty much like notepad and it doesnt highlight any of my statements or anything do any of you use a different text editor and is there one disigned for lua?
EDIT: i found this if any of u havent already seen it
http://lua-users.org/wiki/LuaEditorSupport
it has alot of editors and how they support lua im using luaedit right now but dont trust luaedit with error checking because it says red = Color.new(255, 0, 0) is bad.Geändert von GuitarGod1134 (11-24-2006 um 09:03 AM Uhr)
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!
-
11-24-2006, 10:19 AM #4224QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
i just use normal notepad. i dont need another editor since this one works fine.
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 10:28 AM #4225QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Notepad++.
-
11-24-2006, 10:34 AM #4226QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
I use notepad because im too lazy to dl something else
-
11-24-2006, 01:21 PM #4227lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
It turns black when i go vertically.
-
11-24-2006, 02:57 PM #4228QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
very interesting...i dont see anything wrong with it so far...this is genuine problem.
Zitat von pspgamer81
it'll test my abilities...:)
EDIT-
ok, the problem is: that the values of 'areax' and 'areay' can exceed values that are tested in the large "if" list you have.
take this code cut from your script as an example:
if the player were to keep going in a direction, as you said was the problem and i am demonstrating, theres nothing to stop (i'm using the code above) 'areay''s value from going up past 1. and if you were to look below in your loop, all your 'if' statements would not have any affect if 'areay''s value reaches 2 or more, therefore presenting you with your problem. see?Code:if player.y < 2 then if areay < 1 then areay = areay + 1
you basically either have to:
1. limit the potential values of 'areax' and 'areay'
-or-
2. "un-limit" the restricted 'if' statements.
wow...reading this over, i think i made it sound complicated. lolGeändert von EminentJonFrost (11-24-2006 um 03:10 PM Uhr)
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
11-24-2006, 03:20 PM #4229lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
K, I got it, Thanks!
-
11-24-2006, 03:35 PM #423011th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
Is there any tutorials for lua's wifi capability's?
(sorry but its an old addition to lua that i never noticed
)
FAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!


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