Seite 322 von 342 ErsteErste ... 222 272 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 ... LetzteLetzte
Zeige Ergebnis 9.631 bis 9.660 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; Nice TurtlesPwn , i've did it just like this: Code: --table for units unit = {} unit[1] = {x=10,y=10,health=100, exist ...

  
  1. #9631
    QJ Gamer Bronze
    Points: 7.257, Level: 56
    Level completed: 54%, Points required for next Level: 93
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Ort
    B.F.
    Beiträge
    328
    Points
    7.257
    Level
    56
    My Mood
    Psychedelic
    Downloads
    1
    Uploads
    0

    Standard

    Nice TurtlesPwn,
    i've did it just like this:

    Code:
    --table for units
    unit = {}
    unit[1] = {x=10,y=10,health=100, exist = true}
    unit[2] = {x=10,y=10,health=100, exist = true}
    unit[3] = {x=10,y=10,health=100, exist = true}
    
    --counter
    c = 1
    
    
    --main loop
    while true do
    ---
    for i=1,#unit do
    ----
    if unit[i].health<=0 then unit[i].exist = false end --this makes the unit disappear from the screen when dead
    end
    
    --this cleans the sub-table containing the dead unit parameters.
    while c<=#unit do
       if not unit[c].exist then table.remove(unit,c) end
           c=c+1	
    end
    if c>=#unit then c=1 end
    I guess i did it according to what u said before.Anyway, this works fine.



  2. #9632
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    no, that's not what I said, thats one of the worse ways to do it.

    replace
    Code:
    for i=1,#unit do
    ----
    if unit[i].health<=0 then unit[i].exist = false end --this makes the unit disappear from the screen when dead
    end
    
    --this cleans the sub-table containing the dead unit parameters.
    while c<=#unit do
       if not unit[c].exist then table.remove(unit,c) end
           c=c+1	
    end
    if c>=#unit then c=1 end
    with
    Code:
    for i, thisunit in ipairs(unit) do
    	if thisunit.health <= 0 then
    		table.remove(unit,i)
    	end
    end
    [size=3][url=http://luaplayer.org/forums/index.php?topic=507]Complete Lua development cycle outline[/url][/size]

  3. #9633
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    tables in lua don't start at 0?
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  4. #9634
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    no, they start at 1. they're weird....but to me starting at 1 is the more logical way to do it.
    [size=3][url=http://luaplayer.org/forums/index.php?topic=507]Complete Lua development cycle outline[/url][/size]

  5. #9635
    QJ Gamer Bronze
    Points: 5.583, Level: 48
    Level completed: 17%, Points required for next Level: 167
    Overall activity: 0%

    Registriert seit
    May 2007
    Beiträge
    127
    Points
    5.583
    Level
    48
    Downloads
    0
    Uploads
    0

    Standard

    well tables dont naturally index at 0 but you can use 0 as a key foo[0] = "x" will work just fine, as long as you understand the difference between using a table like an array and using it like a dictionary.
    -- Code Monkey : Sarien, Fishguts, Cracks and Crevices --

    "Did IQ's just drop sharply while I was away?" (Ripley)

  6. #9636
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    So i need a bit of help with table.insert().
    I have to variables, mapX, mapY. These are entered by the player. Then i need to insert the starting elements which are(will be) indexed to 0. So i was wondering about how i'd insert that info into a array. MapX is the length, MapY is the height of the array.

  7. #9637
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    table.insert(atable,athin gtoinsert,ifyouwantthepos itionatwhichtoinsertit)
    atable[index] = athingtoinsert
    [size=3][url=http://luaplayer.org/forums/index.php?topic=507]Complete Lua development cycle outline[/url][/size]

  8. #9638
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    I'm still stuck . So i have the table say called 'map'. Then i have this,
    Code:
    for i = 1, MapX do
         for j = 1, MapY do
              table.insert(map, 0);
                   end
           end
    Would that work? (btw thats off the top of my head)

  9. #9639
    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

    Just test it ! You ask way too many questions. I worked out how to use table.insert within two minutes of testing and a bit of printing to the screen. Better yet, look at the DOCUMENTATION.

  10. #9640
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von eldiablov Beitrag anzeigen
    Just test it ! You ask way too many questions. I worked out how to use table.insert within two minutes of testing and a bit of printing to the screen. Better yet, look at the DOCUMENTATION.
    Well i would if i was near a computer but i'm not you see. Otherwise i would. (i'm on my psp) . And i really haven't asked any coding question in a while.

  11. #9641
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    you need to better explain wth it is youre trying to do, because so far youve said ok i have mapx and mapy and you have to guess what exactly those are being used for and now help me with table.insert and also im using some for loops
    [size=3][url=http://luaplayer.org/forums/index.php?topic=507]Complete Lua development cycle outline[/url][/size]

  12. #9642
    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 dan369 Beitrag anzeigen
    I'm still stuck . So i have the table say called 'map'. Then i have this,
    Code:
    for i = 1, MapX do
         for j = 1, MapY do
              table.insert(map, 0);
                   end
           end
    Would that work? (btw thats off the top of my head)
    yes that would create a table full of 0's (not even multi dimensional) which doesnt seem so useful to me XD.
    ------ 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).

  13. #9643
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von TurtlesPwn Beitrag anzeigen
    you need to better explain wth it is youre trying to do, because so far youve said ok i have mapx and mapy and you have to guess what exactly those are being used for and now help me with table.insert and also im using some for loops
    I'm trying to make a initial blank canvas, the player will enter values (MapX, MapY). This would be the size of said canvas. Which should be an array like,
    map = {
    {0,0,0,0,}
    }
    Something like that.

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

    Zitat Zitat von dan369 Beitrag anzeigen
    And i really haven't asked any coding question in a while.
    Your millions of threads on evilmana beg to differ.

  15. #9645
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von dan369 Beitrag anzeigen
    I'm trying to make a initial blank canvas, the player will enter values (MapX, MapY). This would be the size of said canvas. Which should be an array like,
    map = {
    {0,0,0,0,}
    }
    Something like that.
    just make the tables manually dont bother with insert
    Code:
    for i = 1, mapY do
    	map[i] = {}
    	for j = 1, mapX do
    		map[i][j] = 0
    	end
    end
    [size=3][url=http://luaplayer.org/forums/index.php?topic=507]Complete Lua development cycle outline[/url][/size]

  16. #9646
    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

    Zitat Zitat von dan369 Beitrag anzeigen
    map = {
    {0,0,0,0,}
    }
    Something like that.

    A two dimensional array? No.

    Something like this:
    Code:
    map = {
    	{0,0,0,0},
    	{0,0,0,0},
    	{0,0,0,0},
    	{0,0,0,0}
    }

  17. #9647
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von TurtlesPwn Beitrag anzeigen
    just make the tables manually dont bother with insert
    Code:
    for i = 1, mapY do
    	map[i] = {}
    	for j = 1, mapX do
    		map[i][j] = 0
    	end
    end
    Would that make the two-dimensional array?

    @Nielkie, yeah i kinda rushed my little example

    My last question, how would i write that array to a file?

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

    Umm...
    Code:
    for i = 1, mapY do
    	for j = 1, mapX do
    		file:write(map[i][j])
    	end
    end

  19. #9649
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    Thanks nielkie
    -=Double Post Merge =-
    Zitat Zitat von eldiablov Beitrag anzeigen
    Your millions of threads on evilmana beg to differ.
    Check the dates. I might have 'millions' of threads but it's not a crime to ask for a couple of questions/suggestions. You do know this is the Lua programming Help thread. You don't have to help anyone u know. Anyway i tried to test the output and the gd news is that it writes 0 to the .txt file. But it is no array there is no map = {
    {0,0,0,0,0},
    {0,0,0,0,0},
    {0,0,0,0,0}
    }
    it is just a huge row of 0
    Geändert von dan369 (01-08-2009 um 08:36 AM Uhr) Grund: Automerged Doublepost

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

    Well obviously... you'll have to read the map back in...
    Code:
    for i = 1, mapY do
    	for j = 1, mapX do
    		map[i][j] = file:read(1)
    	end
    end
    Though this is just a guide. You'll also have to store and read back the dimensions of the map. Of course, you'll have to create a more advanced way of storing each number, or what ever data type you choose to store in the array, so that each one is the same length in the file. I suggest 8-bit integers.

  21. #9651
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    Could i just use this?

  22. #9652
    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

    i dont know can you use a function? you tell me!
    ------ 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. #9653
    QJ Gamer Blue
    Points: 4.008, Level: 40
    Level completed: 29%, Points required for next Level: 142
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Ort
    dfgd
    Beiträge
    66
    Points
    4.008
    Level
    40
    Downloads
    0
    Uploads
    0

    Talking

    Zitat Zitat von FaT3oYCG Beitrag anzeigen
    i dont know can you use a function? you tell me!
    ROFL

    Dan, experiment dude find things out for yourself, then if your still stuck then ask questions but thats just my opinion.
    Anyway to the point, a while ago i created a little Lua file from which you could create a table of values and save that said table to a .lua file and then you could load that table from that said file.
    You'll get what i mean better when you actually see it, i'm not guaranteeing that is the most brilliant thing ever but it would help you get a leg up on what you are trying to do and hey every little helps.

    http://www.megaupload.com/?d=2OQN2WD5

    P.S i created this about 1 year ago . . . , Oh if you ever need a tile map i have one you could use, just give me a PM if you ever need it or help for that matter.

  24. #9654
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von FaT3oYCG Beitrag anzeigen
    i dont know can you use a function? you tell me!
    Ok, i should of been a bit more exact. I meant would it do what i want? Save a 2d array to a file, that's what i meant.

    @Luke, i'd like to take a look at your example, but megaupload doesn't work for me . Though thanks, if say you could host on a site like sendspace, it would be grateful

    Though lots of MapEditors have used that table.save() function, though i saw the output in a file and it wasn't the output i was hoping for, so that got my curious on the output hense why i asked the question,

  25. #9655
    QJ Gamer Blue
    Points: 4.008, Level: 40
    Level completed: 29%, Points required for next Level: 142
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Ort
    dfgd
    Beiträge
    66
    Points
    4.008
    Level
    40
    Downloads
    0
    Uploads
    0

    Talking

    Zitat Zitat von dan369 Beitrag anzeigen
    Ok, i should of been a bit more exact. I meant would it do what i want? Save a 2d array to a file, that's what i meant.

    @Luke, i'd like to take a look at your example, but megaupload doesn't work for me . Though thanks, if say you could host on a site like sendspace, it would be grateful

    Though lots of Map Editors have used that table.save() function, though i saw the output in a file and it wasn't the output i was hoping for, so that got my curious on the output hense why i asked the question,
    Of course i can Dan, here's the link . . .
    http://www.sendspace.com/file/kh1bwr

    hope this helps you with loading tables from a file.
    Geändert von lukespalding (01-09-2009 um 02:17 AM Uhr)

  26. #9656
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    Thanks Luke

  27. #9657
    QJ Gamer Blue
    Points: 4.008, Level: 40
    Level completed: 29%, Points required for next Level: 142
    Overall activity: 0%

    Registriert seit
    Dec 2007
    Ort
    dfgd
    Beiträge
    66
    Points
    4.008
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von dan369 Beitrag anzeigen
    Thanks Luke
    Your Welcome!

  28. #9658
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von dan369 Beitrag anzeigen
    Would that make the two-dimensional array?


    look at the code

    make up a number for mapX and mapY, lets make each of them = 3

    now run through the forloops in your head

    and see what it makes

    alternatively you could get something like TTLDE and test simple stuff on the psp on your own. or quit complaining that you're on your psp, because that really isn't any of our problems and if you can't test things out you shouldn't be asking for help.
    [size=3][url=http://luaplayer.org/forums/index.php?topic=507]Complete Lua development cycle outline[/url][/size]

  29. #9659
    Lua guy
    Points: 11.690, Level: 71
    Level completed: 10%, Points required for next Level: 360
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Ort
    Wales, cardiff
    Beiträge
    1.442
    Points
    11.690
    Level
    71
    My Mood
    Blah
    Downloads
    0
    Uploads
    0

    Standard

    I've done it now. At that moment in time, i was on my psp.

  30. #9660
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von dan369 Beitrag anzeigen
    I've done it now. At that moment in time, i was on my psp.
    this is my point. dont keep asking questions that can be answered by testing simply because you arent able to test. wait until you can, try stuff out, and then if you still dont get it, ask.
    [size=3][url=http://luaplayer.org/forums/index.php?topic=507]Complete Lua development cycle outline[/url][/size]


 

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 .