Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to call a global function in another script?

Asked by 10 years ago

Alright, so I've been looking for the answer to this question for a while, but never found it. What I want to do is have all my Functions and Variables in one script then be able to call then in a different script.

For example:

_G.BaseScriptName.GlobalFunction = function(Args)
    -- CODE HERE
end

Then I want to be able to call it in a different script like:

_G.BaseScriptName.GlobalFunction(Args)

Basicly the problem is when I call it, it gives this error:

Workspace.Script:3: attempt to call field 'GlobalFunction' (a nil value)

Any help is appreciated :D

0
you need to define the BaseScriptName RM0d 305 — 10y
0
I just posted a comment. RM0d 305 — 10y

2 answers

Log in to vote
1
Answered by
RM0d 305 Moderation Voter
10 years ago

in script one you had

_G.BaseScriptName.GlobalFunction = function(Args)
    -- CODE HERE
end

make it have this at the top it will fix it. _G.BaseScriptName = {}

_G.BaseScriptName = {}

_G.BaseScriptName.GlobalFunction = function(Args)
    -- CODE HERE
end

It is simply a index, but you never created the house to the door in other words.#

If I helped upvote my answer .

Ad
Log in to vote
0
Answered by 10 years ago

I have the _G.BaseScriptName = {} table, but the function only works in the base script itself and the command line in studio.

Im obviously missing something VERY essential

I didnt really make myself clear, This is what I have:

_G.BaseScript = {}

_G.BaseScript.OutputLine = function(Line)
    print(Line)
end
0
But the problem is when calling it in the other script it just gives an error Irrelevant0 0 — 10y

Answer this question