question

Started by Kelvin Garcia Mendoza, Mar 04, 2019, 05:27 AM

Previous topic - Next topic

Kelvin Garcia Mendoza

hello, I've been asking myself what's '::' and what's its usage

example:
::Message( text );
instead of
Message( text );
can you please explain me how and when to use it?

regards!

DizzasTeR

Its used to reach out a variable/data outside of scopes.
function onScriptLoad() {
    local a = 1;
    { // Starting a general scope inside script load
        local a = 3;
        print(format("local scope a: %i, outside local scope a: %i", a, ::a));
    }
}

Usually used in classes/tables instead of general scopes like above
function LOGINFO(s) { print("[LOG] " + s); }

function CPlayer::Foo() {
    LOGINFO("Called player method Foo"); // Error, LOGINFO is not present in CPlayer class
    ::LOGINFO("..."); // Look for it outside the CPlayer scope
}

I haven't touched squirrel for quite a while now so it could be abit rusty :P

Kelvin Garcia Mendoza


Milos

What about the client side?
Some scripters use:
myVar <- 0;
function Script::ScriptLoad() {
    ::myVar = 1;
    Console.Print("Test: " + ::myVar);
}
or
myVar <- 0;
function Script::ScriptLoad() {
    myVar = 1;
    Console.Print("Test: " + myVar);
}
Both work, but...
Is this necessary for variables called from outside the function?
What is the correct way to use this in client?