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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 03 Feb 2009 |
| Total Posts: 2574 |
|
|
| 03 Mar 2014 05:53 PM |
| Thanks a bunch! This helps a lot. |
|
|
| Report Abuse |
|
|
Vexedly
|
  |
| Joined: 15 Sep 2006 |
| Total Posts: 7011 |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 03 Mar 2014 06:08 PM |
Add this to the script before it is called
while _G.variableName == nil do wait() end |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 263 |
|
| |
|