| View previous topic :: View next topic |
| Author |
Message |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Sat Dec 24, 2005 7:54 pm Post subject: NOOB forum? |
|
|
I consider myself to be a noob and I have a lot of rather basic questions.
Is there a special place on the forum were we ,noobs, can go? I don't want to annoy you guys, see :-)
While we're at it, I was sorting out the table.sort finction. And I don't get it.
Can anyone help me out?
| Code: |
-- sorting test
function sorteren(a,b)
if a<b then
return false
else
return true
end
end
table = {}
table[1] = 3
table[2] = 1
table[3] = 2
table.sort(table,sorteren(table[i],table[i+1])) |
_________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Sun Dec 25, 2005 4:57 am Post subject: Re: NOOB forum? |
|
|
| the underminer wrote: |
Can anyone help me out?
| Code: |
-- sorting test
function sorteren(a,b)
if a<b then
return false
else
return true
end
end
table = {}
table[1] = 3
table[2] = 1
table[3] = 2
table.sort(table,sorteren(table[i],table[i+1])) |
|
This is my favorite time to let you know your doing everything all wrong.
Isnt that fun :-)
First problem. You are defining table as a table. When table is a function command list. (So if you use table.sort it will error out) instead try something like "data" or test..
instead of trying to call your own custom function to use a sort method.
All you require is something simpler. Here lets try this.
| Code: |
data = {2,1,3}
table.sort(data, function(table1,table2) return table1>table2 end)
|
Another thing you might want to look into is sub arrays.
| Code: |
data = {
["blah1"] = { "random", 32, "miscdata" }
["blah2"] = { "random", 12, "miscdata" }
["blah3"] = { "random", 64, "miscdata" }
}
table.sort(data, function(table1,table2) return table1[2]>table2[2] end)
|
Thats right its that simple.
Heres what I did there.
I used an indexed table (table.sort works on any type of table)
Sub tables are refered to by keys in that case id i was refering to sort it was on the second index (so if there is no id(#=) then you can refer to it by its location based on last placed.
If you have any other questions feel free to post. :-) |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Mon Dec 26, 2005 2:00 am Post subject: |
|
|
Wow, that's quite an elaborate answer romero!
All a noob could ever wish for. (A ferrari in my garage would be nice too, but that's another thing.) Thnx _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Mon Dec 26, 2005 2:12 am Post subject: |
|
|
T-riffic! even sorts out text alphabetically! superb. thnx again _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
illfoundedmind

Joined: 24 Nov 2005 Posts: 22 Location: N/A
|
Posted: Thu Jan 05, 2006 5:03 am Post subject: |
|
|
Thought this was a n00b question so I'll ask it here
I was wondering if there is a way to "unload" an image (maybe set the
varible to a number instead of that image) or is there no need to (Lua does cache the image files and it does take up processing power unless BLITed)? _________________ illfoundedmind Production Studio |
|
| Back to top |
|
 |
modsyn
Joined: 27 Sep 2005 Posts: 28
|
Posted: Thu Jan 05, 2006 5:16 am Post subject: |
|
|
from http://www.lua.org/manual/5.0/manual.html#predefined
| Quote: | collectgarbage ([limit])
Sets the garbage-collection threshold to the given limit (in Kbytes) and checks it against the byte counter. If the new threshold is smaller than the byte counter, then Lua immediately runs the garbage collector (see 2.9). If limit is absent, it defaults to zero (thus forcing a garbage-collection cycle). |
|
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Thu Jan 05, 2006 7:40 am Post subject: |
|
|
| illfoundedmind wrote: | Thought this was a n00b question so I'll ask it here
I was wondering if there is a way to "unload" an image (maybe set the
varible to a number instead of that image) or is there no need to (Lua does cache the image files and it does take up processing power unless BLITed)? |
Variable = nil
Which removes the variable from existance. |
|
| Back to top |
|
 |
illfoundedmind

Joined: 24 Nov 2005 Posts: 22 Location: N/A
|
Posted: Fri Jan 06, 2006 2:10 am Post subject: |
|
|
Just wanted to make sure,
Thanks _________________ illfoundedmind Production Studio |
|
| Back to top |
|
 |
|