1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  4. The reforging of the races is complete. Come see the 14th Techtree Contest Results.
    Dismiss Notice
  5. It's time to choose your horse in the race - the 32nd Modeling Contest Poll is up!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[vJASS] Question about structs

Discussion in 'Triggers & Scripts' started by dardas, May 21, 2011.

  1. dardas

    dardas

    Joined:
    Sep 12, 2008
    Messages:
    649
    Resources:
    0
    Resources:
    0
    Hi, i was wonder if its possible to do this:
    Code (vJASS):

    struct strExtension
          string data = ""
          public method operator = takes string data returns nothing
                set .data = data
                //Here lies the problem btw, theres no method operator =
          endmethod
          public method operator == takes strExtension s returns boolean
                return .data == s.data
          endmethod
    endstruct

    library X initializer onInit
          private function onInit takes nothing returns nothing
                local strExtension s = "Hello"
                if s == "Hello" then
                      //Actions #1
                else
                      //Actions #2
                endif
          endfunction
    endlibrary
     

    so basicly, the struct gives you the value in the variable called data, instead of the integer.
    is it possible?
    Sorry if you dont understand, i'm bad at explaining things..

    Thanks in advance..
     
  2. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    463
    Resources:
    0
    Resources:
    0
    Nope, only possible with integers like ARGB.

    That's possible because structs are implemented as integer. I mean you could do some hacks
    with StringHash but you would still need an explicit constructor.
    Then better use a regular struct with an regular constructor.
     
  3. dardas

    dardas

    Joined:
    Sep 12, 2008
    Messages:
    649
    Resources:
    0
    Resources:
    0
    Well.. i could use arrays, [] has an operator, and so does []=,
    but it will be too much like table of strings.. donno how well that will go ;p
    i guess ill give it a try..
     
  4. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    or use operator +, if you don't need it...

    or just keep the struct member "data" to be publicly usable...
     
  5. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,193
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    In vJass, you can only overload variable names and operators [], []= and <.

    I may add fully-dynamic operators in Luck but I'm undecided on their readability factor.
     
  6. dardas

    dardas

    Joined:
    Sep 12, 2008
    Messages:
    649
    Resources:
    0
    Resources:
    0
    I've found that using .get() is better ;p
    and then i added a color value, so .get(boolean colored)
    Thanks for the tip tho ;p

    @bribe
    if you will do that, that would be really awesome.. thanks ;p
     
  7. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,193
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    The first version will not allow operator overloading if I start to run low on time, but they may likely end up being added later on (around the time I get a seperate compiler to turn vJass scripts into Luck scripts).
     
  8. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Why not just use a normal member variable? No need to make everything unreadable to save a few keystrokes.
     
  9. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,193
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Yeah, operators are really bad for readability. It's a lot easier to understand "this.set(index, val)" and how it operates as a method than to guise the thing using "this[index] = val"
     
  10. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    or just simply make them as normal members so the user can manipulate them directly...
     
  11. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Usually (unless you're totally insane, which I guess is a possibility) you use operators in place of functions rather than simple variable assignment/retrieval.