Community discussions

 
man
newbie
Topic Author
Posts: 46
Joined: Tue Jul 25, 2017 2:58 pm

Globals are emply from script but have a values at CL

Wed Jul 04, 2018 3:20 pm

Hello, I have sopent almost a day finding out why my Global variables have values in one scripts and are empty at other.

For instance i have a :global URL "http://google.com";
In the command line and in the script i have creacted it, the $URL has a value = http://google.com
But in one of the scripts it is empty.
Policy for all scripts are correct.
 
man
newbie
Topic Author
Posts: 46
Joined: Tue Jul 25, 2017 2:58 pm

Re: Globals are emply from script but have a values at CL

Wed Jul 04, 2018 3:48 pm

Really something strange. Even my functions (globals) are emply.
They are visible on scripts they were created and in CL, but not from any other script!
 
User avatar
dasiu
Trainer
Trainer
Posts: 232
Joined: Fri Jan 30, 2009 11:41 am
Location: Reading, UK
Contact:

Re: Globals are emply from script but have a values at CL

Wed Jul 04, 2018 6:48 pm

In the beginning of each script you need to define the variables (even the global ones) you are using. You just need to do:
:global URL;
- so it's not changing the value, the variable is all the time there, it just makes the global variable "visible" from the "scope" of the script. You need to do the same for all global variables (and the functions) you will be using inside the script. You can compare it to old programming languages (like C) when you needed to declare the variables you'll be using :).
 
man
newbie
Topic Author
Posts: 46
Joined: Tue Jul 25, 2017 2:58 pm

Re: Globals are emply from script but have a values at CL

Thu Jul 05, 2018 9:47 am

Oh, You are the real Man 8) ! Thank l you!
I have only a rude words regarding myself, as seems i have missed that in the wiki. As i have a quite lot scripts, i have moved all Global variables to a file (glob.rsc) and simply make an import of it after each reboot, to be sure that all my variables and functions are present.
And you can just imagen, i have started to to add all globals with their values to scripts :shock: :lol:

Who is online

Users browsing this forum: Google [Bot] and 6 guests