question
[Suggestion] "Arrow target" »

[SK]Kelvin

  • Jr. Member
  • Posts: 79
question
«  »Last edited
hello, I’ve been asking myself what’s ‘::’ and what’s its usage

example:
Code: [Select]
::Message( text );

instead of
Code: [Select]
Message( text );

can you please explain me how and when to use it?

regards!

Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,105
Re: question
« Reply #1,  »
Its used to reach out a variable/data outside of scopes.
Code: [Select]
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
Code: [Select]
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

[SK]Kelvin

  • Jr. Member
  • Posts: 79

Milos

  • Jr. Member
  • Posts: 83
Re: question
« Reply #3,  »
What about the client side?
Some scripters use:
Code: [Select]
myVar <- 0;
function Script::ScriptLoad() {
    ::myVar = 1;
    Console.Print("Test: " + ::myVar);
}
or
Code: [Select]
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?

[Suggestion] "Arrow target" »