.

Dirac

22710180
Reaction score
147
you got everything wrong and you're mixing a bunch of keywords used for other finality such as "private"

you should read the jasshelper manual

static in the JASS language has 2 uses:

-Inside structs to specify that a member (variable or method) is not attached to an instance ("this.") and instead it works like a global if it's a variable or as a function if it's a method, if you don't know what a struct is then you don't need to know what static is
-static ifs, compilation tool, read the manual
 

Bribe

vJass errors are legion
Reaction score
67
A non-static variable in a struct is not comparable to "private variable name". It is comparable to a variable array.

A struct member is not "private" like a private variable. It is simply a variable that can be accessed without prefix from within the struct, but requires "StructName.member" from outside the struct. There are some exceptions to the rule for example when writing a "code" argument you have to type "function thistype.methodName" instead of "function .methodName" or "function methodName".

To answer your first question, a non-static variable is an array. Instead of writing "this.variable" from a struct you'd write "variable[this]" if it wasn't a struct.

The most important part of a struct that people use is the create/destroy methods, because that handles the part which makes it multiply-instanciable. To be honest, most of the time all you need from a struct is this:

JASS:
struct Name
endstruct


With that you can "local integer this = Name.create()" to get an integer to use for an array, and call "Name.destroy(this)" to throw the integer back. You do this because otherwise the struct does not know that integer is free so it keeps incrementing the "this" variable generator variable and that can lead to big problems because arrays can only support integers 0 through 2^13-1 which is obviously not infinite.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>I'd like a clear explanation on how this keyword is exactly supposed to work so I can understand it intuitively.

Well in the scripting language vJass, the static keyword can only be used inside structs. And inside structs it can only be used in two ways:

1| As a member variable modifier:
JASS:
struct STRUCT
    static integer VAR
endstruct

In this context (as a member variable modifier) the static keyword makes the variable VAR "shared" between all instances of the struct/class STRUCT. Shared means that only one copy of it exists for the whole struct/class. If the static is droped (only integer VAR) then
every instance of STRUCT will have it's own copy of VAR.

2| As a member method modifier:
JASS:
struct S
    method not_static_method takes nothing returns nothing
        // there is an implicit argument in this method called "this" in vJass (in others it may be called self)
    endmethod

    static method static_method takes nothing returns nothing
        // there IS NO implicit argument in this method
    endmethod
endstruct

Here's an explanation I found in the wiki:
"Static methods neither require an instance of the class nor can they implicitly access the data (or this, self, Me, etc.) of such an instance. A static method is distinguished in some programming languages with the static keyword placed somewhere in the method's signature."

> I also understand that it is necessary for certain operator overloading, such as static method create.

Well actually the only method overloading (overloaded methods = methods with the same name but different signature; signature = number of arguments and their type) allowed in vJass is for the create and destroy methods, and you don't actually overload them but simply replace them. The create method must be declared static but the destroy cannot be declared static {although it can be used as a static method [STRUCT.destroy(<instance>)] ... go figure}.

The operator overloading ("Jass currently allows operators for <, > , array set and array get.") and property get/set methods can't be static as well.

Edit: Well I forgot about the "static if" so I guess that there are 3 ways/places to use the static keyword =). "static ifs" are used for conditional compilation.
 
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