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 |
|
|
| |
|
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
|
  |
| 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 |
|
|
|
| 15 Sep 2011 08:34 PM |
| http://wiki.roblox.com/index.php/Global_Functions |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 15 Sep 2011 08:50 PM |
What swm said
------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 15 Sep 2011 09:13 PM |
_G["onClicked()"] = function(arg1,arg2)
into
_G["onClicked"] = function(arg1,arg2) |
|
|
| Report Abuse |
|
|
|
| 15 Sep 2011 09:14 PM |
| Are you trying to use the function through one script or multiple scripts? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 15 Sep 2011 09:24 PM |
while true do _G["onClicked"]() end
------------------------------------------------------------------------------------------------------------ROBLOX >>>>>>>> MC |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|