what do these mean?

Started by MEGAMIND, Aug 08, 2018, 02:11 PM

Previous topic - Next topic

MEGAMIND

I have seen many scripters using this :: Before using some codes like ::createvehicle so what do these mean?, do? Are neccessary or not?

ysc3839

#1
http://www.squirrel-lang.org/squirreldoc/reference/language/execution_context.html#variables
QuoteGlobal variables are stored in a table called the root table. Usually in the global scope the environment object is the root table, but to explicitly access the closure root of the function from another scope, the slot name must be prefixed with '::' (::foo).
If this code is in a class, '::' is necessary to access the global function.

Edit: It seems that I'm wrong?
class test_class
{
function print1()
{
::print("print1");
}

function print2()
{
print("print2");
}
}

function global_print1()
{
::print("global_print1");
}

function global_print2()
{
print("global_print2");
}

global_print1();
global_print2();

local test = test_class();
test.print1();
test.print2();
This code outputs:
[SCRIPT]  global_print1
[SCRIPT]  global_print2
[SCRIPT]  print1
[SCRIPT]  print2

This code shows differences:
class test_class
{
function print1()
{
::print("print1");
}

function print2()
{
print("print2");
}

function print(text)
{
::print("!!!" + text + "!!!");
}
}

function global_print1()
{
::print("global_print1");
}

function global_print2()
{
print("global_print2");
}

global_print1();
global_print2();

local test = test_class();
test.print1();
test.print2();
[SCRIPT]  global_print1
[SCRIPT]  global_print2
[SCRIPT]  print1
[SCRIPT]  !!!print2!!!