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 » Scripting Helpers
Home Search
 

Re: Global function parameters get switched?

Previous Thread :: Next Thread 
Bannana97 is not online. 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 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
02 Mar 2012 06:45 PM
This is the whole script, right?
Report Abuse
Bannana97 is not online. Bannana97
Joined: 22 Jun 2008
Total Posts: 10215
02 Mar 2012 06:46 PM
Correct.
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
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 is not online. 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 is not online. 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 is not online. Bannana97
Joined: 22 Jun 2008
Total Posts: 10215
02 Mar 2012 06:50 PM
Ah, let me try that.
Report Abuse
Bannana97 is not online. 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
epicfail22 is not online. epicfail22
Joined: 25 Sep 2009
Total Posts: 3739
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
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
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
epicfail22 is not online. epicfail22
Joined: 25 Sep 2009
Total Posts: 3739
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
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
02 Mar 2012 07:02 PM
@epicfail: You wouldn't.
Report Abuse
smurf279 is not online. 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 is not online. 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
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
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 is not online. 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
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
02 Mar 2012 07:16 PM
@smurf: Debatable.
Report Abuse
mrclover is not online. mrclover
Joined: 17 Dec 2011
Total Posts: 1541
02 Mar 2012 07:34 PM
I am confused
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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