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: Make/Use global functions and include script

Previous Thread :: Next Thread 
TwillightOLink is not online. TwillightOLink
Joined: 26 Oct 2009
Total Posts: 88
12 Nov 2014 06:31 AM
Hello guys!
I've been away for ~2 years. I've earned much coding experience and got into Lua coding by Garry's Mod. So i am trying to code on Roblox now but it is all different (No clientside,serverside and less functions)

Now how could i possibly include a script (game.workspace.TestScript) into the currently running script? I need this for making quick change for e.g. scripted blocks i want to change quickly.

Secondly i would like to know how to use functions from other scripts or make global functions.

Thanks!
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
12 Nov 2014 06:50 AM
I've never used Garry's Mod, but Roblox lua has quite a few functions still. It still has client and server to worry about, and with FilteringEnabled on, you need to worry about client and server even more!

If you want to include a script into a running script, the preferred method is with ModuleScripts, which act as modules or libraries.
http://wiki.roblox.com/index.php?title=Module_scripts

If both scripts need to run at the same time, you can use Bindable or Remote functions for sending data, or if you just need to share variables and don't want to call functions, you can use _G.
http://wiki.roblox.com/index.php?title=Global_function

For example, _G.Hello = 2
Then that works in another script too.
Report Abuse
TwillightOLink is not online. TwillightOLink
Joined: 26 Oct 2009
Total Posts: 88
12 Nov 2014 06:52 AM
I tried similar, it is way different from gLua which would be _G["Hello"] = 2

I love that Roblox uses lua but i need a challange ;_;
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
12 Nov 2014 07:10 AM
You can do
_G["Hello"] = 2 as well.

With a table...
local Table = {
Hello = 5,
["Bye"] = 7
}

And then you can access either of them with
Table["Hello"]
or
Table.Hello

and

Table["Bye"]
or
Table.Bye
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
12 Nov 2014 07:10 AM
I'm almost certain you can do that on GMod too, if GMod uses Lua.
Report Abuse
TwillightOLink is not online. TwillightOLink
Joined: 26 Oct 2009
Total Posts: 88
12 Nov 2014 07:50 AM
Yeah you can, it is just a bit of a change because GLua is based 90% of functions which change variables and values and no direct change.
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