NOOB forum?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

NOOB forum?

Post by the underminer »

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: Select all

-- sorting test

function sorteren(a,b)
if a<b then
return false
else
return true
end
end

table = &#123;&#125;
table&#91;1&#93; = 3
table&#91;2&#93; = 1
table&#91;3&#93; = 2

table.sort&#40;table,sorteren&#40;table&#91;i&#93;,table&#91;i+1&#93;&#41;&#41;
Behold! The Underminer got hold of a PSP
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Re: NOOB forum?

Post by romero126 »

the underminer wrote: Can anyone help me out?

Code: Select all

-- sorting test

function sorteren&#40;a,b&#41;
if a<b then
return false
else
return true
end
end

table = &#123;&#125;
table&#91;1&#93; = 3
table&#91;2&#93; = 1
table&#91;3&#93; = 2

table.sort&#40;table,sorteren&#40;table&#91;i&#93;,table&#91;i+1&#93;&#41;&#41;
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: Select all

data = &#123;2,1,3&#125;
table.sort&#40;data, function&#40;table1,table2&#41; return table1>table2 end&#41;
Another thing you might want to look into is sub arrays.

Code: Select all

data = &#123;
     &#91;"blah1"&#93; = &#123; "random", 32, "miscdata" &#125;
     &#91;"blah2"&#93; = &#123; "random", 12, "miscdata" &#125;
     &#91;"blah3"&#93; = &#123; "random", 64, "miscdata" &#125;
&#125;
table.sort&#40;data, function&#40;table1,table2&#41; return table1&#91;2&#93;>table2&#91;2&#93; end&#41;
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. :-)
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

Post by the underminer »

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
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

Post by the underminer »

T-riffic! even sorts out text alphabetically! superb. thnx again
Behold! The Underminer got hold of a PSP
User avatar
illfoundedmind
Posts: 22
Joined: Thu Nov 24, 2005 10:03 am
Location: N/A
Contact:

Post by illfoundedmind »

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 StudioImage
modsyn
Posts: 28
Joined: Tue Sep 27, 2005 6:02 am

Post by modsyn »

from http://www.lua.org/manual/5.0/manual.html#predefined
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).
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

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.
User avatar
illfoundedmind
Posts: 22
Joined: Thu Nov 24, 2005 10:03 am
Location: N/A
Contact:

Post by illfoundedmind »

Just wanted to make sure,

Thanks
illfoundedmind Production StudioImage
Post Reply