Seite 107 von 342 ErsteErste ... 7 57 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 157 207 ... LetzteLetzte
Zeige Ergebnis 3.181 bis 3.210 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; Zitat von N0obKi|l3r.exe im about to commit suicide from stupidity last question: how can i make a random number load... ...

  
  1. #3181
    QJ Gamer Gold
    Points: 18.627, Level: 86
    Level completed: 56%, Points required for next Level: 223
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Ort
    LOLWUT
    Beiträge
    2.625
    Points
    18.627
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von N0obKi|l3r.exe
    im about to commit suicide from stupidity last question:

    how can i make a random number load... i.e a number bettween 1 and 3 eighter 1, 2, or 3 ?
    Put math.randomseed(os.time() ) as the first line. Then do:
    math.random(low, high)
    You could just do mynumber = math.random(low,high)

    Hope I helped. :)



  2. #3182
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    myNumber = math.random(1,30)

    This picks a number at random between 1 and 30.If you put this BEFORE your main loop, it will pick a random number once, when the script is first started. If you put this AFTER your main loop, it will pick a new number each time the loop performs.

    Also, if you are going to be using random numbers, put this at the beggining of your code:

    math.randomseed(os.time() )

    Without this, it would pick the same random number every time, which wouldn't make it very random.

    EDIT: Oops, looks like PSPduh already helped you. BTW- Don't worry about making stupid mistakes, everyone does it.

  3. #3183
    QJ Gamer Gold
    Points: 18.627, Level: 86
    Level completed: 56%, Points required for next Level: 223
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Ort
    LOLWUT
    Beiträge
    2.625
    Points
    18.627
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Access_Denied
    myNumber = math.random(1,30)

    This picks a number at random between 1 and 30.If you put this BEFORE your main loop, it will pick a random number once, when the script is first started. If you put this AFTER your main loop, it will pick a new number each time the loop performs.

    Also, if you are going to be using random numbers, put this at the beggining of your code:

    math.randomseed(os.time() )

    Without this, it would pick the same random number every time, which wouldn't make it very random.

    EDIT: Oops, looks like PSPduh already helped you. BTW- Don't worry about making stupid mistakes, everyone does it.
    Yes but yours is much more explained then mine. :)

  4. #3184
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von PSPduh
    Yes but yours is much more explained then mine. :)
    That's probably why you posted before me, I took too long to write it.:)

  5. #3185
    Asleep...
    Points: 11.516, Level: 70
    Level completed: 67%, Points required for next Level: 134
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    1.383
    Points
    11.516
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    thnaks both off you. now with this im going top make it so thaty after 5 seconds, it will load a number. if number == 1 then health = health - 5 and restart timer and start it. iff 2 then do nothing what do ya think? fighting games are confusong thnx to all who hasve helped!

  6. #3186
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    You could do something like this:

    if number == 1 then
    health = health - 5
    counter:reset(0)
    counter:start()
    end

  7. #3187
    Asleep...
    Points: 11.516, Level: 70
    Level completed: 67%, Points required for next Level: 134
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    1.383
    Points
    11.516
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    i know i did i was just tellin waht i was gonna do i9 did:



    if counter:time() > 4000 then
    mynumber = math.random(1,1000)
    screenrint(30,30,"num".. mynumber,black)
    counter:reset(0)
    counter:start()
    end

    if mynumber == 2 then
    Health = Health - 5
    end
    -= Double Post =-
    damn. while it waits for the timer to laod up to 4000,,, it like subtract 5 every sec of it... sdo im sticking to 1000
    Geändert von N0obKi|l3r.exe (08-12-2006 um 11:57 AM Uhr) Grund: Automerged Doublepost

  8. #3188
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    OK, I just downloaded TTLDE v 2.1. I have tried it using the widows emulator and it works fine. But, when I go into my other program and write "dofile("TTLDE.lua")" in the windows emulator, I get all kinds of errors. But when I run it alone, it works fine. Does anyone know why? And yes, I have all the files in the same directory.
    -= Double Post =-
    Sorry for bumping this so quickly, but I need an answer ASAP.
    Geändert von Access_Denied (08-12-2006 um 08:34 PM Uhr) Grund: Automerged Doublepost

  9. #3189
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    The error names would help immensly ;)

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


  10. #3190
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    Nevermind, I'm done with that problem. But now I need to know, How many images can you load in one script in LuaPlayer?

  11. #3191
    Developer
    Points: 5.650, Level: 48
    Level completed: 50%, Points required for next Level: 100
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    USA, Virginia
    Beiträge
    580
    Points
    5.650
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    Im in need of a little bit of help. Im having problems getting my start menu working the way it should. What im trying to do is, after you press start to bring up the startmenu pressing start again should make it go away.. this can work using the break function to make the start menu go away instead of the whole script but i still need to know what to put to make it use the start button after it has allready been pressed to bring it up. Heres my code.
    Code:
    if pad:start() then
    		while true do
    			screen:clear()
                screen:blit(0,0,board)
    			pad=Controls.read()
    			if pad:up() and oldpad:up()~=pad:up() then
    				sel=sel-1
    			elseif pad:down() and oldpad:down()~=pad:down() then
    				sel=sel+1
    			end
    			if sel<1 then sel=4 end
    			if sel>4 then sel=1 end
    			local choice={"Save","Save & Quit","Quit","Cancel"}
    			local chcol={editcolor,editcolor,editcolor,editcolor}
    			chcol[sel]=selecolor
                screen:blit(190,106,start)
    			screen:print(224,117,choice[1],chcol[1])
    			screen:print(196,127,choice[2],chcol[2])
    			screen:print(224,137,choice[3],chcol[3])
    			screen:print(216,147,choice[4],chcol[4])
    			if pad:cross() then
    				if sel==1 or sel==2 then
    					local file=io.open("./memos/"..field,"w")
    					file:write(field2)
    					file:close()
    				end
    				if sel==2 or sel==3 then
    					goprg = false
    					background=Image.load("./images/background.png")
    					tfread = false
               				end
                                  break
                                  end
    
    			screen.waitVblankStart()
    			screen:flip()
    			oldpad=pad
    		end
    i have got this to work the way i want by simply using

    Code:
    if pad:circle() then
                      break
                      end
    but, circle is not the buton i want to use, its start that i need.

    and another question i have is, how do i make it so pressing circle makes this only select once instead of switching back and forth real fast..

    Code:
    elseif pad:circle() then
              if fieldedit == 1 then fieldedit = 2 
              else                   fieldedit = 1
              end
    what that does it when you press ( and hold ) circle it switches between the two really fast and makes it hard to select. i need to know how to make it only switch once per time your press circle.

  12. #3192
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    Well I don't feel like reading your code, so I won't answer your first question. But I'll answer you second one.

    Put this above your "while true do":

    oldpad = Controls.read()

    Put this under it if you haven't already

    pad = Controls.read()

    Put this after your "screen.flip"

    oldpad = pad

    now change "if pad:circle()" to this

    if pad:circle() and oldpad:circle() ~= pad:circle() then

    This will make it so it only changes once when you press circle.
    -= Double Post =-
    Wait, I know the ansere to your first question. You used the start button in your main loop. But you didn't use it in your pause function. So you can just do this

    if pad:start() then
    break
    end

    But I would replace both of your "if pad:start()" with:

    if pad:start() and oldpad:start() ~= pad:start() then

    Not doing this would make it pause and unpause very quickly.
    Geändert von Access_Denied (08-14-2006 um 09:47 PM Uhr) Grund: Automerged Doublepost

  13. #3193
    QJ Gamer Green
    Points: 13.310, Level: 75
    Level completed: 15%, Points required for next Level: 340
    Overall activity: 0%

    Registriert seit
    Dec 2005
    Ort
    Here
    Beiträge
    2.715
    Points
    13.310
    Level
    75
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Branin
    Im in need of a little bit of help. Im having problems getting my start menu working the way it should. What im trying to do is, after you press start to bring up the startmenu pressing start again should make it go away.. this can work using the break function to make the start menu go away instead of the whole script but i still need to know what to put to make it use the start button after it has allready been pressed to bring it up. Heres my code.
    Code:
    if pad:start() then
    		while true do
    			screen:clear()
                screen:blit(0,0,board)
    			pad=Controls.read()
    			if pad:up() and oldpad:up()~=pad:up() then
    				sel=sel-1
    			elseif pad:down() and oldpad:down()~=pad:down() then
    				sel=sel+1
    			end
    			if sel<1 then sel=4 end
    			if sel>4 then sel=1 end
    			local choice={"Save","Save & Quit","Quit","Cancel"}
    			local chcol={editcolor,editcolor,editcolor,editcolor}
    			chcol[sel]=selecolor
                screen:blit(190,106,start)
    			screen:print(224,117,choice[1],chcol[1])
    			screen:print(196,127,choice[2],chcol[2])
    			screen:print(224,137,choice[3],chcol[3])
    			screen:print(216,147,choice[4],chcol[4])
    			if pad:cross() then
    				if sel==1 or sel==2 then
    					local file=io.open("./memos/"..field,"w")
    					file:write(field2)
    					file:close()
    				end
    				if sel==2 or sel==3 then
    					goprg = false
    					background=Image.load("./images/background.png")
    					tfread = false
               				end
                                  break
                                  end
    
    			screen.waitVblankStart()
    			screen:flip()
    			oldpad=pad
    		end
    i have got this to work the way i want by simply using

    Code:
    if pad:circle() then
                      break
                      end
    but, circle is not the buton i want to use, its start that i need.

    and another question i have is, how do i make it so pressing circle makes this only select once instead of switching back and forth real fast..

    Code:
    elseif pad:circle() then
              if fieldedit == 1 then fieldedit = 2 
              else                   fieldedit = 1
              end
    what that does it when you press ( and hold ) circle it switches between the two really fast and makes it hard to select. i need to know how to make it only switch once per time your press circle.
    to make the circle stop going insanely fast switching between its actions, just put "screen.waitVblankStart(1 0)" at the top of "end". (so its the last thing that the small loop does. thatll work.

    as for pressing start, make the whole code under "if pad:start() then" a function.

    then put:

    Code:
    if pad:start() then
    your-function-name-here()
    end
    and to make it go back, in your new function, put "if pad:start() then break end".

    there you go. : )
    [CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]

  14. #3194
    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

    Can anyone tell me if string.gmatch is implemented in the latest version of LuaPlayer? It doesn't seem to have it in the Windows version.

    (Note that I can't check since I don't have a PSP capable of homebrew. I am just trying to help someone else out).

  15. #3195
    Developer
    Points: 5.650, Level: 48
    Level completed: 50%, Points required for next Level: 100
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    USA, Virginia
    Beiträge
    580
    Points
    5.650
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    Ok, iv tried what you have said but now pressing circle does nothing at all, no errors or a anything.

    Code:
    screen:waitVblankStart(10)
              screen:flip()
              pad = Controls.read()
              elseif pad:circle() and pad:circle() ~= oldpad:circle() then
              if fieldedit == 1 then fieldedit = 2 
              else                   fieldedit = 1
              end
              DisplayScreen()
              screen:waitVblankStart()
              screen:flip()
             else
               screen:waitVblankStart()
            end
          end
        end
      else
        screen:waitVblankStart(10)
      end
    oldpad = pad
    end
    above is the very end of my script.. can anyone tell me why pressing circle does nothing now.

  16. #3196
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    You put this:

    elseif pad:circle() and pad:circle() ~= oldpad:circle() then

    it should be

    elseif pad:circle() and OLDpad:circle() ~= PAD:circle() then

    See the changes?

  17. #3197
    Developer
    Points: 5.650, Level: 48
    Level completed: 50%, Points required for next Level: 100
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    USA, Virginia
    Beiträge
    580
    Points
    5.650
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    same thing bro, still does nothing.

  18. #3198
    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

    Someone else had a similar problem using oldpad:
    [WiP] Assualt - BETA .1

    Zitat Zitat von Access_Denied
    You put this:

    elseif pad:circle() and pad:circle() ~= oldpad:circle() then

    it should be

    elseif pad:circle() and OLDpad:circle() ~= PAD:circle() then

    See the changes?
    Doesn't matter, both lines are logically the same.
    A ~= B is the same as B ~= A

  19. #3199
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    Did you put in this line before your "while true do"?

    oldpad = Controls.read()

  20. #3200
    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

    If he didn't, it would crash since oldpad would be nil.

    Try this:
    Code:
    LastCircleKeyState = false;
    
    while true do
    -- blah blah
    pad = Controls.read();
    
    if pad:circle() then
    if not LastCircleKeyState then
    -- do stuff
    end
    LastCircleKeyState = true;
    else
    LastCircleKeyState = false;
    end
    -- blah blah
    end

  21. #3201
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von head_54us
    Someone else had a similar problem using oldpad:
    [WiP] Assualt - BETA .1


    Doesn't matter, both lines are logically the same.
    A ~= B is the same as B ~= A
    Yes, but sometimes LUA isn't very logical.
    Geändert von Access_Denied (08-15-2006 um 09:33 AM Uhr)

  22. #3202
    Your Fate is Grim...
    Points: 11.640, Level: 70
    Level completed: 98%, Points required for next Level: 10
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    2.269
    Points
    11.640
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    altair: u told me how to find current fps, can u link tell me again?? i cant find the post tat u told me in. thx
    --------------------------------------------------------------------------------------

  23. #3203
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    I think altair is gone. He's coming back, but I think he's on vacation or something.

  24. #3204
    QJ Gamer Green
    Points: 13.310, Level: 75
    Level completed: 15%, Points required for next Level: 340
    Overall activity: 0%

    Registriert seit
    Dec 2005
    Ort
    Here
    Beiträge
    2.715
    Points
    13.310
    Level
    75
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Branin
    Ok, iv tried what you have said but now pressing circle does nothing at all, no errors or a anything.

    Code:
    screen:waitVblankStart(10)
              screen:flip()
              pad = Controls.read()
              elseif pad:circle() and pad:circle() ~= oldpad:circle() then
              if fieldedit == 1 then fieldedit = 2 
              else                   fieldedit = 1
              end
              DisplayScreen()
              screen:waitVblankStart()
              screen:flip()
             else
               screen:waitVblankStart()
            end
          end
        end
      else
        screen:waitVblankStart(10)
      end
    oldpad = pad
    end
    above is the very end of my script.. can anyone tell me why pressing circle does nothing now.
    wheres the first "if"?
    [CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]

  25. #3205
    QJ Gamer Green
    Points: 9.165, Level: 64
    Level completed: 39%, Points required for next Level: 185
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Ort
    England ~¦¦¦|+|¦¦¦~
    Beiträge
    1.112
    Points
    9.165
    Level
    64
    My Mood
    Bored
    Downloads
    0
    Uploads
    0

    Standard

    Whats the best text editor to do lua code in? Im using notepad at the moment but whats the best program that checks your syntax as you type?
    ...Just Returned To The Scene...

  26. #3206
    Developer
    Points: 12.154, Level: 72
    Level completed: 26%, Points required for next Level: 296
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Ort
    Dubuque
    Beiträge
    423
    Points
    12.154
    Level
    72
    My Mood
    Lurking
    Downloads
    1
    Uploads
    0
    PSP Demo Videos (updated 11/29/08)
    MinerPSP Coder

  27. #3207
    QJ Gamer Green
    Points: 9.165, Level: 64
    Level completed: 39%, Points required for next Level: 185
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Ort
    England ~¦¦¦|+|¦¦¦~
    Beiträge
    1.112
    Points
    9.165
    Level
    64
    My Mood
    Bored
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von jsharrad
    this doesnt do lua
    ...Just Returned To The Scene...

  28. #3208
    QJ Gamer Gold
    Points: 22.012, Level: 92
    Level completed: 67%, Points required for next Level: 338
    Overall activity: 0%

    Registriert seit
    Aug 2005
    Beiträge
    4.540
    Points
    22.012
    Level
    92
    Downloads
    0
    Uploads
    0

    Standard

    RAWR -edited-
    Geändert von Urza the Tyrant (08-16-2006 um 04:54 AM Uhr)

  29. #3209
    Developer
    Points: 12.154, Level: 72
    Level completed: 26%, Points required for next Level: 296
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Ort
    Dubuque
    Beiträge
    423
    Points
    12.154
    Level
    72
    My Mood
    Lurking
    Downloads
    1
    Uploads
    0

    Standard

    oops, wrong link :)
    notepad2 again. :P
    PSP Demo Videos (updated 11/29/08)
    MinerPSP Coder

  30. #3210
    QJ Gamer Green
    Points: 9.165, Level: 64
    Level completed: 39%, Points required for next Level: 185
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Ort
    England ~¦¦¦|+|¦¦¦~
    Beiträge
    1.112
    Points
    9.165
    Level
    64
    My Mood
    Bored
    Downloads
    0
    Uploads
    0

    Standard

    how do i make an image move using the arrow keys? my image is called "smiley" so some code would be nice :)
    ...Just Returned To The Scene...


 

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 09:01 PM Uhr.

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