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: Is it possible modify variables in other scripts?

Previous Thread :: Next Thread 
KeolaOwnz is not online. KeolaOwnz
Joined: 03 Feb 2009
Total Posts: 2574
03 Mar 2014 05:37 PM
I am making a GUI in which answering two questions right on the same GUI on separate buttons will let you advance to the next level. I was wondering how I could accomplish this. I was hoping I could have a script modify a variable in another somehow.

Thanks!
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
03 Mar 2014 05:40 PM
Not sure if this will accomplish what you are going after, but you can use global variables. (You can't use them in a local script).

_G.myVariable = "Hello"

(in another script)

print(_G.myVariable)
>> Hello
Report Abuse
KeolaOwnz is not online. KeolaOwnz
Joined: 03 Feb 2009
Total Posts: 2574
03 Mar 2014 05:44 PM
So I just use

_G.variableName

to make it global? If that's the case, I can modify global variables too?
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
03 Mar 2014 05:50 PM
Yeah, but if you create a global variable, always make sure you use _G. in front of it when you use it.
Report Abuse
KeolaOwnz is not online. KeolaOwnz
Joined: 03 Feb 2009
Total Posts: 2574
03 Mar 2014 05:53 PM
Thanks a bunch! This helps a lot.
Report Abuse
Vexedly is not online. Vexedly
Joined: 15 Sep 2006
Total Posts: 7011
03 Mar 2014 05:57 PM
[ Content Deleted ]
Report Abuse
KeolaOwnz is not online. KeolaOwnz
Joined: 03 Feb 2009
Total Posts: 2574
03 Mar 2014 05:58 PM
Thanks to you both. I'll be sure not to.
Report Abuse
KeolaOwnz is not online. KeolaOwnz
Joined: 03 Feb 2009
Total Posts: 2574
03 Mar 2014 06:07 PM
When I tried it, I got an error for trying to perform arithmetic on it, and called it a nil value. But I thought it was global?
Report Abuse
VividSilence is not online. VividSilence
Joined: 21 Jul 2008
Total Posts: 1008
03 Mar 2014 06:08 PM
Add this to the script before it is called

while _G.variableName == nil do wait() end
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
04 Mar 2014 08:28 PM
You were probably trying to perform arithmetic on it before it was loaded in the main script... Maybe you can define it as something in the beginning of the script, so it doesn't error out.

ex)

_G.var = 0 --define it so you get no errors

--scripting
_G.var = 5


(in another script)

wait() --add a delay, give time for the other script to load the variable
print(_G.var + 5)
Report Abuse
LogicCaik is not online. LogicCaik
Joined: 21 Mar 2010
Total Posts: 263
04 Mar 2014 08:31 PM
Bump

0xCaik
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