Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Global Variables, how do they work?

Asked by
Necrorave 560 Moderation Voter
9 years ago

I am attempting to have one script with a boolean variable determine if another script should run.

I seem to be having trouble getting the variable to transfer over though.

This is a basic summary of what I am trying to do. (Rather than throwing my entire block of code at you)

Script 1:

start = true

Script 2:

while true do

while start do -- "start" is used here
    -- Blah blah blah, code here.  (Nothing that affects "start")
wait()
end

Is this how I would use non-local variables inside other scripts?

All the scripts that use such things are running when I run my environment (I have a "while true" keeping them running in the background).

However, script 2 never goes through that second while loop.

Anyone have ideas?

Thanks

1 answer

Log in to vote
4
Answered by 9 years ago

Say you have _G.Var = true in the server-script 'apple' then you have another server-script called 'Bananas' you can access _G.Var from Bananas since it is Global

In Apples

_G.Var = true

In Bananas

print(_G.Var)

Please upvote my answer if this helped.

0
Thanks a lot. I have been messing with global functions and tried to do the same with variables, but I must of messed something up my first try. Necrorave 560 — 9y
Ad

Answer this question