Bannana97
|
  |
| Joined: 22 Jun 2008 |
| Total Posts: 10215 |
|
|
| 02 Mar 2012 06:36 PM |
For some strange reason, my args for this global function get switched around:
_G.Funcs = {} Funcs.Lol = function(arg1, arg2) -- arg1 should be a string, arg2 a number. print(arg1) print(arg2) end
When I call it in another script, for some odd reason, arg2 becomes arg1 and arg1 becomes arg2:
_G.Funcs.Lol("hi", 5) > 5 > hi |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 02 Mar 2012 06:45 PM |
| This is the whole script, right? |
|
|
| Report Abuse |
|
|
Bannana97
|
  |
| Joined: 22 Jun 2008 |
| Total Posts: 10215 |
|
| |
|
|
| 02 Mar 2012 06:48 PM |
I may be a bit rusty here, but do you not have to assign the function using "_G.Funcs.whatever"?
Other than that, though, I see nothing that would cause that :l |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 02 Mar 2012 06:48 PM |
> _G.Funcs = {} Funcs.Lol
You must have made the function twice. _G.Funcs.Lol~=Funcs.Lol |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 02 Mar 2012 06:49 PM |
| Dang it crazy, beat me by a second |
|
|
| Report Abuse |
|
|
Bannana97
|
  |
| Joined: 22 Jun 2008 |
| Total Posts: 10215 |
|
| |
|
Bannana97
|
  |
| Joined: 22 Jun 2008 |
| Total Posts: 10215 |
|
|
| 02 Mar 2012 06:51 PM |
Nope, the script is different. Here is the actual script, sorry. :/
local Library = {} Library.Out = function(txt, num) wait(num) print(txt) end
_G.Library = Library
In the other script:
_G.Library:Out("Hi", 2) Output says that num is a string, not an int.
|
|
|
| Report Abuse |
|
|
|
| 02 Mar 2012 06:55 PM |
| I don't think you can use it as a method. do _G.Library.Out("Hi",2) |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2012 06:55 PM |
"_G.Library:Out("Hi", 2)" "Library:Out" ":Out" ":"
lrn2method
When you call a method with a colon, it passes the 'self' parameter automatically - the first parameter of the method is the object that the method was called on.
You either need to call it as a member function (just use a '.' to index it), add a 'self' parameter so that the parameter list works with how you're calling it, or define it as a method (using a colon), which will make the 'self' parameter implied, and will add a variable 'self' to the function's enviroment whenever it's called as a method. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2012 06:59 PM |
Ohhh. I never really got methods. So how would I go about doing something like-
Part = Workspace.Part
Rename = function(self,newName) print("Renaming "..self.Name.." to "..newName) self.Name = newName end
Part:Rename("Hello") |
|
|
| Report Abuse |
|
|
| |
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 02 Mar 2012 07:04 PM |
@epic u got to use cool metatables for stuff like that |
|
|
| Report Abuse |
|
|
Bannana97
|
  |
| Joined: 22 Jun 2008 |
| Total Posts: 10215 |
|
|
| 02 Mar 2012 07:07 PM |
| So to each function, I must add 'self' as the first parameter, then that self is the table I am using for the method? Cool. :O |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2012 07:09 PM |
Well, if you call it as a method, then yes.
However, it would be much simpler to just call it as a function ( _G.Library.Out("hi", 5) ). If you insist on calling it as a method, though, nothing is stopping you. |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 02 Mar 2012 07:11 PM |
^
*Calling it with a colon.
_G.Library.Out & _G.Library:Out are both methods |
|
|
| Report Abuse |
|
|
| |
|
mrclover
|
  |
| Joined: 17 Dec 2011 |
| Total Posts: 1541 |
|
| |
|