generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Table stuff

Previous Thread :: Next Thread 
DevVince is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
vectorGunner is not online. vectorGunner
Joined: 23 Mar 2014
Total Posts: 784
04 Mar 2015 04:06 AM
Just put functions into the table?

table = { }

function table.functionName(parameters)
end

table.functionName(parameters)
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
04 Mar 2015 04:08 AM
local Table = {MethodName = function(Self) print(Self.MethodName) end}

Table:MethodName()


:D
Report Abuse
DevVince is not online. 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
vectorGunner is not online. vectorGunner
Joined: 23 Mar 2014
Total Posts: 784
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
vectorGunner is not online. vectorGunner
Joined: 23 Mar 2014
Total Posts: 784
04 Mar 2015 04:12 AM
'items name is found' what is item?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
04 Mar 2015 04:12 AM
I wasn't trying to 1up you, I was trying to look cooler than you.
Report Abuse
DevVince is not online. 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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
04 Mar 2015 04:25 AM
:D
Report Abuse
DevVince is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
vectorGunner is not online. vectorGunner
Joined: 23 Mar 2014
Total Posts: 784
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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
vectorGunner is not online. vectorGunner
Joined: 23 Mar 2014
Total Posts: 784
04 Mar 2015 04:42 AM
OOP isn't directly supported in lua so get out of here with your terminology!
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
04 Mar 2015 04:43 AM
MoonScript FTW
Report Abuse
DevVince is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
04 Mar 2015 04:44 AM
And it isn't "terminology", it is nomenclature.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image