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 ...
-
01-05-2009, 06:05 AM #9631QJ Gamer Bronze

- Registriert seit
- Dec 2007
- Ort
- B.F.
- Beiträge
- 328
- Points
- 7.257
- Level
- 56
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Nice TurtlesPwn,
i've did it just like this:
I guess i did it according to what u said before.Anyway, this works fine.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
-
01-06-2009, 07:23 AM #9632QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
no, that's not what I said, thats one of the worse ways to do it.
replace
withCode: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
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]
-
01-06-2009, 05:14 PM #9633QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
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
-
01-06-2009, 06:14 PM #9634QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
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]
-
01-07-2009, 05:37 AM #9635
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)
-
01-07-2009, 12:46 PM #9636Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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.
-
01-07-2009, 02:53 PM #9637QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
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]
-
01-07-2009, 03:04 PM #9638Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
I'm still stuck
. So i have the table say called 'map'. Then i have this,
Would that work? (btw thats off the top of my head)Code:for i = 1, MapX do for j = 1, MapY do table.insert(map, 0); end end
-
01-07-2009, 03:06 PM #9639Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
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.
-
01-07-2009, 03:18 PM #9640Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
-
01-07-2009, 03:33 PM #9641QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
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]
-
01-07-2009, 03:38 PM #9642Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-08-2009, 12:10 AM #9643Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
-
01-08-2009, 12:47 AM #9644Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
-
01-08-2009, 06:16 AM #9645QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
-
01-08-2009, 06:55 AM #9646QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
-
01-08-2009, 07:03 AM #9647Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
-
01-08-2009, 07:15 AM #9648QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Umm...
Code:for i = 1, mapY do for j = 1, mapX do file:write(map[i][j]) end end
-
01-08-2009, 08:06 AM #9649Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Thanks nielkie

-=Double Post Merge =-
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 0Geändert von dan369 (01-08-2009 um 08:36 AM Uhr) Grund: Automerged Doublepost
-
01-08-2009, 09:27 AM #9650QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Well obviously... you'll have to read the map back in...
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.Code:for i = 1, mapY do for j = 1, mapX do map[i][j] = file:read(1) end end
-
01-08-2009, 11:14 AM #9651Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Could i just use this?
-
01-08-2009, 11:33 AM #9652Developer 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 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).
-
01-08-2009, 12:26 PM #9653QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- dfgd
- Beiträge
- 66
- Points
- 4.008
- Level
- 40
- Downloads
- 0
- Uploads
- 0
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.
-
01-08-2009, 12:59 PM #9654Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Ok, i 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,
-
01-08-2009, 01:12 PM #9655QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- dfgd
- Beiträge
- 66
- Points
- 4.008
- Level
- 40
- Downloads
- 0
- Uploads
- 0
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)
-
01-08-2009, 01:40 PM #9656Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Thanks Luke
-
01-08-2009, 01:47 PM #9657QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- dfgd
- Beiträge
- 66
- Points
- 4.008
- Level
- 40
- Downloads
- 0
- Uploads
- 0
-
01-08-2009, 03:41 PM #9658QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
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]
-
01-08-2009, 04:17 PM #9659Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
I've done it now. At that moment in time, i was on my psp.
-
01-08-2009, 04:21 PM #9660QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
[size=3][url=http://luaplayer.org/forums/index.php?topic=507]Complete Lua development cycle outline[/url][/size]


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