Difference between variables..

Charapanga

New Member
Reaction score
46
Hi,
As in the title...what is the difference between the variables:
Private
Private constant
local
UDG
?
 
Reaction score
341
private variables are used only inside a library and scope , they can't be used out side of it.

constants values cannot be changes

locals can only be used in one function , they do not carry over

udg's are global variables , defined in the variable editor ( GUI )
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
Private: A global variable created in vJass that can only be used in the same scope or library as it was made in. NOT function, but scope or library. Aditionally, variables created in a scope gain the scope's name as a prefix. Meaning that a global variable named X:
JASS:
scope Test
globals
      private real x
endglobals
endscope

Will become:
JASS:
Test_x


Private constant: Same as Private, but the constant part means that it can't be changed, and that it gets inlined by the Jass-parser, making constants the fastest kind of variable that can be used.

Local: Variable that can only be used in the same function at was defined, unless used as an argument. Like this:
JASS:
function 2 takes nothing returns nothing
call BJDebugMsg(R2S(x)) // Illegal, the local was defined in a different function.
endfunction

function 12 takes real x returns nothing
call BJDebugMsg(R2S(x)) //Legal! The variable has been used as an argument, meaning that it was passed to a function.
endfunction

function 1 takes nothing returns nothing
local real x = GetUnitX(GetTriggerUnit())
local real y = GetUnitY(GetTriggerUnit())
endfunction


Remember that local arguments cannot be used in functions that are used as code. Like unit group callbacks.

UDG: User Defined Global, a global variable that's been created in the GUI variable editor. Has a udg_ prefix before it's name, and can be used freely in any trigger across the game memory.

EDIT: Why so fast?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Private and public are both vJASS preprocessor commands. Private means it can't be used outside of the scope/library it is in. Public means you have to add the scope/library's name as a prefix.

Constant means that it will be set at map initialization and can never be changed.

Local is a local variable, which means it can only be used inside the function it is declared in. They have to be declared at the top of a function, and a unique instance of the variable is created every time the function is run.

udg_ means "User Defined Global". Global variables you create in the Variable editor automatically have this prefix. With vJASS, you can declare global blocks, which allows you to create globals without the udg_ prefix.

"Static" is a vJASS struct keyword. It means that the method or variable does not change when you use a different instance of the struct. If you use it on a variable, it means that you refer to the struct like this:

JASS:
struct Test
    static integer i = 5
    integer O

    method random takes nothing returns integer
        return this.O * 5
    endmethod

    static method somemethod takes Test rar returns integer
        return rar.O * 5
    endmethod
endstruct


Since 'i' is a static variable, you can't refer to it as 'rar.i'. You have to refer to it as 'Test.i'. The same goes for the methods. You can refer to random as 'rar.random()', but you can't refer to somemethod as 'rar.somemethod(rar)'. You have to refer to somemethod as 'Test.somemethod(rar)'.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top