| View previous topic :: View next topic |
| Author |
Message |
CT_Bolt
Joined: 04 Mar 2006 Posts: 14 Location: Computer Chair
|
Posted: Wed Mar 08, 2006 3:31 am Post subject: Assign a function to a Table??? |
|
|
Well... Hello my fellow PSP Lua coders... OK so I know it's posible to create a table with a function, I just don't know exactlly how to do what I need to do, which is:
1. I am creating a ScrollingCanvas table and I want to assign the function 'Move' to the table, to move the picture(canvas) around the screen using the tables position data (X, Y).
2. The question for you is: How do I create the table, so I can call the move method like this: | Code: | | AScrollingCanvas:Move(X, Y) |
Please Help.
PS. If I didn't give enough information, plz just PM me. |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Wed Mar 08, 2006 4:07 am Post subject: |
|
|
| Code: |
function foo()
print "foo"
end
function bar()
print "bar"
end
my = {f=foo, b=bar} -- by named keys
my.f()
my.b()
-- OR
my = {foo, bar} -- by indices
my[1]()
my[2]()
|
Is this what you wanted to know? _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
CT_Bolt
Joined: 04 Mar 2006 Posts: 14 Location: Computer Chair
|
Posted: Wed Mar 08, 2006 5:34 am Post subject: Not quite... |
|
|
Well... I actually knew how to do that(I have pretty good knowledge of Lua now) but, Thank you for replying.
The basic difference between what you have showed me and what I mean is I need to use values from 'AScrollCanvas' ( X & Y ) and then change them accordingly (change only the current table's X & Y values).
Although I might use that way, do you understand what I mean now?
Oh B-T-W Thanks anyway for you're help!!! |
|
| Back to top |
|
 |
|