As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 03:03 AM |
Hey everybody,
Recently I stumbled across metatables and I have now constructed a ~700 line script, which will be uploaded to the public later today here:
http://www.roblox.com/MetaService-item?id=107807122
I am in a bit of trouble though, because I've tried to make events too, but they're ran in the service-holder due to global tables and such.
_G.somestuff will return a local metatable.
Can I then do something like this: _G.somestuff:connect = function(...) stuff end
Where, from a normal script or such,using ex. _G.somestuff:connect(function pprint(a - w) end)
Will result in THAT script to crash, not mine.
- As, return math.floor(num / (2 ^ x)) % 2 |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 05:04 AM |
Hm, not a single answer. I wonder if SH is dead, or if this is better off at Scripters.
- As, your new encryption service. |
|
|
| Report Abuse |
|
|
777MrEpic
|
  |
| Joined: 17 Oct 2012 |
| Total Posts: 3998 |
|
|
| 27 Feb 2013 06:23 AM |
Hmm I saw _G Tables yesterday Call dat function if u didn't look for spelling. |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 09:00 AM |
hm, what I'm thinking is something like this (I'm back on pc now, so yaaay; also, I added the loadstring part on the run, right now, since I'm unsure what function() print("HI") end() will do.):
--- Script 1 ---
_G.tablestuff:connect = loadstring("function(...) --[[dostuff]] end")
--- Script 2 ---
_G.tablestuff:connect(function() print("Lol, function as argument :3") end)
Which, in the theory would equal to:
loadstring("function(...) --[[dostuff]] end")(function() print("Lol, function as argument :3") end)
---------------- :/
- As, planned features in the next build>s< of MetaInstances: StringCrypter [ Service ] Particle [ Object ] UtilityGui [ Object ] |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2013 10:44 AM |
I'm not sure if you know but, you know you can pass on functions as arguments right?
_G.tablestuff:connect(func) = function() func(arguments) end
_G.tablestuff:connect(function(arguments)
end) |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 11:40 AM |
Hm, tried it out, I seem to get some syntax problems (aka simple output errors)
It doesn't seem like you can do the _G.tablestuff:connect(func) = function() stuff end
-part.
Since, without (func), and putting func in the unnamed function, will result in "function arguments expected near =", and keeping the function argument tag-thing will result in "unexpected symbol near =".
- As, Vigirene, DES, I am a crypting method?! |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 11:50 AM |
Used: _G.lolstuff.ev = function(_, func) func("hello") end -- 1st argument is self, keep in mind.
Now, when running _G.lolstuff:ev(function(a) print(a + 1) end) -- Will error xP
the output WILL still have some connection to the declaration of the function after "Used".
local func method ev _G.lolstuff:ev(function...
- As, can plugins or executed scripts by any chance get it's own source? |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2013 12:06 PM |
Btw don't take my example as a proper example that was just something to guide you. Let's see...
local table = {}
function table.connect(self, func) if type(func) == "function" then local arguments = {"Hello", "there"} func(arguments) end end
function functionA(arguments) print(unpack(arguments)) end
table:connect(functionA)
Tested and worked fine for me. |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 12:13 PM |
Aw, then the user will have to do the unpack-stuff in their functions. 3:
hm, I wonder how roblox have done it then? Probably not Lua xD
- As, why not? Oh... |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2013 12:21 PM |
| Oh that was just an example, let me give it another test without unpack and I doubt they used Lua. |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2013 12:23 PM |
| Works fine without unpack as well, if you want more arguments though you'll obviously have to give more arguments. |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 01:30 PM |
Hm, sorry, I still don't see that it can be used just like events in roblox instances = Eliminate any error track from the script making the "fake" object, in this case, and send them through _G and shared.
Oh, you shouldn't by any chance know how to make an Executed Script or Plugin able to read it's own body/source? So it can be cloned to a LocalScript >_>
I wonder if getfenv() will work (without anything as argument) <<<
- As, We've struck 800 lines of gold! |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 27 Feb 2013 01:58 PM |
| You basically mean that you want "_G metatables?" |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 02:13 PM |
As you can see in the model on the first post (what you call it) on the thread, I am trying to make what is known as "Custom Objects" on wiki.roblox.com.
It is not exactly like "Custom Objects", from the fact that it is more of a "Custom Service" at the moment, providing metatables shared global without any known possibility to break (Test it! >:D)
So.. yeah.. 3: I'd just like the script that try to set the function to that event, as if you did Workspace.Part.Changed:connect(function() print("I AM A FUNCTION SET TO AN EVENT!") end) to break if there was any errors with the function sent to the event-handling functions. And without making it look differently from the normal roblox instances.
- As, I wonder why getfenv() cannot get local variables? ;) Maybe because of the local? |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 02:16 PM |
>>> Another problem (Which may have been posted before):
Goal = Set a LocalScript's Source to the code from a Plugin.
Problem = How?!
- As, the variables above do not work in Roblox, sorry. |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 02:29 PM |
...
Nah...
A quick solution would be to turn the whole script into a string variable and use loadstring on it. Then we still have the whole script declared. Which will have me to switch from string to roblox code every time I want to edit the script... with proper markup.
- As, the person above me is definitely going to join the 20k post club. |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2013 02:29 PM |
| Unless the whole script is a function I don't see any other way to do it. |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2013 02:33 PM |
| That was about the getfenv() method btw. |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 02:34 PM |
Hm... RATEX, how would you pass a function from a server-side script to a LocalScript? o_o
:: Achievement - Globalizing MetaInstances fulfilled! (I guess, I used server.rbxl D:)
- As, * CLICK UPDATE ON THE WORLD ! :O * |
|
|
| Report Abuse |
|
|
einsteinK
|
  |
| Joined: 22 May 2011 |
| Total Posts: 1015 |
|
|
| 27 Feb 2013 02:36 PM |
To create localscripts (or kind of):
O Make a source localscript with this code: repeat wait() until script:findFirstChild("code") loadstring(script.code.Value)()
then do: local s = ScriptHereAbove:clone() s.Parent = player.PlayerGui -- as example local c = Instance.new("StringValue",s) c.Text = "print('Trololo')" -- The "source" c.Name = "code" -- Let the script find it and run it
(This is used a lot by adminscripts, but then with normal scripts)
O Use loadstring in a safe enviroment: function createScript(code) succes, error = ypcall(loadstring(code)) if not succes then print("An error happened: "..error) end end
createScript("print('lol')") |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 02:37 PM |
oh, ok. o_o hmm.
Gotta try then :3
- As, updating world won't work, sorry D: We've got to wait until the next build before we can update the world to Level 2014. |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2013 02:37 PM |
| You could use string values, but I'm afraid that they would be inefficient with long scripts. You can just have 2 scripts anyways. I'm in the middle of a Smite game, I'll collaborate more in a few minutes. |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 27 Feb 2013 02:39 PM |
> Einstein, right now it's structured like this:
Script > LocalScript
You can take the source from the Script and put it into a Plugin (I hope), which would then be able to take it's own source and copy it to a new LocalScript, since plugins is raw Lua, no objects.
I... will... try update the model soon, but I'm afraid it will have bugs. >_> Well, LET'S DO IT!
- As, WHO CAN, MOON CAN! |
|
|
| Report Abuse |
|
|