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 Functions

Previous Thread :: Next Thread 
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 08:17 PM
What can I do to make a function global? I have a function called supplybox(). How can i make this global so I can run it from other functions? Help is appreciated.
Report Abuse
MrSmurfsAlt is not online. MrSmurfsAlt
Joined: 22 Feb 2011
Total Posts: 265
15 Sep 2011 08:24 PM
Use
_G
Report Abuse
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 08:31 PM
how would I type it for the function? Using _G and a function name, how do I combine them to make it a true global function?
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
15 Sep 2011 08:33 PM
_G["Function name"] = function(arg1, arg2)
--body of function
end
Report Abuse
MrSmurfsAlt is not online. MrSmurfsAlt
Joined: 22 Feb 2011
Total Posts: 265
15 Sep 2011 08:34 PM
http://wiki.roblox.com/index.php/Global_Functions
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
15 Sep 2011 08:50 PM
What swm said

------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC
Report Abuse
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 09:02 PM
Now I'm getting this error: http://img641.imageshack.us/img641/3125/errorhelp.png
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
15 Sep 2011 09:04 PM
It seems as is you forgot an end.

P.S. Next time, just copy and paste the output text. You can get banned for posting photo links like that.

------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC
Report Abuse
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 09:09 PM
roblox wouldnt let me post the output text because it posted a security issue to the forums.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
15 Sep 2011 09:11 PM
Just put a space between the inequality signs in "eof", like this:

< eof >

When there's no space, the site thinks you're trying to set HTML coding.

------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC
Report Abuse
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 09:12 PM
ok, i now have the error sorted out. but how do i call a global function. Im adding it to:

while true do
onClicked()
end

and the function I'm trying to run has this on the line:

_G["onClicked()"] = function(arg1, arg2)

what am i missing here? im new to global stuff btw
Report Abuse
izzatnasruna is not online. izzatnasruna
Joined: 09 Jun 2009
Total Posts: 1927
15 Sep 2011 09:13 PM
_G["onClicked()"] = function(arg1,arg2)

into

_G["onClicked"] = function(arg1,arg2)
Report Abuse
MrSmurfsAlt is not online. MrSmurfsAlt
Joined: 22 Feb 2011
Total Posts: 265
15 Sep 2011 09:14 PM
Are you trying to use the function through one script or multiple scripts?
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
15 Sep 2011 09:15 PM
To set it:
_G["onClicked"] = function(arguments)

To load it:
_G["onClicked"]()

------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC
Report Abuse
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 09:23 PM
im on a journey tonight lul error after error. this time i am getting an error saying:

Workspace.genbutton.Script:14: '=' expected near 'end'

Here is the snippet I'm working with (lines 12,13,and 14):

while true do
_G["onClicked"]
end
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
15 Sep 2011 09:24 PM
while true do
_G["onClicked"]()
end

------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC
Report Abuse
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 09:49 PM
did that now i get:

Workspace.genbutton.Script:13: attempt to call field 'onClicked' (a nil value)
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
15 Sep 2011 09:51 PM
Then you didn't set the function properly :P

------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC
Report Abuse
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 09:52 PM
what else do i need on it?

while true do
_G["onClicked"]()
end
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
15 Sep 2011 09:57 PM
You need to set it like this:

_G["onClicked"] = function()
--code
end

Then, to access it from any script, you use this:
_G["onClicked"]()

------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC
Report Abuse
deathw8 is not online. deathw8
Joined: 04 Mar 2008
Total Posts: 102
15 Sep 2011 10:01 PM
hahaha ooooh wow. didnt even need it. ok thanks for the help :p at least i learned something new.
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