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; Code: System.usbDiskModeActivate() blue = Color.new(0,0,255) green = Color.new(0,255,0) red = Color.new(255, 0, 0) player = {x = 1, y = ...
-
12-09-2006, 04:26 PM #4591QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- BEHIND YOU!!
- Beiträge
- 1.061
- Points
- 6.453
- Level
- 52
- Downloads
- 0
- Uploads
- 0
That is my script and I get error. Index.lua 50:unexpected symbol near "=".Code:System.usbDiskModeActivate() blue = Color.new(0,0,255) green = Color.new(0,255,0) red = Color.new(255, 0, 0) player = {x = 1, y = 1, image = Image.createEmpty(32,32)} enemy = {x = 448, y = 240, image = Image.createEmpty(5,5)} player.image:clear(blue) enemyimg = enemy.image:clear(green) function movement() if pad:up() then player.y = player.y - 5 end if pad:down() then player.y = player.y + 5 end if pad:right() then player.x = player.x + 5 end if pad:left() then player.x = player.x - 5 end end function AI() follow = math.random(3) if follow == 1 then if player.x > enemy.x then enemy.x = enemy.x + 10 end if player.x < enemy.x then enemy.x = enemy.x - 10 end if player.y > enemy.y then enemy.y = enemy.y + 10 end if player.y < enemy.y then enemy.y = enemy.y - 10 end end end function collision() if enemy.y > player.y + player:height() and enemy.y + enemy:height() < player.y and enemy.x < player.x + player:width() and enemy.x + enemy:width() > player.x then enemy.x = oldenemyx enemy.y = oldenemyy player.x = oldplayerx player.y = oldplayery player.image:width() = player.image:width() - 1 player.image:height() = player.image:height() - 1 end end function endofgame() if player:width() = 0 and player:height() = 0 then screen:clear() screen:print(194, 136, "Game Over", red) end end while true do oldenemyy = enemy.y oldenemyx = enemy.x playery = player.y playerx = player.x screen:clear() pad = Controls.read() screen:blit(player.x, player.y, player.image) screen:blit(enemy.x, enemy.y, enemy.image) movement() AI() collision() endofgame() screen.flip() screen.waitVblankStart() end
Can someone help me I am just trying out to get my AI down and collision and a bunch of stuff working together. I don't even see an error at all.
[url=http://xs.to][img]http://xs313.xs.to/xs313/07106/wmnp8z.png[/img][/url]
What's a recovery.elf
[QUOTE=iball]
He's the one that fixes Santa's sleigh when it breaks down[/QUOTE]
[QUOTE=Deturbanator]why are we allowed to see the whole flesh and being of the boob but we MUST blur out the tit?[/QUOTE]
[PRE][B]sg57 i love you for turning on the light of homebrew when i was in the darkness of sony[/b][/pre]
-
12-09-2006, 04:40 PM #4592QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
try changing height and width to number values.
Zitat von psp11
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-09-2006, 04:46 PM #4593QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
No.
if player:width() = 0 and player:height() = 0 then
needs to be
if player:width() == 0 and player:height() == 0 then
-
12-09-2006, 04:50 PM #4594QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- BEHIND YOU!!
- Beiträge
- 1.061
- Points
- 6.453
- Level
- 52
- Downloads
- 0
- Uploads
- 0
Yah, I did screw up there but I still get the same error. I think it is before that.
Zitat von -TacticalPaper-
[url=http://xs.to][img]http://xs313.xs.to/xs313/07106/wmnp8z.png[/img][/url]
What's a recovery.elf
[QUOTE=iball]
He's the one that fixes Santa's sleigh when it breaks down[/QUOTE]
[QUOTE=Deturbanator]why are we allowed to see the whole flesh and being of the boob but we MUST blur out the tit?[/QUOTE]
[PRE][B]sg57 i love you for turning on the light of homebrew when i was in the darkness of sony[/b][/pre]
-
12-09-2006, 05:21 PM #4595QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
To use the analog stick, refer to the lua snippets thread which tells you how.
-
12-09-2006, 05:28 PM #4596QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- BEHIND YOU!!
- Beiträge
- 1.061
- Points
- 6.453
- Level
- 52
- Downloads
- 0
- Uploads
- 0
I think I know the problem. This is just a guess. The width and height can not be change in my example. I think that they just return numbers and that they can't be changed. I am going to try it out right now.
[url=http://xs.to][img]http://xs313.xs.to/xs313/07106/wmnp8z.png[/img][/url]
What's a recovery.elf
[QUOTE=iball]
He's the one that fixes Santa's sleigh when it breaks down[/QUOTE]
[QUOTE=Deturbanator]why are we allowed to see the whole flesh and being of the boob but we MUST blur out the tit?[/QUOTE]
[PRE][B]sg57 i love you for turning on the light of homebrew when i was in the darkness of sony[/b][/pre]
-
12-09-2006, 06:54 PM #4597
if you don't look at the snippet, the analog stick's values can be stored into two variables, which show the x and y of the analog stick.
Zitat von EminentJonFrost
for example,
dx = pad:analogX()
dy = pad:analogY()
if you move it left, the value of dx will equal -127.
if you move right, the value of dx will equal 128
up, and dy equals -127
down, and dy equals 128
-
12-09-2006, 06:58 PM #4598QJ Gamer Silver
- Registriert seit
- Oct 2006
- Ort
- 貴方
- Beiträge
- 1.159
- Points
- 7.371
- Level
- 57
- Downloads
- 0
- Uploads
- 0
im trying out htis menu style from evilmana
Zitat von code
adn i keep getting an error saying
table index is nil
-
12-09-2006, 07:00 PM #4599lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Why not use an easier menu code? If you want, Their is easier ones to learn on evilmana.
-
12-09-2006, 07:08 PM #4600QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Neither currselect or entries have been given a value by this point in the code so what actually happens is:Code:menu[currselect] =1 menu[entries]=table.getn(menu) - 2
Causing the error.Code:menu[nil] =1 menu[nil]=table.getn(menu) - 2
-
12-09-2006, 08:19 PM #4601No longer a community member.
- Registriert seit
- Jan 2006
- Ort
- jkl
- Beiträge
- 82
- Points
- 6.948
- Level
- 54
- Downloads
- 0
- Uploads
- 0
how do i disable the home button? i dont want that "do you want to quit the game?" screen to come up. i want nothing to happen when you push home. is it possible to do this in lua?
-
12-09-2006, 08:22 PM #4602QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Nope, the main system overrides anything lua tells it to do. You can use the home button but the home screen will still come up.
-
12-09-2006, 08:32 PM #4603No longer a community member.
- Registriert seit
- Jan 2006
- Ort
- jkl
- Beiträge
- 82
- Points
- 6.948
- Level
- 54
- Downloads
- 0
- Uploads
- 0
ah damn
-
12-09-2006, 08:34 PM #4604QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Just do if pad:home() then os.exit() end
-
12-09-2006, 08:45 PM #4605No longer a community member.
- Registriert seit
- Jan 2006
- Ort
- jkl
- Beiträge
- 82
- Points
- 6.948
- Level
- 54
- Downloads
- 0
- Uploads
- 0
thanks, but ive already tried that, it makes the psp freeze in some weird way at the "do you want to quit this game?" screen
Zitat von -TacticalPaper-
-
12-09-2006, 09:05 PM #4606QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
ok then get the luaplayer mod and use System.quit()
-
12-09-2006, 10:04 PM #4607lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
I really dont like the way it exits, Cause if os.exit does not work, The you have to use systemquit but not everyone has the LUA Mod by cools, So i just put a break
-
12-09-2006, 10:10 PM #4608QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
But that doesnt work with home.
-
12-09-2006, 10:14 PM #4609lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Well, Then everyone should just get the LUA Player mod and then we can use systemquit!
-
12-10-2006, 03:55 AM #4610QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
Allright, ball moves at the start now, but when it hits the bat's, it just moves through them, and when it hits the end of the room, (which is, when its about to move out of the PSP screen) THEN it bounces away.
There must be something wrong with the collosion, here is the edited script:
white = Color.new(255, 255, 255)
screen
rint(136, 136, "Loading LUA Pong...", white)
screen.flip()
background = Image.load("Background.pn g")
bat1 = { x = 20, y = 100, }--Put the images in tables
bat2 = { x = 460, y = 100, }
ball = { x = 240, y = 146, mx = 1, my = 0 }--Put ball's image in it's table
--MX and MY are movemenyx and movementy. Start off mx at 1
screen.waitVblankStart(60 )
ball2 = Image.load("Ball.png")
bat11 = Image.load("bat1.png")
bat21 = Image.load("bat2.png")
while true do
screen:clear()
pad = Controls.read()
screen:blit(bat1.x, bat1.y, bat11, true)
screen:blit(bat2.x, bat2.y, bat21, true)
screen:blit(ball.x, ball.y, ball2, true)
--theres collision for bat1 now for bat 2
if ball.x == bat1.x and ball.y >= bat1.y and ball.x < (16*64) then
ball.mx = -ball.mx
end
--theres paddle 2's collision
if ball.x == bat2.x and ball.y >= bat2.y and ball.x < (16*64) then
ball.mx = -ball.mx --That should make it opposite of ball.mx, making it change directions.
end
--with ballmoving you had the idea but you need more
ball.x = ball.x + ball.mx --This makes the ball move to the right when ball.mx is positive, to the left when its negative.
--Then you can add some stuff dealing with my later. For making it move up//down, do something like
--ball.y = ball.y-ball.my
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
if pad:start() then
break
end
screen
rint(136, 136, "Welcome to the world of PPP.", white)
screen.waitVblankStart()
screen.flip()
endMy PSP Projects:
___________________
None.
-
12-10-2006, 10:05 AM #4611QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Bad check. If the ball is moving 3 pxs per frame in the X direction, how can you guarantee that the ball's X and bat's X will be in the exact same postion?Code:ball.x == bat2.x
-
12-10-2006, 02:06 PM #4612
Is it possible to drop the decimal in a number? Cause I can't seem to find any distinction between an integer and a double in LUA.
-
12-10-2006, 02:38 PM #4613QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Use the math library's floor or ceil function. It basically rounds down or up respectively.
http://lua-users.org/wiki/MathLibraryTutorial
You won't be able to tell the difference between an image, sound, integer, double, float, string, characters etc in Lua. It is just the way all scripting languages are for them to work as scripting languages.
-
12-10-2006, 03:14 PM #4614
Ok, I got it now, thanks! :)
-
12-10-2006, 03:50 PM #4615Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Does anyone know how to view an entire text file in lua. I know its possible because fosk and them have done it but i dont want to take any of thier code so does anyone know a tutorial that explains how to open text files and view them in lua?
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!
-
12-10-2006, 03:56 PM #4616lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
This is how you will view the entire txt file.Code:y = 10 file = io.open("testRead.txt","r") for line in file:lines() do y = y + 10 screen:print(100,y,line,white) end file:close()
You must declare the color "white"(You can use other colors too.)Geändert von Anti-QJ (12-10-2006 um 04:51 PM Uhr)
-
12-11-2006, 06:06 AM #4617QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Good job copying a snippet from evilmana

BTW that one has no scrolling.
-
12-11-2006, 06:14 AM #4618QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
... I guess im bothering you Tactical, maybe ill just wait for EminentJonFrost or eldiablov...
I'm just so sad... this is the first game i've ever made, (Exept if you count my windows clone on PC) so its not that i cant wait, its just that i h8 my self because i dont know a 0.000000001 part of lua. (Allright, maybe more) but still...
Whitehawk's tut didn't help a lot, only a little, and after the tut, it says:
"Congratulations, you are now a developer!"
|
|
Yeah right, i leaned how to blit an image, to write text on screen, and to play a sound. Thats great.My PSP Projects:
___________________
None.
-
12-11-2006, 06:16 AM #4619QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Actually you just arent quite being clear. What do you need help in right now? Also I recommend the tuts over at evilmana to learn more if youd like.
-
12-11-2006, 06:33 AM #4620Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Evilmana is noob friendly but it is so tempting to copy from


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