EgoMoose
|
  |
| Joined: 04 Feb 2009 |
| Total Posts: 2896 |
|
|
| 08 Aug 2015 05:45 PM |
Basically my main question is if it's possible to somehow have a table return or set one of it's values called without indexing it, so only using the table variable as reference. The main purpose of this would be to allow myself to use methods on single values.
So ideally I'd want to be able to do something like this:
local t = {value = 10;}
function t:randomMethod() print("Bob's your uncle") end
print(t) --> 10 t = 13 print(t) --> 13 t:randomMethod() --> Bob's your uncle
However, I want t to remain a table, so it returns t.value, but when I set t = x It's actually updating t.value = x. There very well may not be a solution but I figure I'd better ask. |
|
|
| Report Abuse |
|
|
Funse
|
  |
| Joined: 11 Jun 2012 |
| Total Posts: 7887 |
|
|
| 08 Aug 2015 05:48 PM |
local t = {} t.value = 10
local t:randomMethod() = function() print("s") end
print(t.value) t.value = 13 print(t.value) t:randomMethod() |
|
|
| Report Abuse |
|
|
EgoMoose
|
  |
| Joined: 04 Feb 2009 |
| Total Posts: 2896 |
|
|
| 08 Aug 2015 06:08 PM |
| I know you can do that, but I'm specifically wondering about my above question. |
|
|
| Report Abuse |
|
|
EgoMoose
|
  |
| Joined: 04 Feb 2009 |
| Total Posts: 2896 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 08 Aug 2015 06:37 PM |
yay my with module works here (although your table must be global): http://www.roblox.com/CntKillMes-With-Module-item?id=252348051
require(workspace.MainModule)();
t = {t = 10;} function t:randomMethod() print("Bob's your uncle") end with2(t) do print(t); t = 13; print(t); self:randomMethod(); end with2(); |
|
|
| Report Abuse |
|
|