DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:04 AM |
Can I put code into a table?
Like:
--Tried this in studio but the code has a red line under it. Table = {
{'Script1', --Code },
{'Script2', --Code },
{'Script3', --Code },
}
Table.Script1[2]--Run script one :D |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:05 AM |
| Well you can put functions in the table... Not code though. You could also put strings, and load them with Loadstring, but that doesn't work in LocalScripts. |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:06 AM |
Just put functions into the table?
table = { }
function table.functionName(parameters) end
table.functionName(parameters) |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:08 AM |
local Table = {MethodName = function(Self) print(Self.MethodName) end}
Table:MethodName()
:D |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:10 AM |
Whoops, setup the table wrong.
Table = {
Script1 = { --Code },
Script2 = { --Code },
Script3 = { --Code },
}
But yea i'm using the script 1,2,3 as if statements kind of. If the items name is found inside the table then it'll run the code within the table for that name. Another way to do this? |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:10 AM |
| He just wants to fire "code" from other sections of the script okay? stop trying to 1up me! |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:12 AM |
| 'items name is found' what is item? |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:12 AM |
| I wasn't trying to 1up you, I was trying to look cooler than you. |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:17 AM |
That totally wasn't a late post. Also I do like the way Jarod said better. :3
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:19 AM |
No longer need the if statement now I can just make it find the function in the table. :DD
local Table = {
MethodName = function(Self) print(Self.MethodName) end ,
MethodName2 = function(Self) print(Self.MethodName) end ,
MethodName3 = function(Self) print(Self.MethodName) end ,
}
Table:MethodName2() |
|
|
| Report Abuse |
|
|
| |
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:32 AM |
Question,
When printing method name how do I print the name of it cause it's printing the table name.
MethodName = function(Self) print(Self.MethodName) end ,
}
Table:MethodName()
I want it to be printing the function name if possible, how would I do that? |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:35 AM |
The code I did was just an example. I really recommend you don't use methods unless you are doing OOP stuff, and know how methods work. Since you only want to store code, I think you should really just use functions.
Table = {FunctionName = function() print(5) end}
Table.FunctionName() |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:38 AM |
That is how methods work. The method is really usually used for using tables for... psuedo instances.
So like Part:Destroy() Destroy is the method for part.
Part = { Size = Vector3.new(1,1,1) Destroy = function(Self) print(Self.Size.x) end };
That is why I suggested functions instead.
Hope this helped in your understanding of how methods work.
P.S.Destroy doesn't really print size or anything, just showing an example of how you would create a pseudo instance and access variables in the instance for the method with things you know ( like part properties / methods ). |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:39 AM |
Gimmie wiki link so I can understand how to use this better?
Or something.. I want to use the functions name for something inside of the code so I don't have to copy and paste the function name myself so it's automatically there. |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:41 AM |
"psuedo instances." Uhh, they are used for classes, which are in 99 of 100 cases NOT pseudo-instances. |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:42 AM |
Well... I'm using it to change values and run other functions... >_> |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:42 AM |
| OOP isn't directly supported in lua so get out of here with your terminology! |
|
|
| Report Abuse |
|
|
| |
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:44 AM |
| Entered in psuedo instances and got nothing on the wiki. O.o? |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:44 AM |
| And it isn't "terminology", it is nomenclature. |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2015 04:45 AM |
You should have searched "Classes" or "OOP" on the wiki. It would be even better to do it on Google: "site:wiki.roblox.com OOP" |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 04 Mar 2015 04:48 AM |
:o I like how you can use this, i'm going to use this more often.:) |
|
|
| Report Abuse |
|
|