Zeige Ergebnis 8.161 bis 8.190 von 10238
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's it. And I still haven't changed it; it works. Haha....
-
12-02-2007, 02:52 PM #8161QJ Gamer Blue
- Registriert seit
- Jan 2007
- Ort
- U.S.
- Beiträge
- 405
- Points
- 7.014
- Level
- 55
- Downloads
- 0
- Uploads
- 0
That's it. And I still haven't changed it; it works. Haha.
-
12-03-2007, 09:45 AM #8162
- Registriert seit
- Dec 2007
- Beiträge
- 23
- Points
- 3.045
- Level
- 33
- Downloads
- 0
- Uploads
- 0
Hi everyone,
just need a little advice, i recently picked up lua for coding
(since i can't be arsed to install cygwin and all the other stuff
for coding in C for the psp), since this is a new language for me
i rely a lot on tutorials for learning how lua works, but for the problem
i have at the moment i cant find anything on the net, and the searchfunction
wasn't helpfull either...
oh, yeah, i almost forgot :-) here my problem:
i load several sets of sounds in variables which looks like this:
s1 = Sound.load("1a.wav")
s2 = Sound.load("1b.wav")
s3 = Sound.load("1c.wav")
s4 = Sound.load("1d.wav")
my problem now is, in some sound sets there might not be a "1b.wav",
my question is, how can i check if the file exists before i load it, so i can
load another file if there is none ?
greetings
Eelim
-
12-03-2007, 11:27 AM #8163Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
this is untested but I'm sure that upon an error luaplayer returns nil so this may work
oh ye and could you please use (code) and (/code) tags it makes things easier to read thanks - replace the brackets with square bracketsCode:if s2 == nil then s2 = whichever default file you want it to be end
if that works then i just had an idea this code may be better than that code as it checks for an error or not
to make it more efficient you could make a function that checks if the result is nil and if it is to use the default file and if not then load the file originally suggestedCode:if s2 == nil then s2 = Sound.load("default.wav") else s2 = Sound.load("1b.wav") end
to call that function for example you would useCode:function sound_check(variable, sound_file) if variable == nil then variable = Sound.load("default.wav") else variable = Sound.load(sound_file) end end
to make it so you only have to type the name of the file the code would be thisCode:sound_check(s2, "b1.wav")
to call that function for example you would useCode:function sound_check(variable, sound_file) if variable == nil then variable = Sound.load("default.wav") else variable = Sound.load("sound_file") end end
this would mean that if the file does not exist then it would set that variable as default.wav but if that file does exist then it will set the variable to the sound file you told it to originally and you don't have to set the variable at the beginning of the program i don't think so then with this code you could just useCode:sound_check(s2, b1.wav)
all of the above are untested if they don't work come back here to get some more helpCode:sound_check(s2, b1.wav) s2:play()
thanksGeändert von FaT3oYCG (12-03-2007 um 12:02 PM Uhr)
------ 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).
-
12-03-2007, 11:33 AM #8164Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
No. You would type
Code:if s1 = nil then put rest of code here
-
12-03-2007, 11:45 AM #8165Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
ok sorry i will change that thanks
EDIT:
revised and improved code with more options
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).
-
12-03-2007, 01:07 PM #8166
- Registriert seit
- Dec 2007
- Beiträge
- 23
- Points
- 3.045
- Level
- 33
- Downloads
- 0
- Uploads
- 0
sorry, thats not it, your code would work if i just don't know if i have
loaded a file into the variable or not.
But the error occurs while trying
to load a file, not while trying to play it.
stops the player if the file is not on the memorystick, so i can't check ifCode:s2 = Sound.load("sound2.wav")
s2 would be nil, cause the has player already stopped.
so what i need is either
a) The syntax to access the file system and look if the filename exists
or
b) the syntax for global errorhandling so i can prevent the player from halting.
greetings
Eelim
-
12-03-2007, 01:13 PM #8167Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
hmm i have had many problems with music files and such before sometimes i dont know why but if you load a file e.g. a music file or a picture file after line 32 it crashes so separate your files into different lua files for example
sounds.lua - load all sounds in this file
pictures.lua - load all pictures in this file
and then in your main file normally your index.lua put
dofile("sounds.lua")
dofile("pictures.lua")
and it should work if not it is probably an error because of how long the file takes to load
as you cannot do something like this
s2 = Sound.load("sound2.wav")
s2:play()
also this code
will check if the file exists or not - just call the function and pass the variable name and file name and it will see if the file is there if it isn it returns nil so then will handle the error accordingly to the code thereafterCode:function sound_check(variable, sound_file) if variable == nil then variable = Sound.load("default.wav") else variable = Sound.load("sound_file") end end
to handle errors the error will display a message to the user but a nil statement will be passed before hand so you can ask if nil has been passed as shown above------ 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).
-
12-03-2007, 02:54 PM #8168
- Registriert seit
- Dec 2007
- Beiträge
- 23
- Points
- 3.045
- Level
- 33
- Downloads
- 0
- Uploads
- 0
doesn't work,
if i use that code it always plays the default file, no matter if
the wanted file exists or not, cause since the variable is "new"
it is always nil, if i declare it before i call the function the player
stops if my wanted file does not exist. if i declare the variable
with a placeholder it is never nil, now the player tries again to
load the file and stops if it doesnt exist.
so again:
i need to know if the file exists on the memory stick BEFORE i
try to load it with "Sound.load".
how do i do that??
greetings
Eelim
-
12-03-2007, 03:13 PM #8169Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
well you could replace that function to detect a file it is quite simple you could have modified it yourself but here it is
Code:function file_check(path) if path == nil then s2 = nil end end
and then you could just leave s2 as a blank variable
or change it to a default file
hope that helps come back if not
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).
-
12-03-2007, 03:26 PM #8170
- Registriert seit
- Nov 2007
- Beiträge
- 12
- Points
- 2.876
- Level
- 32
- Downloads
- 0
- Uploads
- 0
Eldiablov - No. It's
In comparisons a double = is used. Single is for setting a variable equal to something.Code:if blah == nil
However, that's not even the best way to do it. A better way to do it would be
Code:if not blah
-
12-03-2007, 03:30 PM #8171Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
dont worry tux i realized that it was two not one thanks ne way and i think it was because that is what i originally had mine as but then i changed it
and how would we use an if not statement for this situation - enlighten me please------ 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).
-
12-03-2007, 03:46 PM #8172lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
He already gave you a example. Use your Lua skills since your an expert now.
-
12-03-2007, 03:49 PM #8173Developer 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 didn't find if not blah very useful i only asked how it could be used if it makes you fell better ill ask again in more detail
Zitat von Anti-QuickJay
hi TuxThePenguin could you please give me a detailed example of how the if not statement could be used to find out if a file exists
thanks
happy now A-QJ ??????------ 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).
-
12-03-2007, 03:52 PM #8174lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Learn how to check if a file exists. Then learn how to use a if not statement.
Learn Lua.
Now I'm happy :)
-
12-03-2007, 03:52 PM #8175
- Registriert seit
- Dec 2007
- Beiträge
- 23
- Points
- 3.045
- Level
- 33
- Downloads
- 0
- Uploads
- 0
hi, me again
this cannot work, same reasons as above, you are telling theCode:function file_check(path) if path == nil then s2 = nil end end
variable it is something when you call the function, so it is never nil,
and it does not check the memory stick if a file exists or not.
what i want to do is a "File Operation" on the "File System", classical
Input Output operations, and after more than 10 hours of searching
the net, i finally found the syntax for doing so.
so here is the code to check if a file exists on the memorystick or not
if someone should happen to have the same problem
greetingsCode:function file_check(filename) f = io.open(filename) if f == nil then screen:print(100,100,"No such file exists") else screen:print(100,100,"File Found") f:close() end end file_check("test.wav")
Eelim
-
12-03-2007, 03:54 PM #8176Developer 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 can cope with that
Zitat von Anti-QuickJay
well done Eelim for solving your problem
and thanks for posting the answer not many people bother too------ 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).
-
12-07-2007, 10:59 AM #8177Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Eelim i dont know if you will check this but i feel so stupid now that i know your problem and the result that you wanted this will let you check for a file
so to make a file check functionCode:assert()
by using assert there is no need to actually open the file or close it so it should be much quickerCode:function file_check(file_path) file = assert(io.open(file_path)) if file == nil then screen:print(10, 10, "the file path was invalid") else screen:print(10, 10, "the file path was valid") end end
you can also return custom error messages using this command and create an error handler for your programs
- i dont have an example error handler but this is sort of how assert is used
this code means that if the condition is met then it will carry out the assert command so say if file == nil then you would useCode:if condition then assert(test, "message") end
if there is no message then the command can be used to check values and will return either false or nil so if the error or condition is false it wont be executed, but if it is nill it will assert the command givenCode:if file == nil then assert(file == nil, "this file is invalid") end
- an example of this is the code used at the top of my post
that is the part of the code that is seen as the test
in the top post no message was passedCode:io.open(file_path)
the error messages come out the same was as if an error is returned in lua player with a black screen and a white error message
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).
-
12-09-2007, 02:15 AM #8178
- Registriert seit
- Dec 2007
- Beiträge
- 23
- Points
- 3.045
- Level
- 33
- Downloads
- 0
- Uploads
- 0
hi,
i just didn't know lua had an assert command, for the things
i do now, it's ok the way i do it, cause if the file exists i have to
open it anyways, but for more complex structures assert is a
big win.
thx for the info!!!
i am a software engineer for over 10 years now, and i know several languages,
but i am new to lua, and one of my biggest problems is, i can't find
anything decent on the net on lua syntax, sure there are thousands
of tutorials, but 99,9% deal with the basic hello world, almost no
advanced tutorials, and if you manage to find something more advanced,
its usually unreadable (explaining every line of code, but not displaying,
the whole thing, so that you loose track of what the code actually does,
or yellow text on white background.. stuff like that..)
but anyways, thx a again for the assert info, that is a big help
greetings
Eelim
-
12-09-2007, 06:13 AM #8179
You've been a software engineer for over 10 years, and can't figure out something as simple as going to Lua.org and learning the syntax? That's pretty hard to believe.
Zitat von Eelim
[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.
-
12-09-2007, 06:32 AM #8180Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
VERY hard to believe
Anyway you could go to www.evilmana.com for information on lua etc
~Sullivan~
-
12-10-2007, 09:15 AM #8181
- Registriert seit
- Dec 2007
- Beiträge
- 23
- Points
- 3.045
- Level
- 33
- Downloads
- 0
- Uploads
- 0
on lua.org everything concerning the io system has a big fat "TODO"
written under the topic, so no help there, evilmana is nice,
but not very readable (but good tutorials none the less), but
also nothing on the io system.
i wouldn't have asked here, if it was as simple as going to lua.org, think before you diss.
greetings
Eelim
-
12-10-2007, 10:07 AM #8182Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
not to offend you but where have you been looking dont use lua.org use the official lua users wiki
http://lua-users.org/wiki/IoLibraryTutorial
go here for all of the directories and examples - most are filled in
http://lua-users.org/wiki/TutorialDirectory
IO defo is------ 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).
-
12-10-2007, 10:29 AM #8183QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
http://www.lua.org/manual/5.1/manual.html#5.7
Zitat von Eelim
Lua.org -> Documentation -> Reference Manual -> IO
http://www.lua.org/pil/21.html
Lua.org -> Documentation -> Programming in Lua -> The first edition is available online! -> The IO library
http://lua-users.org/wiki/IoLibraryTutorial
Lua.org -> Community -> Wiki -> LuaTutorial -> TutorialDirectory -> IoLibraryTutorial
http://www.evilmana.com/tutorials/lua_tutorial_09.php
Evilmana.com -> Tutorials -> Lua for Beginners -> Reading and Writing Files[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
12-10-2007, 10:58 AM #8184Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
ok then do use lua.org its more specific thanks yaustar we can always count on you
------ 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).
-
12-19-2007, 08:50 AM #8185QJ Gamer Green
- Registriert seit
- Jul 2005
- Ort
- Belgium
- Beiträge
- 594
- Points
- 7.599
- Level
- 58
- Downloads
- 0
- Uploads
- 0
I'm hoping someone can help me out here :)
This script works perfect on LUAplayer on my computer, but when testing it on the PSP it's a bit flawed.
What this does is read the color of the base map (PNG is not attached, but any PNG image image will do that's 480*272 and is only Black and white, other colors won't be seen anyway
) or you could always replace it with any other shape blitted to the screen instead of loading the image. According to the collor spotted it will either "collide" and not be able to move, or get damaga or heal.
It's something I'm working on so people who don't know LUA can easely "paint" their own levels with collision detection.
The only problem is, the collisions get detected a bit slow on the PSP. On the computer it works just fine, but on PSP sometimes it detects the collision as soon as you enter a black field, but somtimes it detects it afther a few pixels and you will get stuck as a result
It seems to be happening most when you have been moving around for a few seconds without colliding with an object, when you stand still in front of an object and then press an arrowbutton it'll collide instantly.
Does anyone know how to solve this?
Spoiler for Collision Script:
-
12-19-2007, 07:12 PM #8186QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Instead of having so many variables, use more functions.
This could help:
Code:function CollisionCheckLineColour(x1,y1,x2,y2,colour,img) --Only works with straight lines img = img or screen local colliding = false local test1; local test2; local NotTest; local step; if x1 == x2 then test1 = y1 test2 = y2 NotTest = x1 elseif y1 == y2 then test1 = x1 test2 = x2 NotTest = y1 end if test1 < test2 then step = 1 else step = -1 end for i=test1,test2,step do if img:Pixel(NotTest,i) == colour then colliding = true end end return colliding end function CollisionCheckBoxColour(x,y,width,height,colour,img) if CollisionCheckLineColour(x,y,x + width,y,colour,img) or CollisionCheckLineColour(x + width,y,x + width,y + height,colour,img) or CollisionCheckLineColour(x,y + height,x + width,y + height,colour,img) or CollisionCheckLineColour(x,y,x,y + height,colour,img) then return true else return false end end
-
12-19-2007, 07:38 PM #8187QJ Gamer Green
- Registriert seit
- Jul 2005
- Ort
- Belgium
- Beiträge
- 594
- Points
- 7.599
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Thx Nielke, I'll take a look at it tomorow, it's a tad to late right now for me ^^ Thx tho
-
12-22-2007, 08:48 PM #8188
Does anyone think they could convert this into an EBoot for me?
http://forums.qj.net/f-psp-developme...ml#post1915912
It needs LUAPlayer 0.16 MOD4. Last time I tried doing it, it didn't work at all. ;_;
-
12-22-2007, 11:55 PM #8189lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
These should work. I haven't tested.
http://www.sendspace.com/file/uvn88u
-
12-23-2007, 05:01 AM #8190QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- The Netherlands
- Beiträge
- 104
- Points
- 3.617
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Hi folks !
Im trying to make a little game, now i'm working on the beginmenu. I'm trying to load a background an tell the psp that if the cross button is pressed it should do file ./game.lua . But i get this error : Bad argument #2 to blit (image expected, got nil)
This is the code :
I really hope you guys can help me !white = Color.new(255,255,255)
red = Color.new(255,0,0)
blue = Color.new(0,0,255)
orange = Color.new(255, 102, 0)
background = Image.load("images/begin.jpg")
oldpad = Controls.read()
while true do
pad = Controls.read()
screen:clear()
screen:blit(0,0,begin, true)
if pad:cross() then
dofile("./game.lua")
end
screen.waitVblankStart()
screen.flip()
end
Cheers.


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