.

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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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