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: Is there a "self" command in Lua (like in JavaScript)?

Previous Thread :: Next Thread 
MrSquer is not online. MrSquer
Joined: 18 Feb 2011
Total Posts: 6103
27 May 2015 10:10 AM
Here is the code for the script, because I don't think the forums support indentation: http://prntscr.com/7a0bd1
Report Abuse
Anticodist is not online. Anticodist
Joined: 05 Feb 2014
Total Posts: 1191
27 May 2015 10:13 AM
1. Forums do support indentation now.
2. 'self' for tables is inclusive when setting metatables:

local tab = {some_value, "hi", 123}
setmetatable(tab, {__call = function(self, ...)
local args = {...}
-- etc etc
end})



-𝒩 | Anticodist, Scripter
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 May 2015 10:13 AM
local functionTable = {}

functionTable.Function = function(self, text)
print(self, text)
end)

functionTable:Function("Test")
Report Abuse
Anticodist is not online. Anticodist
Joined: 05 Feb 2014
Total Posts: 1191
27 May 2015 10:13 AM
I misread. Refer to ^



-𝒩 | Anticodist, Scripter
Report Abuse
Anticodist is not online. Anticodist
Joined: 05 Feb 2014
Total Posts: 1191
27 May 2015 10:14 AM
@epic, *end



-𝒩 | Anticodist, Scripter
Report Abuse
MrSquer is not online. MrSquer
Joined: 18 Feb 2011
Total Posts: 6103
27 May 2015 10:15 AM
@epicbreaker So you're saying that "self" must be a parameter of the function? Will that give the core table or the functions table though? I want it to give the "father" table, not the nested one.
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 May 2015 10:15 AM
Oops, thanks.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
27 May 2015 10:15 AM
^

Really...
Was that needed lol. :P
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 May 2015 10:16 AM
It should give the table the function is currently in.
Report Abuse
MrSquer is not online. MrSquer
Joined: 18 Feb 2011
Total Posts: 6103
27 May 2015 10:17 AM
Okay, so then how do I get the "father" table from the nested table?
Report Abuse
Anticodist is not online. Anticodist
Joined: 05 Feb 2014
Total Posts: 1191
27 May 2015 10:17 AM
Just use 'parent'



-𝒩 | Anticodist, Scripter
Report Abuse
Anticodist is not online. Anticodist
Joined: 05 Feb 2014
Total Posts: 1191
27 May 2015 10:18 AM
As the terminology, I meant. He keeps saying 'father.'



-𝒩 | Anticodist, Scripter
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 May 2015 10:21 AM
I'm not sure it's possible.
Report Abuse
MrSquer is not online. MrSquer
Joined: 18 Feb 2011
Total Posts: 6103
27 May 2015 10:22 AM
Here's a visualization of what I want
http://prntscr.com/7a0gtj
Report Abuse
MrSquer is not online. MrSquer
Joined: 18 Feb 2011
Total Posts: 6103
27 May 2015 10:23 AM
MY MISTAKE, THAT'S OLD LINK, give me a minute to get new one
Report Abuse
Anticodist is not online. Anticodist
Joined: 05 Feb 2014
Total Posts: 1191
27 May 2015 10:24 AM
To my knowledge, you can't.



-𝒩 | Anticodist, Scripter
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 May 2015 10:24 AM
You can't.

"return Core" will be the only way.
Report Abuse
MrSquer is not online. MrSquer
Joined: 18 Feb 2011
Total Posts: 6103
27 May 2015 10:26 AM
http://prntscr.com/7a0i3e
Report Abuse
MrSquer is not online. MrSquer
Joined: 18 Feb 2011
Total Posts: 6103
27 May 2015 10:28 AM
Nevermind. I can make a parameter called core, and then outside of the function, call the script and set the argument for core to _G.core.

SOLVED
SOLVED
SOLVED
SOLVED
SOLVED
SOLVED
Report Abuse
Anticodist is not online. Anticodist
Joined: 05 Feb 2014
Total Posts: 1191
27 May 2015 10:30 AM
You could attempt using table.insert



-𝒩 | Anticodist, Scripter
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
27 May 2015 11:21 AM
These idiots are idiots, you shouldn't make self a parameter of the function. You have to create a "method" for this to work:

local tab = {}

function tab:Foo()
print(self==tab)
end

tab:Foo() --> true
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
27 May 2015 11:30 AM
Tables don't know where they're contained because they're passed by reference. If they need to know where they're contained it needs to be set in a key
Methods can be declared as
function tableName:MethodName(...)
-- code; self is implicit
end
or,
tableName.MethodName = function(self,...)
-- code
end
Both of which would be called as tableName:MethodName(...) and self would be passed by the :Syntax
Not really good for anything but classes or __index functions
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
27 May 2015 11:45 AM
^ Luna to the rescue :3
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
27 May 2015 11:46 AM
I already rescued, noob, gtfo.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
27 May 2015 11:48 AM
Did somebody ruin your cornflakes this morning? Also you said they had to be constructed as function t:M(...) which is totally wrong - They don't *have* to be written like that at all.
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