1) What does the "gadget:" gadget:MyFunction() do?
2) I have a function in my gadget I want other gadgets to have acess, I am trying to reduce code redundancy. I see that I can use sendtounsynced calls across gadgets, what about functions within synced?
Lua questions
Moderator: Moderators
Re: Lua questions
Bit confused but are you talking about the declaration or invocation?smoth wrote:1) What does the "gadget:" gadget:MyFunction() do?
Calling gadget:MyFunction() without any arguments is probably wrong, don't you need the gadget "object" to invoke it on? f.e: myGadget:MyFunction() or gadget.MyFunction(myGadget)? It may also have problems with scope if called from other gadgets - I don't think gadget:MyFunction() is globally defined, and it's probably ill advised to "VFS:Include" one gadget into another.
Again, I'm a bit confused if what you're trying to do is anything more than having a simple function invocation, but just having that function defined in other files. How is it different than2) I have a function in my gadget I want other gadgets to have acess, I am trying to reduce code redundancy. I see that I can use sendtounsynced calls across gadgets, what about functions within synced?
https://github.com/gajop/Toolbox/blob/m ... r.lua#L120 , is the function defined as a "method" in a gadget - does it really need to be a method?
Thing to pay attention to is that the errors produced in the called function would crash the invoking gadget if left uncaught, and not the "gadget" where the function was defined.
Re: Lua questions
i removed this part. -kaisersmoth wrote:1) What does the "gadget:" gadget:MyFunction() do?
These all are basically the same things:
function gadget:GameFrame(n) end
function gadget.GameFrame(self, n) end
gadget.GameFrame = function(self, n) end
gadget['GameFrame'] = function(self, n) end
There is many ways to do it. One of the easiest is to use a global table like GG.smoth wrote: 2) I have a function in my gadget I want other gadgets to have acess, I am trying to reduce code redundancy. I see that I can use sendtounsynced calls across gadgets, what about functions within synced?
Re: Lua questions
http://www.lua.org/pil/16.html will help you understand the colon operator.
But as Pako rudely suggests, it calls a function with the object itself as the first argument. The 'gadget' object is basically the object created by the gadgethandler upon loading this particular.. gadget.
https://github.com/spring/spring/blob/d ... s.lua#L392
WRT #2, I agree with Pako, I'd use GG.
Example # 1: Lus Helper Gadget from BTL
Example #2: Custom Command ID Generator from S44
But as Pako rudely suggests, it calls a function with the object itself as the first argument. The 'gadget' object is basically the object created by the gadgethandler upon loading this particular.. gadget.
https://github.com/spring/spring/blob/d ... s.lua#L392
WRT #2, I agree with Pako, I'd use GG.
Example # 1: Lus Helper Gadget from BTL
Example #2: Custom Command ID Generator from S44
Re: Lua questions
ah ok, thanks floz. Isn't gg bad? IIRC JK/zever have advocated other methods.
I am not too bothered by pako, it is how he talks to people at least he is trying to give me info. Forb, if I was upset I can report pako but I am not.
I am not too bothered by pako, it is how he talks to people at least he is trying to give me info. Forb, if I was upset I can report pako but I am not.
Re: Lua questions
Link related: http://answers.springlobby.info/questio ... created-it
I don't know of any issues with GG but I'm not an expert.
I don't know of any issues with GG but I'm not an expert.
Re: Lua questions
oh, I did the code and it worked but I was worried I was building bad code 

Re: Lua questions
what's so special with "GG" other than being used often?
wouldn't it make more sense to create your own table if you don't want to pollute the global namespace?
wouldn't it make more sense to create your own table if you don't want to pollute the global namespace?
Re: Lua questions
It's shared amongst all gadgets.
Otherwise gadgets get their own environnment.
Otherwise gadgets get their own environnment.