How to call functions in other script files in Roblox

I have a script file built into Workspace containing functions. I would like to name these functions from script files embedded in workspace child objects. I do not want to copy and paste these functions into multiple script files. I believed that an object-oriented approach would be best if it were possible.

+3
source share
8 answers

I found what I was looking for in this tutorial Publication of Public Functions written by the notorious jediknightkrazy .

+2
source

_G shared. Shared , _G, "shared" , _G, _G ( ROBLOX). :

shared["variablename"] = value

, _G. :

Script 1

shared["rprint"] = function(array) for i,v in pairs(array) do print(i, v) end end

Script 2

repeat wait() until shared["rprint"]
shared.rprint({"Hello, ", "How", " are", " you?"})

script ", ?"

+3

. script :

_G.myFunction = function() print("Hello World") end

script :

repeat wait() until myFunction myFunction()

_G, , script , _G.

+1

. script :

_G.myFunction = function() print("Hello World") end

script :

repeat wait() until myFunction myFunction()

: _G, script , _G.

, - ROBLOX _G , .

dofile() ROBLOX, .

: script - _G, _G.MyFunction = function (parameters). script _G - _G.MyFunction().

, ROBLOX, , _G . - , Camoy:

repeat wait() until _G.MyFunction() 

, ! -pighead10

+1

- _G shared.

script,

_G.myFunction = function(Arguments)

-- blah

end

script .

repeat wait() until _G.myFunction ~= nil

_G.myFunction()

_G.

+1

, , _G .

Script

_G.myFunction = function()
     print("Hello, myFunction!")
end

Script

repeat wait() until _G.myFunction()
_G.myFunction()

, myFunction!

+1

BindableEvents RemoteEvents. , , _G. . Bindableevents RemoteEvents . BindableEvents RemoteEvents / /.

http://wiki.roblox.com/index.php?title=API:Class/BindableEvent

+1

, . , - !

0

Source: https://habr.com/ru/post/1711447/


All Articles