forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

NOOB forum?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Sat Dec 24, 2005 7:54 pm    Post subject: NOOB forum? Reply with quote

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
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Sun Dec 25, 2005 4:57 am    Post subject: Re: NOOB forum? Reply with quote

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
View user's profile Send private message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Mon Dec 26, 2005 2:00 am    Post subject: Reply with quote

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
View user's profile Send private message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Mon Dec 26, 2005 2:12 am    Post subject: Reply with quote

T-riffic! even sorts out text alphabetically! superb. thnx again
_________________
Behold! The Underminer got hold of a PSP
Back to top
View user's profile Send private message
illfoundedmind



Joined: 24 Nov 2005
Posts: 22
Location: N/A

PostPosted: Thu Jan 05, 2006 5:03 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
modsyn



Joined: 27 Sep 2005
Posts: 28

PostPosted: Thu Jan 05, 2006 5:16 am    Post subject: Reply with quote

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
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Thu Jan 05, 2006 7:40 am    Post subject: Reply with quote

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
View user's profile Send private message
illfoundedmind



Joined: 24 Nov 2005
Posts: 22
Location: N/A

PostPosted: Fri Jan 06, 2006 2:10 am    Post subject: Reply with quote

Just wanted to make sure,

Thanks
_________________
illfoundedmind Production Studio
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group