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; Zitat von littlevish This may be a dumb question, but is there an easy way to restart my script? (Eg. ...
-
03-06-2008, 12:05 PM #8371Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Zitat von littlevish
look at the lua snippets i posted a good game state system there, thanks to sg57 who gave me the idea by posting his and then i made my own
Zitat von SG57
LINK
thanks
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-07-2008, 01:43 PM #8372Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
ok i have an error message which i have never seen before!!
THE ERROR:
581: attempt to perform arithmetic on global 'Moving' ( a boolean value) WAT does this mean and how would u fix it??
-
03-07-2008, 02:13 PM #8373
Show us the few lines before and after 581. Also, a boolen value is a value that holds either 'true' or 'false'.
Zitat von dan369
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
03-07-2008, 02:26 PM #8374Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
i know wat i did wrong i but
where it should beCode:if Moving-Left == true then
at least i know wat boolean error means thanks!!!Code:if Moving_Left == true then
-= Double Post =-
since that it has been working fine!! but there is one promblem when it loads up the menu the backgroung image doesn't change, it loads up the menu-image but it doesn't load up the level image is there a way to clear the screen when X is pressed on menu = 1 so that it would load up the other backgroung imageGeändert von dan369 (03-07-2008 um 03:00 PM Uhr) Grund: Automerged Doublepost
-
03-07-2008, 04:16 PM #8375Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
screen:clear()
use game states aswell and at the beginning of each state put
screen:clear()
if you want something to show in every state put it outside of the states------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-07-2008, 04:35 PM #8376Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
when you press X the game state changes to "Game"
Should it be like this
Code:if pad:cross() and gamestate = "Game" then screen:clear() Load_First_level() end
-
03-08-2008, 05:49 AM #8377Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
i would use this method
Zitat von dan369
here is what i posted in the snippets not so long ago
Code:white = Color.new(255, 255, 255) black = Color.new(0, 0, 0) red = Color.new(255, 0, 0) green = Color.new(0, 255, 0) blue = Color.new(0, 0, 255) orange = Color.new(235, 115, 0) yellow = Color.new(255, 255, 0) state = { loading = 1, menu = 2, game = 3 } current_state = state.loading function Set_State(state_to_change_to) current_state = state_to_change_to end function Get_State() return current_state end function Start_States() if Get_State() == state.loading then -- do loading stuff screen:clear() screen:print(10, 10, "loading state", white) if pad:cross() and oldpad:cross() ~= pad:cross() then Set_State(state.menu) end elseif Get_State() == state.menu then -- do menu stuff screen:clear() screen:print(10, 10, "menu state", white) if pad:cross() and oldpad:cross() ~= pad:cross() then Set_State(state.game) end elseif Get_State() == state.game then -- do game stuff screen:clear() screen:print(10, 10, "game state", white) if pad:cross() and oldpad:cross() ~= pad:cross() then Set_State(state.loading) end end end oldpad = Controls.read() while true do pad = Controls.read() screen:clear() -- main Start_States() -- main if Controls.read():start() then break end screen.flip() screen.waitVblankStart() oldpad = pad end------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-08-2008, 06:17 AM #8378Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
so say i have 3 scripts, index(starting one), menu( menu) game(game) how would u incorporate that with this???
-
03-08-2008, 06:24 AM #8379Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
it is better to have 3 scripts in most projects and structure them to fit your needs but if you want to keep your separate files then i would do this
in each of your files, make the information inside them a function
so go into game.lua and on the first line type function Game(), and on the last line another end - do this for menu.lua aswell, then have this file structure,
index.lua
main.luaCode:dofile("main.lua")
then use the Get_State() and Set_State(state) commands to swap through eachCode:white = Color.new(255, 255, 255) black = Color.new(0, 0, 0) red = Color.new(255, 0, 0) green = Color.new(0, 255, 0) blue = Color.new(0, 0, 255) orange = Color.new(235, 115, 0) yellow = Color.new(255, 255, 0) dofile("game.lua") dofile("menu.lua") state = { menu = 1, game = 2 } current_state = state.loading function Set_State(state_to_change_to) current_state = state_to_change_to end function Get_State() return current_state end function Start_States() if Get_State() == state.menu then -- do menu stuff Menu() if pad:cross() and oldpad:cross() ~= pad:cross() then Set_State(state.game) end elseif Get_State() == state.game then -- do game stuff Game if pad:cross() and oldpad:cross() ~= pad:cross() then Set_State(state.menu) end end end oldpad = Controls.read() while true do pad = Controls.read() screen:clear() -- main Start_States() -- main if Controls.read():start() then break end screen.flip() screen.waitVblankStart() oldpad = pad end------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-08-2008, 06:51 AM #8380Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
i get this know in the script file i'll put the dofile command in the script
is there possibly an easy way the actual promblem is that when i press X on start(selected 1) it doesn't chande the background img to the actual one i want it keeps the menu image, is there a way when X is pressed on selected 1 that it will clear the screen black and the blit the other image??
-= Double Post =-
i have FIXEDDD IT Turns out i was that image was blitting underneath DUHHHH since i have fix that i have only one little tweak to do thanksGeändert von dan369 (03-08-2008 um 11:36 AM Uhr) Grund: Automerged Doublepost
-
03-09-2008, 07:00 AM #8381QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- dfgd
- Beiträge
- 66
- Points
- 4.008
- Level
- 40
- Downloads
- 0
- Uploads
- 0
omg ive been looking all over the internet on how to load tiles from a tile sheet then input them into a table so then i can use them in my tile engine and blit them to the screen with the corrosponding number.
how the hell can i do it?
ive been looking at like zelda demo/LUMM all those things with tile engines in and i have no idea on how to mod it to my game.
can some one please give me a code snippet or a link to a tutorial or site on how to load 32x32 tiles from a tile sheet and input them into a table.
thxz for any replys
Luke
-
03-09-2008, 11:21 AM #8382Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-10-2008, 03:19 PM #8383QJ Gamer Blue
- Registriert seit
- Dec 2006
- Beiträge
- 251
- Points
- 4.872
- Level
- 44
- Downloads
- 0
- Uploads
- 0
Can't find where I went wrong...
It returns nil when I do showEnemy()
Code:--vars enemies = 0 test = 1 enemyImg = Image.load("enemy.png") screenColor = Color.new(255,255,255) --tables player = {x=200, y=100, width=25, height=25, speed=10, img = Image.load("player.png")} block = {x=0, y=0, width=20, height=20, img = Image.load("block.png")} enemy = { } function newEnemy() enemies = enemies + 1 new = enemies + 1 enemy[enemies] = {x=math.random(0,460), Y=math.random(0,252), width=25, height=25, speed=5, direction=math.random(1,4)} showEnemies() end function showEnemies() --directions: 1 up, 2 right, 3 down, 4 left for i=1, enemies do screen:blit(enemy[i].x, enemy[i].y, enemyImg) if enemy[i].direction == 1 then if enemy[i].y >= 0 then enemy[i].direction = 3 else enemy[i].y = enemy[i].y - enemy[i].speed end elseif enemy[i].direction == 2 then if enemy[i].x >= 480 - enemy[i].width then enemy[i].direction = 4 else enemy[i].x = enemy[i].x + enemy[i].speed end elseif enemy[i].direction == 3 then if enemy[i].y >= 272-enemy[i].width then enemy[i].direction = 1 else enemy[i].y = enemy[i].y + enemy[i].speed end elseif enemy[i].direction == 4 then if enemy[i].x >= 0 then enemy[i].direction = 1 else enemy[i].y = enemy[i].y - enemy[i].speed end end end end while true do pad = Controls.read() screen:clear(screenColor) if pad:up() then player.y = player.y - player.speed elseif pad:down() then player.y = player.y + player.speed elseif pad:left() then player.x = player.x - player.speed elseif pad:right() then player.x = player.x + player.speed end if pad:start() then break end if enemies < 1 then newEnemy() else showEnemies() end screen:blit(player.x,player.y,player.img) screen:blit(block.x,block.y,block.img) screen.flip() screen.waitVblankStart() end
-
03-10-2008, 03:59 PM #8384words 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
littlevish - Lua player interprets scripts as it runs through it, not all at once then runs through it - your calling showEnemies in yoiur newEnemy function, and to newEnemy's scope, there's no such thing as showEnemies.
Basically - just move the showEnemies function above the newEnemy.
...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
-
03-10-2008, 04:03 PM #8385Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
and please excuse what i said on that. those were my n00b days.
Zitat von FaT3oYCG
not entirely true. the speedup is not nearly as much as i make it sound.* Found a major flaw in sprite sheet animation blitting. The problem was, the lib calculated the width to height ratio in the blit function, when it should have been done in the loading function. It works both ways, but doing it the the blitting function meant that the lib was dividing (with is a costly calculation) every frame unnecessarily. I fixed it so that it calculates only once, in the loading function. This should provide a MASSIVE speed-up when using sprite sheets.--------------------------------------------------------------------------------------
-
03-10-2008, 04:12 PM #8386words 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
ahhhh...
Zitat von Grimfate126
First milestone to success is admitting 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
-
03-10-2008, 04:41 PM #8387Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
lol. truth hurts
Zitat von SG57

if only vista let me code again...--------------------------------------------------------------------------------------
-
03-10-2008, 05:16 PM #8388QJ Gamer Blue
- Registriert seit
- Dec 2006
- Beiträge
- 251
- Points
- 4.872
- Level
- 44
- Downloads
- 0
- Uploads
- 0
edit: nvm, it was a case-sensitive problem
Geändert von littlevish (03-10-2008 um 06:23 PM Uhr)
-
03-13-2008, 11:49 AM #8389
did somebody help me correctly delete some files from flash1?
i cant assign flash 1 to delete custom ptf theme
with my script...
Geändert von lps (03-13-2008 um 12:12 PM Uhr)
-
03-13-2008, 12:48 PM #8390Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
i thought you could copy paste delete files from flash with lua player anyway ?, but if you can't use luaplayer hm or another version that has flash assign and un assign and then use the remove file option
System.removeFile(path)------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-13-2008, 01:14 PM #8391
can you write example, how can i correctly assign flash1?
???Code:System.assign(flash1:) System.removeFile(flash1:/some.file) System.unassign(flash1:)
-
03-13-2008, 01:17 PM #8392Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
you have to un assign first, there was some example scripts that came with sg57's mod, search for the download on dl.qj.net, or pm him
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-13-2008, 03:22 PM #8393
Last time I checked, the flash1 is in write mode to begin with.
Zitat von lps
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
03-14-2008, 07:58 AM #8394
so how i can to delete the file?
Zitat von Judas
-
03-14-2008, 09:09 AM #8395Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
System.removeFile("flash1 :/folder/file.ext")
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-14-2008, 11:32 AM #8396
hmmmmm...
you dont understand((
how can i correctly mount f1, delete file, unmount f1 ?
-
03-14-2008, 11:39 AM #8397Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
so basically you want me to do it for you
Zitat von lps
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
03-14-2008, 11:41 AM #8398QJ Gamer Platinum
- Registriert seit
- Feb 2006
- Ort
- National Front Disco
- Beiträge
- 13.057
- Points
- 66.627
- Level
- 100
- Downloads
- 0
- Uploads
- 0
How ironic.
Zitat von FaT3oYCG
-
03-14-2008, 12:17 PM #8399
Why do you need to un-mount the flash1? Delete the file, and be done with it, that's it. No more work required.
Zitat von lps
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
03-14-2008, 01:44 PM #8400Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
if you do need to mount it i dont know the specific commands, as i have said there are examples in the mod that was made
Zitat von Judas
if you do just mount it and delete then unmount
it is probably something like
System.assign("flash0:")
and
System.unassign("flash0:" )
and then do what i said------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).


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