I have a script file embedded in the Workspace that contains functions. I would like call these functions from script files embedded in child objects of the Workspace. I don't want to have to copy and paste these functions into multiple script files. I figured the object oriented approach would be best if its possible.
A:
I am not familiar with Roblox but you can simply use dofile('myFunctions.lua')
to load a file in Lua. Another solution would be to create a module for your functions.
Nick
2009-06-29 17:39:53
I don't think this will work in the Roblox sandbox. As far as I know Scripts within Roblox objects can't access the file system.
Slim
2009-06-29 18:38:27
+1
A:
I found what I was looking for in this tutorial on Exposing public functions written by the notorious jediknightkrazy.
Slim
2009-06-29 19:50:58
+1
A:
You can make the function global. In one script do this:
_G.myFunction = function() print("Hello World") end
In another script do this:
repeat wait() until myFunction myFunction()
By defining a function is _G you must wait for the script to execute assigning the function, then you can call the function even without specifying _G.
Camoy
2010-07-17 12:35:11