Seite 273 von 342 ErsteErste ... 173 223 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 323 ... LetzteLetzte
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....

  
  1. #8161
    QJ Gamer Blue
    Points: 7.014, Level: 55
    Level completed: 32%, Points required for next Level: 136
    Overall activity: 0%

    Registriert seit
    Jan 2007
    Ort
    U.S.
    Beiträge
    405
    Points
    7.014
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    That's it. And I still haven't changed it; it works. Haha.



  2. #8162
    Points: 3.045, Level: 33
    Level completed: 97%, Points required for next Level: 5
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Beiträge
    23
    Points
    3.045
    Level
    33
    Downloads
    0
    Uploads
    0

    Standard

    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

  3. #8163
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    this is untested but I'm sure that upon an error luaplayer returns nil so this may work

    Code:
    if s2 == nil then
    s2 = whichever default file you want it to be
    end
    oh ye and could you please use (code) and (/code) tags it makes things easier to read thanks - replace the brackets with square brackets

    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

    Code:
    if s2 == nil then
    s2 = Sound.load("default.wav")
    else
    s2 = Sound.load("1b.wav")
    end
    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 suggested

    Code:
    function sound_check(variable, sound_file)
    
    if variable == nil then
    variable = Sound.load("default.wav")
    else
    variable = Sound.load(sound_file)
    end
    
    end
    to call that function for example you would use

    Code:
    sound_check(s2, "b1.wav")
    to make it so you only have to type the name of the file the code would be this

    Code:
    function sound_check(variable, sound_file)
    
    if variable == nil then
    variable = Sound.load("default.wav")
    else
    variable = Sound.load("sound_file")
    end
    
    end
    to call that function for example you would use

    Code:
    sound_check(s2, b1.wav)
    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 use

    Code:
    sound_check(s2, b1.wav)
    s2:play()
    all of the above are untested if they don't work come back here to get some more help

    thanks
    Geä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).

  4. #8164
    Banned for LIFE
    Points: 18.744, Level: 86
    Level completed: 79%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    East London, England
    Beiträge
    2
    Points
    18.744
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    No. You would type
    Code:
    if s1 = nil then 
    
    put rest of code here

  5. #8165
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    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).

  6. #8166
    Points: 3.045, Level: 33
    Level completed: 97%, Points required for next Level: 5
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Beiträge
    23
    Points
    3.045
    Level
    33
    Downloads
    0
    Uploads
    0

    Standard

    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.

    Code:
    s2 = Sound.load("sound2.wav")
    stops the player if the file is not on the memorystick, so i can't check if
    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

  7. #8167
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    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

    Code:
    function sound_check(variable, sound_file)
    
    if variable == nil then
    variable = Sound.load("default.wav")
    else
    variable = Sound.load("sound_file")
    end
    
    end
    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 thereafter



    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).

  8. #8168
    Points: 3.045, Level: 33
    Level completed: 97%, Points required for next Level: 5
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Beiträge
    23
    Points
    3.045
    Level
    33
    Downloads
    0
    Uploads
    0

    Standard

    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

  9. #8169
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    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
    path example
    e.g. for path

    "ms0:/PSP/GAME/LuaPlayer/application_directory/music_file.wav"



    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).

  10. #8170
    Points: 2.876, Level: 32
    Level completed: 84%, Points required for next Level: 24
    Overall activity: 0%

    Registriert seit
    Nov 2007
    Beiträge
    12
    Points
    2.876
    Level
    32
    Downloads
    0
    Uploads
    0

    Standard

    Eldiablov - No. It's
    Code:
    if blah == nil
    In comparisons a double = is used. Single is for setting a variable equal to something.

    However, that's not even the best way to do it. A better way to do it would be
    Code:
    if not blah

  11. #8171
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    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. #8172
    lol
    Points: 20.859, Level: 91
    Level completed: 2%, Points required for next Level: 491
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    Whittier, CA
    Beiträge
    5.791
    Points
    20.859
    Level
    91
    Downloads
    0
    Uploads
    0

    Standard

    He already gave you a example. Use your Lua skills since your an expert now.

  13. #8173
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Anti-QuickJay
    He already gave you a example.
    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

    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).

  14. #8174
    lol
    Points: 20.859, Level: 91
    Level completed: 2%, Points required for next Level: 491
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    Whittier, CA
    Beiträge
    5.791
    Points
    20.859
    Level
    91
    Downloads
    0
    Uploads
    0

    Standard

    Learn how to check if a file exists. Then learn how to use a if not statement.
    Learn Lua.

    Now I'm happy :)

  15. #8175
    Points: 3.045, Level: 33
    Level completed: 97%, Points required for next Level: 5
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Beiträge
    23
    Points
    3.045
    Level
    33
    Downloads
    0
    Uploads
    0

    Standard

    hi, me again

    Code:
    function file_check(path)
    
    if path == nil then
    s2 = nil
    end
    
    end
    this cannot work, same reasons as above, you are telling the
    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

    Code:
    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")
    greetings
    Eelim

  16. #8176
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Anti-QuickJay
    Learn how to check if a file exists. Then learn how to use a if not statement.
    Learn Lua.

    Now I'm happy :)
    i can cope with that


    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).

  17. #8177
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    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

    Code:
    assert()
    so to make a file check function

    Code:
    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
    by using assert there is no need to actually open the file or close it so it should be much quicker

    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

    Code:
    if condition then
    assert(test, "message")
    end
    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 use

    Code:
    if file == nil then
    assert(file == nil, "this file is invalid")
    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 given

    - 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

    Code:
    io.open(file_path)
    in the top post no message was passed

    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).

  18. #8178
    Points: 3.045, Level: 33
    Level completed: 97%, Points required for next Level: 5
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Beiträge
    23
    Points
    3.045
    Level
    33
    Downloads
    0
    Uploads
    0

    Standard

    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

  19. #8179
    Ænima
    Points: 6.447, Level: 52
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Sep 2007
    Beiträge
    587
    Points
    6.447
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Eelim
    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
    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.
    [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.

  20. #8180
    Banned for LIFE
    Points: 18.744, Level: 86
    Level completed: 79%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    East London, England
    Beiträge
    2
    Points
    18.744
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    VERY hard to believe

    Anyway you could go to www.evilmana.com for information on lua etc

    ~Sullivan~

  21. #8181
    Points: 3.045, Level: 33
    Level completed: 97%, Points required for next Level: 5
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Beiträge
    23
    Points
    3.045
    Level
    33
    Downloads
    0
    Uploads
    0

    Standard

    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

  22. #8182
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    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).

  23. #8183
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Eelim
    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
    http://www.lua.org/manual/5.1/manual.html#5.7
    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

  24. #8184
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    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).

  25. #8185
    QJ Gamer Green
    Points: 7.599, Level: 58
    Level completed: 25%, Points required for next Level: 151
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Belgium
    Beiträge
    594
    Points
    7.599
    Level
    58
    Downloads
    0
    Uploads
    0

    Standard

    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:
    -- Easy Collisions --
    -- Author: Mistabeen --

    --var--
    red = Color.new(255,0,0)
    white = Color.new(255,255,255)
    black = Color.new(0,0,0)
    pink = Color.new(255,0,240)
    green = Color.new(0,255,0)
    map = Image.load( 'collide.png' )
    posX = 300
    posY = 100
    mspeedL = 1
    mspeedR = 1
    mspeedT = 1
    mspeedB = 1
    hp = 100


    -- main loop --
    while true do
    screen:clear(white)
    pad = Controls.read()

    -- movement --
    -- You might want to change posX > Value according to the "speed" of your object,
    -- if your detecting pixels go offscreen the script will crash
    -- When you are making the background scroll instead of the player
    -- you don't need to worry about these values and just delete them
    if pad:left() and posX > 17 then
    posX = posX - mspeedL
    end

    if pad:right() and posX < 463 then
    posX = posX + mspeedR
    end

    if pad:up() and posY > 17 then
    posY = posY - mspeedT
    end

    if pad:down() and posY < 255 then
    posY = posY + mspeedB
    end
    --end movement--

    if pad:select() then
    break
    end

    -- this shows your black and white map you created
    -- as an alternative, you could blit the hitboxes of the location of enemies,
    -- or user placed objects (RTS game as an example) in black on the screen instead of an image
    -- this would create an interactive base image for easy collisions --
    screen:blit(0,0,map)
    -- This get's the colors from the map to know if your object is close to an edge or not
    -- These are 8 possitions it takes the colorinformation from
    -- This is used for the topdown view of a character (or isometric view)
    -- You can add or remove pixels to suit your needs
    topcol = screenixel(posX,posY-14)
    topRcol = screenixel(posX+10,posY-9)
    topLcol = screenixel(posX-10,posY-9)
    Rcol = screenixel(posX+14,posY)
    Lcol = screenixel(posX-14,posY)
    botcol = screenixel(posX,posY+14)
    botLcol = screenixel(posX-10,posY+9)
    botRcol = screenixel(posX+10,posY+9)

    -- Here you baisicly compare the detected collor to black
    -- if the color is black, then the movement should stop
    -- you can add and remove some of these restrictions to suit your needs

    if topcol == black then
    mspeedT = 0
    elseif topcol ~= black then
    mspeedT = 1
    end

    if botcol == black then
    mspeedB = 0
    elseif botcol ~= black then
    mspeedB = 1
    end

    if Rcol == black then
    mspeedR = 0
    elseif Rcol ~= black then
    mspeedR = 1
    end

    if Lcol == black then
    mspeedL = 0
    elseif Lcol ~= black then
    mspeedL = 1
    end

    if topRcol == black then
    mspeedT = 0
    mspeedR = 0
    end

    if topLcol == black then
    mspeedT = 0
    mspeedL = 0
    end

    if botLcol == black then
    mspeedB = 0
    mspeedL = 0
    end

    if botRcol == black then
    mspeedB = 0
    mspeedR = 0
    end

    if topcol == pink then
    mspeedT = 0
    hp = hp-1
    end

    if topRcol == pink then
    mspeedT = 0
    mspeedR = 0
    hp = hp-1
    end

    if topLcol == pink then
    mspeedT = 0
    mspeedL = 0
    hp = hp-1
    end

    if Rcol == pink then
    mspeedR = 0
    hp = hp-1
    end

    if Lcol == pink then
    mspeedL = 0
    hp = hp-1
    end

    if botRcol == pink then
    mspeedB = 0
    mspeedR = 0
    hp = hp-1
    end

    if botLcol == pink then
    mspeedB = 0
    mspeedL = 0
    hp = hp-1
    end

    if botcol == pink then
    mspeedB = 0
    hp = hp-1
    end

    if botcol == green or botRcol == green or botLcol == green or Lcol == green or Rcol == green or topLcol == green or topRcol == green or topcol == green then
    hp = hp+1
    end

    -- This is just for debugging purpose
    screen:fillRect(posX-1, posY-1, 3, 3, red)
    screen:fillRect(posX,posY-14, 1, 1, red)
    screen:fillRect(posX+10,p osY-9, 1, 1, red)
    screen:fillRect(posX-10,posY-9, 1, 1, red)
    screen:fillRect(posX+14,p osY, 1, 1, red)
    screen:fillRect(posX-14,posY, 1, 1, red)
    screen:fillRect(posX,posY +14, 1, 1, red)
    screen:fillRect(posX-10,posY+9, 1, 1, red)
    screen:fillRect(posX+10,p osY+9, 1, 1, red)

    screenrint(10,10,mspeedT,red)
    screenrint(10,20,mspeedR,red)
    screenrint(10,30,mspeedL,red)
    screenrint(10,40,mspeedB,red)
    screenrint(10,50,"HP:"..hp,red)

    screen.flip()
    screen.waitVblankStart()

    end

  26. #8186
    QJ Gamer Bronze
    Points: 5.381, Level: 47
    Level completed: 16%, Points required for next Level: 169
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    550
    Points
    5.381
    Level
    47
    Downloads
    1
    Uploads
    0

    Standard

    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

  27. #8187
    QJ Gamer Green
    Points: 7.599, Level: 58
    Level completed: 25%, Points required for next Level: 151
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Belgium
    Beiträge
    594
    Points
    7.599
    Level
    58
    Downloads
    0
    Uploads
    0

    Standard

    Thx Nielke, I'll take a look at it tomorow, it's a tad to late right now for me ^^ Thx tho

  28. #8188
    QJ Gamer Blue
    Points: 5.636, Level: 48
    Level completed: 44%, Points required for next Level: 114
    Overall activity: 0%

    Registriert seit
    Sep 2005
    Beiträge
    300
    Points
    5.636
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    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. ;_;

  29. #8189
    lol
    Points: 20.859, Level: 91
    Level completed: 2%, Points required for next Level: 491
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    Whittier, CA
    Beiträge
    5.791
    Points
    20.859
    Level
    91
    Downloads
    0
    Uploads
    0

    Standard

    These should work. I haven't tested.
    http://www.sendspace.com/file/uvn88u

  30. #8190
    QJ Gamer Blue
    Points: 3.617, Level: 37
    Level completed: 78%, Points required for next Level: 33
    Overall activity: 0%

    Registriert seit
    Apr 2007
    Ort
    The Netherlands
    Beiträge
    104
    Points
    3.617
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    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 :
    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
    I really hope you guys can help me !
    Cheers.


 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 07:54 AM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .