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; Big problem. It won't work. here is post of source: Code: -- ******* RODM: Run or Die Mouse ******** -- ...
-
07-22-2007, 09:30 PM #7771
Big problem. It won't work. here is post of source:
and here is post of error:Code:-- ******* RODM: Run or Die Mouse ******** -- This was Made by Mraellis And GamefreQ for your learning purposes. Please do not steal our work, but -- give us credit instead, and ask for our permission to use this. dofile(Color.lua) --This directs to the color file for the colors of the text -- Images Bat = Image.load("Images/bat.png") grass = Image.load("Images/grass.png") Mouse7 = Image.load("Images/Mouse_UL.png") Mouse9 = Image.load("Images/Mouse_UR.png") Mouse8 = Image.load("Images/Mouse_U.png") Mouse2 = Image.load("Images/Mouse_D.png") Mouse4 = Image.load("Images/Mouse_L.png") Mouse6 = Image.load("Images/Mouse_R.png") Mouse1 = Image.load("Images/Mouse_DL.png") Mouse3 = Image.load("Images/Mouse_DR.png") screenwidth = 480 - player:width() -- These are so you cannot move your character off the screen screenheight = 272 - player:width() -- because the PSP screen has 480 x 272 pixels :) -- Tables (enemies and Players are here) Player = { } Player[1] = { x = 200, y = 50 } -- Sounds Bat = Sound.load("Sounds/Bat.wav",false) Mouse = Sound.load("Sounds/Mouse.wav",false) Boom = Sound.load("Sounds/Boom.wav",false) Chomp = Sound.load("Sounds/Chomp.wav",false) heavyweight = Sound.load("Sounds/heavyweight.wav",false) Shotgun = Sound.load("Sounds/Shotgun.wav",false) Squash = Sound.load("Sounds/Squash.wav",false) Levelstart = Sound.load("Sounds/Levelstart.wav",flase) -- Vars Win = screen:print(200, 100, "Well Done, You Won!", red) Lose = screen:print(200, 100, "Sorry, You Lost!", blue) Score = screen:print(200, 100, "Your score is", red) MadeBy = screen:print(200, 100, "This Game was made by Mraellis And GamefreQ", blue) -- Main loop while true do pad = Controls.read() screen:clear() for a = 0, 14 do for b = 0,8 do screen:blit(32 * a, 32 * b, grass) end end screen:blit(Player[1].x,Player[1].y,Mouse8) if pad:left() and Player[1].x > 0 then Player[1].x = Player[1].x - 5 end if pad:right() and Player[1].x < screenwidth then Player[1].x = Player[1].x + 5 end if pad:up() and Player[1].y > 0 then Player[1].y = Player[1].y - 5 end if pad:down() and Player[1].y < screenheight then Player[1].y = Player[1].y + 5 end screen.waitVblankStart() screen.flip() end
I don't understand. I have all of the files in the correct place (It is not done yet, no where near completion, but I just wanted to test it. but apparently notCode:Error: SCRIPT.LUA:19: attempt to index global 'player' (a nil value) Press start to restart
-
07-22-2007, 09:55 PM #7772QJ Gamer Bronze
- Registriert seit
- Dec 2006
- Beiträge
- 654
- Points
- 5.934
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Aiight i think i might start coding lua then...if so il hafta save up for a laptop to code on lol
-
07-22-2007, 10:03 PM #7773
I was about 2g2 bed when I say that my thread was bumped up so I got a gleam of hope only to find this LOL no problemo though it's all cool but you can code with notepad on anything so I don't think you NEED to get a laptop jsut to code well gl
Zitat von _-Tiger-_
-
07-22-2007, 10:27 PM #7774QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
If you read the error that luaplayer gave you, you would see that on line 19 and 20 a variable called 'player' is used, yet it is not defined any where in the script. Remember, lua is case sensitive. 'Player' is not the same as 'player'. It is also linear, so things are interpreted from top to bottom.
Zitat von Gam3freQ
Code:-- Test Lua Application T_Player[1].x = 10; -- Undefined table T_Player = {} -- Table defined after table-menu
-
07-23-2007, 07:49 AM #7775
ok so also if I fix this then will my Player width and height be the same as Mouse8's width and height? (look at the code for Mouse8) Thank you for all of that
Zitat von _dysfunctional
I also got an error on line 35: error loading sound, so I saw that it sad flase instead of false, so I fixed it, and I got the same error
-= Double Post =-
ZOMG! I downloaded colors.lua from evilmana.com and realized that there are NO SPACES! If there arn't any spaces then that means they won't work! Also they don't work without the spaces I tried! oh no! is there an alternate download with the spaces because that's a good 1000 colors that are now goin to wasteGeändert von Gam3freQ (07-23-2007 um 08:47 AM Uhr) Grund: Automerged Doublepost
-
07-23-2007, 09:59 AM #7776QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 758
- Points
- 8.665
- Level
- 62
- Downloads
- 0
- Uploads
- 0
yes it will....
the only thing spaces do are make your code look nicer
-
07-23-2007, 10:49 AM #7777
no it gave me error dude
Zitat von michaelp
GhostWhite=Color.new(248, 248,255)
does not work BUT
GhostWhite = Color.new(248, 248, 255)
works perfectly and does NOT display error message so I said screw it and spaced out the ones I wanted to use and deleted the rest, and the program works, but I want to change the controls. I do NOT want it to be, up goes up, right goes right, left goes left, down goes down, etc. I want UP on the dpad to move your character whatever direction it is facing, and then left and right to turn or change the direction you're facing like in the flash game.
-
07-23-2007, 11:08 AM #7778QJ Gamer Green
- Registriert seit
- Sep 2006
- Ort
- Cape Town, South Africa
- Beiträge
- 714
- Points
- 5.795
- Level
- 49
- Downloads
- 0
- Uploads
- 0
You could have just used search-replace to fix the spaces...
-
07-23-2007, 11:21 AM #7779QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 758
- Points
- 8.665
- Level
- 62
- Downloads
- 0
- Uploads
- 0
I'm having a bit of a problem with an image.
The image just looks like a button. (Sort of, not from the way I made it)
It has a black background, but when I blit it to the screen(without a background, or black) the background will show up as grey, not black.
I've tried using the True and false value's for the alpha, but same thing.
Anyone know why?
edit: nvm, fixedGeändert von michaelp (07-23-2007 um 01:14 PM Uhr)
-
07-23-2007, 05:18 PM #7780
i've been trying to find a way around this since saturday and i finally found one! yes its true that a screenshot will capture the scaled image but it would take way too long to write to the ms. remember the weird things that were happening with fillRect and print? well those weird things helped me to figure it out. when it blits from the screen, all it sees is alpha=0. when you fillRect or print before Gu.blit, it sees this as alpha=255. we can use this to our advantage to create masks! so in short, the quick fix is:
Zitat von Merick
before the call to Gu.start3d()Code:screen:fillRect(x,y,image:width(), image:height())
-
07-24-2007, 12:00 AM #7781
tell me how
Zitat von coolguy5678
-
07-24-2007, 12:09 AM #7782QJ Gamer Bronze
- Registriert seit
- Dec 2006
- Beiträge
- 654
- Points
- 5.934
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Hows the game going? Im definatly gonna start learning Lua. I think ill start tomorrow, after i workout....gotta get ready for football lol
-
07-24-2007, 02:51 AM #7783No longer a community member.
- Registriert seit
- Sep 2006
- Ort
- Over there.
- Beiträge
- 666
- Points
- 6.420
- Level
- 52
- Downloads
- 0
- Uploads
- 0
Ok well i am not normally a Lua dev i would rather work with C/C++ any day but i have to work in Lua for a little while (if you are active at the luaplayer forums you would know what i am working on). Ok well i have setup the GU in the luaplayer and have it all working but i am wanting to run opacity on my objects so natuarally i enable GU_BLEND and run a normal Gu BlendFunc with (GU_ADD GU_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA) but my draw back is with the Luaplayer Color object i believe. I think that it does not support an alpha value. please correct me if im wrong but how would i go about having an Color object of an object drawn at ~50% opacity
EDIT====
MY BAD I OVER LOOKED IT ON THE DOCUMENTATIONS
-
07-24-2007, 06:28 AM #7784QJ Gamer Green
- Registriert seit
- Sep 2006
- Ort
- Cape Town, South Africa
- Beiträge
- 714
- Points
- 5.795
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Search-replace (you do know how to use search-replace, right?) "=" with " = " (without the quotes).
Zitat von Gam3freQ
-
07-24-2007, 10:42 AM #7785Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
ok guys... we've been doing some work on it and we've hit a problem. the bat doesn't appear and u can go offscreen.
can someone help plz.Code:-- ******* RODM: Run or Die Mouse ******** -- This was Made by Mraellis And GamefreQ for your learning purposes. Please do not steal our work, but -- give us credit instead, and ask for our permission to use this. -- Colors cyan = Color.new(0, 255, 255) red1 = Color.new(255, 0, 0) salmon1 = Color.new(255, 140, 105) burlywood4 = Color.new(139, 115, 85) math.randomseed(os.time()) --/// prevent same random numbers from occuring each run of the game/// -- Images Bat = Image.load ("Images/bat.png") grass = Image.load("Images/Grass.png") Mouse7 = Image.load("Images/Mouse_UL.png") Mouse9 = Image.load("Images/Mouse_UR.png") Mouse8 = Image.load("Images/Mouse_U.png") Mouse2 = Image.load("Images/Mouse_D.png") Mouse4 = Image.load("Images/Mouse_L.png") Mouse6 = Image.load("Images/Mouse_R.png") Mouse1 = Image.load("Images/Mouse_DL.png") Mouse3 = Image.load("Images/Mouse_DR.png") -- Sounds Bat = Sound.load("Sounds/Bat.wav",false) Mouse = Sound.load("Sounds/Mouse.wav",false) Boom = Sound.load("Sounds/Boom.wav",false) Chomp = Sound.load("Sounds/Chomp.wav",false) heavyweight = Sound.load("Sounds/heavyweight.wav",false) Shotgun = Sound.load("Sounds/Shotgun.wav",false) Squash = Sound.load("Sounds/Squash.wav",false) Levelstart = Sound.load("Sounds/Levelstart.wav",false) -- Vars Win = screen:print(200, 100, "Well Done, You Won!", red1) Lose = screen:print(200, 100, "Sorry, You Lost!", cyan) Score = screen:print(200, 100, "Your score is", salmon1) MadeBy = screen:print(200, 100, "This Game was made by Mraellis And GamefreQ", burlywood4) -- Tables (enemies and Players are here) Player = { } Player = { x = 200, y = 50 } Enemy = { } Enemy = { x = 50, y = 50 } screenwidth = 480 - Mouse8:width() -- These are so you cannot move your character off the screen screenheight = 272 - Mouse8:height() -- because the PSP screen has 480 x 272 pixels :) function movePlayer() --/// function to move our player when directionals are pressed/// pad = Controls.read() if pad:left() then Player.x = Player.x - 5 end if pad:right() then Player.x = Player.x + 5 end if pad:up() then Player.y = Player.y - 5 end if pad:down() then Player.y = Player.y + 5 end end function chasePlayer() --/ function to make the enemy chase the player/ stallchase = math.random(2) if stallchase == 1 then if Enemy.x > Player.x then Enemy.x = Enemy.x - 2 elseif Enemy.x < Player.x then Enemy.x = Enemy.x + 2 end end stallchase = math.random(2) if stallchase == 1 then if Enemy.y > Player.y then Enemy.y = Enemy.y - 2 elseif Enemy.y < Player.y then Enemy.y = Enemy.y + 2 end end end --///end the function/// -- Main loop while true do screen:clear() for a = 0, 14 do for b = 0,8 do screen:blit(32 * a, 32 * b, grass) end end screen:blit(Player.x,Player.y,Mouse8) screen:blit(Enemy.x,Enemy.y,Bat) movePlayer() --///call movePlayer function/// chasePlayer() --///call chasePlayer function//// screen.waitVblankStart() screen.flip() end
-
07-24-2007, 10:43 AM #7786Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
ok guys... we've been doing some work on a game and we've hit a problem. the bat doesn't appear and u can go offscreen.
can someone help plz.Code:-- ******* RODM: Run or Die Mouse ******** -- This was Made by Mraellis And GamefreQ for your learning purposes. Please do not steal our work, but -- give us credit instead, and ask for our permission to use this. -- Colors cyan = Color.new(0, 255, 255) red1 = Color.new(255, 0, 0) salmon1 = Color.new(255, 140, 105) burlywood4 = Color.new(139, 115, 85) math.randomseed(os.time()) --/// prevent same random numbers from occuring each run of the game/// -- Images Bat = Image.load ("Images/bat.png") grass = Image.load("Images/Grass.png") Mouse7 = Image.load("Images/Mouse_UL.png") Mouse9 = Image.load("Images/Mouse_UR.png") Mouse8 = Image.load("Images/Mouse_U.png") Mouse2 = Image.load("Images/Mouse_D.png") Mouse4 = Image.load("Images/Mouse_L.png") Mouse6 = Image.load("Images/Mouse_R.png") Mouse1 = Image.load("Images/Mouse_DL.png") Mouse3 = Image.load("Images/Mouse_DR.png") -- Sounds Bat = Sound.load("Sounds/Bat.wav",false) Mouse = Sound.load("Sounds/Mouse.wav",false) Boom = Sound.load("Sounds/Boom.wav",false) Chomp = Sound.load("Sounds/Chomp.wav",false) heavyweight = Sound.load("Sounds/heavyweight.wav",false) Shotgun = Sound.load("Sounds/Shotgun.wav",false) Squash = Sound.load("Sounds/Squash.wav",false) Levelstart = Sound.load("Sounds/Levelstart.wav",false) -- Vars Win = screen:print(200, 100, "Well Done, You Won!", red1) Lose = screen:print(200, 100, "Sorry, You Lost!", cyan) Score = screen:print(200, 100, "Your score is", salmon1) MadeBy = screen:print(200, 100, "This Game was made by Mraellis And GamefreQ", burlywood4) -- Tables (enemies and Players are here) Player = { } Player = { x = 200, y = 50 } Enemy = { } Enemy = { x = 50, y = 50 } screenwidth = 480 - Mouse8:width() -- These are so you cannot move your character off the screen screenheight = 272 - Mouse8:height() -- because the PSP screen has 480 x 272 pixels :) function movePlayer() --/// function to move our player when directionals are pressed/// pad = Controls.read() if pad:left() then Player.x = Player.x - 5 end if pad:right() then Player.x = Player.x + 5 end if pad:up() then Player.y = Player.y - 5 end if pad:down() then Player.y = Player.y + 5 end end function chasePlayer() --/ function to make the enemy chase the player/ stallchase = math.random(2) if stallchase == 1 then if Enemy.x > Player.x then Enemy.x = Enemy.x - 2 elseif Enemy.x < Player.x then Enemy.x = Enemy.x + 2 end end stallchase = math.random(2) if stallchase == 1 then if Enemy.y > Player.y then Enemy.y = Enemy.y - 2 elseif Enemy.y < Player.y then Enemy.y = Enemy.y + 2 end end end --///end the function/// -- Main loop while true do screen:clear() for a = 0, 14 do for b = 0,8 do screen:blit(32 * a, 32 * b, grass) end end screen:blit(Player.x,Player.y,Mouse8) screen:blit(Enemy.x,Enemy.y,Bat) movePlayer() --///call movePlayer function/// chasePlayer() --///call chasePlayer function//// screen.waitVblankStart() screen.flip() end
-
07-24-2007, 10:50 AM #7787QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
because you have a bat image, and a bat sound that are named the same
-
07-24-2007, 10:50 AM #7788QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 758
- Points
- 8.665
- Level
- 62
- Downloads
- 0
- Uploads
- 0
you never put in a function or anything so that the bat/mouse can't go offscreen
also, with all those sounds and pictures, don't you get some sort of memory error, or the game is a bit slow?
also, a suggestion for your "movePlayer" function: make it less than + or - 5, that (i think) will be quite choppy
Your variables should be:
1. functions
or
2. just words
I'm pretty sure you can't be a built-in luaplayer function in a variable
just put the words you want in, and when you want to print it to the screen, do this:
screen
rint(x, y, variable, colour)
-
07-24-2007, 11:21 AM #7789
DONT ARGUE. it doesn't work i have tred it OK?! also look at the post above and help us with that source code somebody, and I do not know how to do "find and replace" or w/e
Zitat von michaelp
-
07-24-2007, 11:30 AM #7790Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
i'll explain f & r later
-
07-24-2007, 11:57 AM #7791
oh ok
Zitat von mraellis
:Punk:
-
07-24-2007, 12:46 PM #7792QJ Gamer Bronze
- Registriert seit
- Dec 2006
- Beiträge
- 654
- Points
- 5.934
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Hey does anyone know how to edit my code while having it on my psp w/o exiting Luaplayer? I've tried this
System.usbDiskModeActivat e()
But i cant edit my code... any help?
Edit: Ok im following tutorial #2 from psp-programming.com and when i try it i says
Error SCRPIT.LUA:130: /=/ expected near /pad/. Any help?Geändert von _-Tiger-_ (07-24-2007 um 01:13 PM Uhr)
-
07-24-2007, 01:39 PM #7793
look at line 130 in your code
Zitat von _-Tiger-_
-
07-24-2007, 01:46 PM #7794QJ Gamer Bronze
- Registriert seit
- Dec 2006
- Beiträge
- 654
- Points
- 5.934
- Level
- 49
- Downloads
- 0
- Uploads
- 0
I did i tried to fix it about 10 times and still nothing... lol
-
07-24-2007, 02:04 PM #7795Banned from QJ for LIFE
- Registriert seit
- Jul 2006
- Beiträge
- 1.557
- Points
- 10.957
- Level
- 69
- Downloads
- 0
- Uploads
- 0
post the full code and we can see where the problem is
-
07-24-2007, 03:52 PM #7796
Thanks for the tip, I was wondering about that.
Zitat von Da_MerV
Also, here's Gu.blit2:
it's basically the same as the first Gu.blit, except this version can draw parts of the image:Code:function Gu.blit2(x, y, image, img_x, img_y, width, height, scale, flip) if not scale or type(scale) == "string" then flip = scale scale = 1 end if flip then if flip == "H" then x_start = img_x + width y_start = img_y x_end = img_x y_end = img_y + height elseif flip == "V" then x_start = img_x y_start = img_y + height x_end = img_x + width y_end = img_y elseif flip == "HV" then x_start = img_x + width y_start = img_y + height x_end = img_x y_end = img_y end else x_start = img_x y_start = img_y x_end = img_x + width y_end = img_y + height end width = (width*scale)+y or (image:width()*scale)+x height = (height*scale)+y or (image:height()*scale)+y temp = { {x_start, y_start, x, y, 0}, {x_end, y_end, width, height, 0} } Gu.enable(Gu.TEXTURE_2D) Gu.texImage(image) Gum.drawArray(Gu.SPRITES, Gu.TEXTURE_32BITF+Gu.VERTEX_32BITF+Gu.TRANSFORM_2D, temp) end
Gu.blit2(10, 10, image, 10, 10, 40, 90, 1.5, "HV")
-
07-24-2007, 03:57 PM #7797QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
are you sure you completely exited your app or game and were in Lowser when trying to edit your code?
Zitat von _-Tiger-_
-
07-24-2007, 03:59 PM #7798lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Once you edit your going to need to quit your game and restart lowser.
-
07-24-2007, 04:05 PM #7799QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
you dont need to restart lowser, just exit the app then restart the app after editing it.
Zitat von Anti-QuickJay
-
07-24-2007, 04:23 PM #7800lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Thats if you include a exit call.


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