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; Okay, heres my code: Code: -- Alien Crosshair Game Screen -- Completally Coded by Mailas Gonrai -- Most errors fixed ...
-
08-22-2006, 09:38 PM #3301QJ Gamer Blue
- Registriert seit
- Aug 2006
- Beiträge
- 145
- Points
- 4.580
- Level
- 43
- Downloads
- 0
- Uploads
- 0
Okay, heres my code:
And my error:Code:-- Alien Crosshair Game Screen -- Completally Coded by Mailas Gonrai -- Most errors fixed by pjspeedy and yaustar -- Colors black = Color.new(0,0,0) blue = Color.new(191, 255, 195) yellow = Color.new(255, 255, 0, 200) green=Color.new(0,255,0, 195) white = Color.new(255,255,255) red = Color.new(255,69,0, 195) -- ETC Variables displayTime = math.random(2,5) counter = 0 speed = 1 offscreen = false pad = Controls.read() -- Functions function RandomPoint() end math.randomseed(os.time()) -- Images back = Image.load("./Images/back_game.png") crosshair = Image.load("./Images/crosshair.png") border = Image.load("./Images/game_border.png") alienimage = Image.load("./Images/alien.png") -- Music Music.playFile("./Music/grmus.it") -- Objects Player = {} Player.x = 208 Player.y = 112 alien = {} alien.x = math.random(1,3) alien.y = math.random (1,3) alien = {x = 0, y = 200} x_point = 23 y_point = 83 -- Health Equivelent Options Player.health = 100 healthbar = {} healthbar.y = 10 function movePlayer() if pad:left() then Player.x = Player.x - 4 end if pad:right() then Player.x = Player.x + 4 end if pad:down() then Player.y = Player.y + 4 end if pad:up() then Player.y = Player.y - 4 end end function perimeterSize() if Player.x > 480 - 64 then Player.x = 480 - 64 end if Player.x < 0 then Player.x = 0 end if Player.y > 272 - 64 then Player.y = 272 - 64 end if Player.y < 0 then Player.y = 0 end end -- THE LOOP!---------------------------------------------------------- while true do screen:clear() x_point = math.random(1,480) y_point = math.random(1,272) AlienMove() if alien.x < x_point then alien.x = alien.x + 2 end if alien.x > x_point then alien.x = alien.x - 2 end if alien.y < y_point then alien.y = alien.y + 2 end if alien.y < y_point then alien.y = alien.y - 2 end if alien.x == x_point and alien.y == y_point then RandomPoint() end counter = counter + 1 if counter >= displayTime then alien.x = math.random(1,3) alien.y = math.random (1,3) end if alien.x == 1 then alien.x = 224 alien.y = 182 end if alien.x == 2 then alien.x = 60 alien.y = 132 end if alien.x == 3 then alien.x = 404 alien.y = 154 end displayTime = math.random(500,2000) counter = 0 end screen:blit(0,0,back) screen:blit(alien.x,alien.y,alienimage) screen:blit(Player.x,Player.y,crosshair) screen:blit(0,0,border) screen:fillRect(320,240,Player.health,healthbar.y,green) screen:print(320,230,Player.health,blue) movePlayer() perimeterSize() alienscreenSize() if pad:l() then dofile("menu.lua") end screen.waitVblankStart() screen.flip() end
error: ./game.lua:159: /<eof>/ expected near /end/
-
08-22-2006, 10:51 PM #3302Developer

- Registriert seit
- Feb 2006
- Ort
- Tauranga, New Zealand
- Beiträge
- 355
- Points
- 5.162
- Level
- 46
- Downloads
- 0
- Uploads
- 0
The 'end' there is messing your script up. Remove it.displayTime = math.random(500,2000)
counter = 0
end
-
08-22-2006, 11:10 PM #3303words 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
Technically, its the end at the very end. Putting that mis-placed end where he does have it, closes the main loop, and until something breaks it, everything beyond it is useless... Removing hte ending end would also solve it ;) Just not how you would want it.

...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
-
08-23-2006, 01:10 AM #3304Developer

- Registriert seit
- Feb 2006
- Ort
- Tauranga, New Zealand
- Beiträge
- 355
- Points
- 5.162
- Level
- 46
- Downloads
- 0
- Uploads
- 0
Yes, I assumed he wanted a solution that would help him.
Zitat von SG57

-
08-23-2006, 01:12 AM #3305QJ Gamer Green
- Registriert seit
- Feb 2006
- Ort
- www.ultimatetalkforums.com Games, RPG, quickchat and more!
- Beiträge
- 532
- Points
- 8.746
- Level
- 62
- Downloads
- 0
- Uploads
- 0
Could anyone tell me how to make it so...in the end of your code when if it sais like..press x how do i make it read another text document...
so how do i make it read another text thing after i press abuton...code please =-)[CENTER][COLOR=black][COLOR=black][URL="http://forums.qj.net/f-psp-firmware-discussion-253/t-psp-firmware-30-get-it-58053.html"][COLOR=cyan]would you upgrade?[/COLOR][/URL] [/COLOR][FONT=Times New Roman][COLOR=navy][URL="http://www.mindistortion.net/iwantyoursoul/?i_am=altunozara"]OMG ITS REAL![/URL][/COLOR][/FONT][COLOR=black] [URL="http://forums.qj.net/showthread.php?t=61756&page=1&pp=10"][COLOR=lime]Sony vs Nintendo[/COLOR][/URL][/COLOR][/COLOR][/CENTER]
[CENTER] [/CENTER]
[CENTER][URL="http://www.ultimatetalkforums.com"][IMG]http://i94.photobucket.com/albums/l82/Altunozara/userbar2.jpg[/IMG][/URL][/CENTER]
[CENTER][SIZE=3]i [/SIZE][URL="http://forums.qj.net/www.gamingwell.com"][SIZE=3]wonder what could be under this hyperlink..hmm[/SIZE][/URL][/CENTER]
[CENTER][SIZE=3][COLOR=green][B][I]Maniakc is awsome!!![/I][/B][/COLOR][/SIZE][/CENTER]
[CENTER][FONT=Arial Black][SIZE=3][COLOR=#660099][I][U][URL="http://forums.qj.net/member.php?u=58299"]The Brain Pwns!!![/URL][/U][/I][/COLOR][/SIZE][/FONT][/CENTER]
[COLOR=sienna]Creator of:[/COLOR][URL="http://forums.qj.net/f-psp-development-forum-11/t-release-go-go-go-beta-66652.html"][COLOR=sienna]GO GO GO![/COLOR][/URL]
-
08-23-2006, 02:07 AM #3306words 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
dofile("path.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
-
08-23-2006, 06:11 AM #3307Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
@ Gonrai
If you wanted you could improve your code's efficiency by combining the functions movePlayer() and perimeterSize() like this:
It's a small improvement, sure, but if your project becomes large, it's the little things like this that you have to watch for and improve.Code:function movePlayer() if pad:left() and Player.x > 0 then Player.x = Player.x - 4 end if pad:right() and Player.x < 480 - 64 then Player.x = Player.x + 4 end if pad:down() and Player.y < 272 - 64 then Player.y = Player.y + 4 end if pad:up() and Player.y > 0 then Player.y = Player.y - 4 end end
@ altunozara
The variable "documenttext" will be one long string containing all of the characters in your text file, including possibly the character representations of escape sequences. Be aware that unless your file is essentially one line (e.g. you didn't press Enter while you were making the text file), you may have some funky characters like that.Code:file=io.open("yourfile.txt","r") documenttext=file:read("*a") file:close()
-
08-23-2006, 09:06 AM #3308Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
is it possible to clear some part of the screen and not everything
-
08-23-2006, 09:07 AM #3309is not posting very often

- Registriert seit
- Feb 2006
- Ort
- omnipresent
- Beiträge
- 5.162
- Points
- 33.152
- Level
- 100
- Downloads
- 0
- Uploads
- 0
I think it is, but i forgot how.
What did we think the world would look like in 2015?
http://forums.qj.net/501501-post26.html
Zitat von Abe
-
08-23-2006, 09:33 AM #3310QJ Gamer Blue
- Registriert seit
- Aug 2006
- Beiträge
- 145
- Points
- 4.580
- Level
- 43
- Downloads
- 0
- Uploads
- 0
Heres what I did:
I looked at what emulator guy said and was kinda confused because
1. the math.random on displayTime is 2,5, not 200,5000
2. There is no end under the counter variable.
THen, I looked at SG57's post and I removed the end so it looks like this:
At the end of my script. But heres what happened:Code:if pad:l() then dofile("menu.lua") end screen.waitVblankStart() screen.flip()
When I loaded my game on my menu script, it just froze.
-
08-23-2006, 09:49 AM #3311Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
@hallo007
I'm not sure what you mean...just stop blitting whatever it is to screen? But you could always cheat and make a rectangle to cover up part of the screen.
Zitat von hallo007
To cover up the left half. Many coders use a separate image variable that they "build up" and then they only have to blit that to screen. I call mine "prescreen" but you may have seen "offscreen" in some codes:Code:coverup=Image.createEmpty(240,272) screen:blit(0,0,coverup)
I've been told this is faster than blitting everything directly to the screen buffer, though I've never actually tested this. It just seems cleaner so I always do it.Code:prescreen=Image.createEmpty(480,272) -- (blit everything to prescreen) coverup=Image.createEmpty(240,272) prescreen:blit(0,0,coverup) screen:blit(0,0,prescreen)
@ Gonrai
Direct from your post above (with indentations left in):
Zitat von Gonrai
Sure looks like it to me, and besides SG57 even told you that it wouldn't work (he teases Lua coders for kicksCode:displayTime = math.random(500,2000) counter = 0 end
).
-
08-23-2006, 10:02 AM #3312QJ Gamer Silver
- Registriert seit
- Jun 2006
- Ort
- Removable Disk (G:)
- Beiträge
- 1.698
- Points
- 13.092
- Level
- 74
- Downloads
- 0
- Uploads
- 0
index.lua:2: error loading sound? help?!
edit. heres the code
iyk = Sound.load("iyk.wav")
iyk
lay()
Music.volume(128)
[_ıииeя_тυяκ*_]
Turkish Power >_<
-
08-23-2006, 10:04 AM #3313is not posting very often

- Registriert seit
- Feb 2006
- Ort
- omnipresent
- Beiträge
- 5.162
- Points
- 33.152
- Level
- 100
- Downloads
- 0
- Uploads
- 0
actually, that presreen thing will use more RAM and be slower, because it has to create the image
What did we think the world would look like in 2015?
http://forums.qj.net/501501-post26.html
Zitat von Abe
-
08-23-2006, 10:23 AM #3314QJ Gamer Silver
- Registriert seit
- Jun 2006
- Ort
- Removable Disk (G:)
- Beiträge
- 1.698
- Points
- 13.092
- Level
- 74
- Downloads
- 0
- Uploads
- 0
i dont get it. why am i getting an error?
Zitat von xsorifc28
[_ıииeя_тυяκ*_]
Turkish Power >_<
-
08-23-2006, 10:30 AM #3315QJ Gamer Blue
- Registriert seit
- Aug 2006
- Beiträge
- 145
- Points
- 4.580
- Level
- 43
- Downloads
- 0
- Uploads
- 0
My code:
It now gives me this error:Code:-- Alien Crosshair Game Screen -- Completally Coded by Mailas Gonrai -- Most errors fixed by pjspeedy and yaustar -- Colors black = Color.new(0,0,0) blue = Color.new(191, 255, 195) yellow = Color.new(255, 255, 0, 200) green=Color.new(0,255,0, 195) white = Color.new(255,255,255) red = Color.new(255,69,0, 195) -- ETC Variables displayTime = math.random(2,5) counter = 0 speed = 1 offscreen = false pad = Controls.read() -- Functions function RandomPoint() end math.randomseed(os.time()) -- Images back = Image.load("./Images/back_game.png") crosshair = Image.load("./Images/crosshair.png") border = Image.load("./Images/game_border.png") alienimage = Image.load("./Images/alien.png") -- Music Music.playFile("./Music/grmus.it") -- Objects Player = {} Player.x = 208 Player.y = 112 alien = {} alien.x = math.random(1,3) alien.y = math.random (1,3) alien = {x = 0, y = 200} x_point = 23 y_point = 83 -- Health Equivelent Options Player.health = 100 healthbar = {} healthbar.y = 10 function movePlayer() if pad:left() then Player.x = Player.x - 4 end if pad:right() then Player.x = Player.x + 4 end if pad:down() then Player.y = Player.y + 4 end if pad:up() then Player.y = Player.y - 4 end end function perimeterSize() if Player.x > 480 - 64 then Player.x = 480 - 64 end if Player.x < 0 then Player.x = 0 end if Player.y > 272 - 64 then Player.y = 272 - 64 end if Player.y < 0 then Player.y = 0 end end -- THE LOOP!---------------------------------------------------------- while true do screen:clear() x_point = math.random(1,480) y_point = math.random(1,272) AlienMove() if alien.x < x_point then alien.x = alien.x + 2 end if alien.x > x_point then alien.x = alien.x - 2 end if alien.y < y_point then alien.y = alien.y + 2 end if alien.y < y_point then alien.y = alien.y - 2 end if alien.x == x_point and alien.y == y_point then RandomPoint() end counter = counter + 1 if counter >= displayTime then alien.x = math.random(1,3) alien.y = math.random (1,3) end if alien.x == 1 then alien.x = 224 alien.y = 182 end if alien.x == 2 then alien.x = 60 alien.y = 132 end if alien.x == 3 then alien.x = 404 alien.y = 154 end screen:blit(0,0,back) screen:blit(alien.x,alien.y,alienimage) screen:blit(Player.x,Player.y,crosshair) screen:blit(0,0,border) screen:fillRect(320,240,Player.health,healthbar.y,green) screen:print(320,230,Player.health,blue) movePlayer() perimeterSize() alienscreenSize() if pad:l() then dofile("menu.lua") end screen.waitVblankStart() screen.flip() end
Code:error: ./game.lua:95: attempt to call a global /ALienMove/ ( a nil value) Error: No script file found. Press start to Restart.
-
08-23-2006, 11:13 AM #3316QJ Gamer Bronze
- Registriert seit
- Feb 2006
- Ort
- Earth, UK
- Beiträge
- 457
- Points
- 5.924
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Alienmove isnt classed as a function
-= Double Post =-
You never did function Alienmove()
You just did Alienmove()
-= Double Post =-
Have you checked that the sound file is not too big or too long for Lua Player
Zitat von xsorifc28
Geändert von JoeDaStudd (08-23-2006 um 11:13 AM Uhr) Grund: Automerged Doublepost
<<Put A message Here>>
<<Just made another rubbish website visit it here.>>
-
08-23-2006, 12:38 PM #3317
- Registriert seit
- Jul 2006
- Beiträge
- 36
- Points
- 3.957
- Level
- 40
- Downloads
- 0
- Uploads
- 0
ok heres the deal..
i need some code to make my character shoot a bullet at wherever my crosshair image is. ive tried ALOT and cant get anything working
my character scrolls left to right at the bottom of my screen. The crosshair can go anywhere by using the directional buttons.
so could someone tell me how to do this?
-
08-23-2006, 12:48 PM #3318QJ Gamer Blue
- Registriert seit
- Aug 2006
- Beiträge
- 145
- Points
- 4.580
- Level
- 43
- Downloads
- 0
- Uploads
- 0
-
08-23-2006, 12:52 PM #3319
- Registriert seit
- Jul 2006
- Beiträge
- 36
- Points
- 3.957
- Level
- 40
- Downloads
- 0
- Uploads
- 0
trust me ive studied that, it just shoots them left right up or down
i need mine to shhot to wherever the crosshair is (that could be any x,y position)
-
08-23-2006, 12:54 PM #3320is not posting very often

- Registriert seit
- Feb 2006
- Ort
- omnipresent
- Beiträge
- 5.162
- Points
- 33.152
- Level
- 100
- Downloads
- 0
- Uploads
- 0
make the cross hairs position x and y.
Then just have the bullets final location as X and YWhat did we think the world would look like in 2015?
http://forums.qj.net/501501-post26.html
Zitat von Abe
-
08-23-2006, 12:57 PM #3321
- Registriert seit
- Jul 2006
- Beiträge
- 36
- Points
- 3.957
- Level
- 40
- Downloads
- 0
- Uploads
- 0
if you look at the evil mana tut its not as easy as just changing some xy positions
he has it set up diferent
-
08-23-2006, 12:58 PM #3322Developer

- Registriert seit
- Jun 2005
- Ort
- At my house...
- Beiträge
- 886
- Points
- 8.360
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Sorry i dont have time to read all of your code but do you have a Controls.read(); at all to intialize the buttons?
Zitat von Gonrai
Edit: nvm found it
F.A.L.O?
-
08-23-2006, 01:12 PM #3323QJ Gamer Silver
- Registriert seit
- Jun 2006
- Ort
- Removable Disk (G:)
- Beiträge
- 1.698
- Points
- 13.092
- Level
- 74
- Downloads
- 0
- Uploads
- 0
size is 450kb...its like 15-20 secs long.
Zitat von JoeDaStudd
[_ıииeя_тυяκ*_]
Turkish Power >_<
-
08-23-2006, 01:18 PM #3324Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
can someone pleas post a snippet to find ur current FPS???
--------------------------------------------------------------------------------------
-
08-23-2006, 02:57 PM #3325
I wanted to add a typewriter effect but I get an error.
Code:-- EVILMANA.COM PSP LUA CODEBASE -- www.evilmana.com/tutorials/codebase -- Typewriter Effect for Text -- SUBMITTED BY: dennis van den broek -- Code : DS (dialogue system) -- Autor: Dennis van den broek white = Color.new(255, 255, 255) -- initialise if the DS (dialogue system) should be called DS_set = 0 -- strings used for the effect DS_str = { } DS_str[1] = "This is a typewriter machine test..." DS_str[2] = "This code is a test which can be used freely," DS_str[3] = "in any type of game, credits are allways welcome" -- temp string that stores the current to write string write_str = "" str_length = 0 -- counter for holding where on the string we are i = 1 num = 1 -- sets the DS on or off function init_DS(type) if type == 1 then DS_set = 1 else DS_set = 0 num = 1 end end -- checks what string to write, function should be upgraded with detection of which string to print -- currently it's a simple placeholding code function set_DS() if num > 3 then init_DS(0) end Typewriter(DS_str[num], 2, 10, 100) end -- the actual code, input the string you wanna print, and how many characters per frame you wanna show up... function Typewriter(str, speed, DSx, DSy) read_str = str str_length = string.len(read_str) if i <= str_length then i = i+speed write_str = string.sub(read_str, 1, i) screen:print(DSx, DSy, write_str, white) else screen:print(DSx, DSy, write_str, white) if pad:cross() and oldpad:cross() ~= pad:cross() then i = 0 num = num + 1 end end end -- main while loop while true do pad = Controls.read() if pad:cross() and oldpad:cross() ~= pad:cross() then init_DS(1) end if DS_set == 1 then set_DS() end screen.waitVblankStart() screen.flip() screen:clear() oldpad = pad end
-
08-23-2006, 03:02 PM #3326words 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
how about you post the error... Why wouldnt you saying you need help?
And I dont have time to read through the code and see whats wrong, even with an the error, but I can say having any 'screen' calls after you flip the display buffer is pointless. remove the screen:clear, it has no effect.
...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
-
08-23-2006, 03:13 PM #3327
I get this error.
Code:Error: index.lua:38 /=/ expected near /to/
-
08-23-2006, 03:19 PM #3328words 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
Well, go to line 38, see if there is something there that shouldnt be... Looks to me that the comment got brought out of the -- segment, making an error... Simply add '--' before 'string' on line 38.

...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
-
08-23-2006, 03:44 PM #3329Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
And on all of the other lines where comments are.
-
08-23-2006, 04:32 PM #3330
Ok I got it to work. Now If I want to exit my program, do I just input
Code:if pad:start() then exit


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