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 havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. The results are out! Check them out.
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. 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.

[JASS] Few Questions

Discussion in 'Triggers & Scripts' started by kennyman94, Mar 16, 2010.

  1. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Code (vJASS):
    struct Fun
        real var
        method myFunc takes nothing returns nothing
            //do your stuff
        endmethod
        method operator var= takes real value returns nothing
            set this.var = value //set the value
            call this.myFunc() //call your function
        endmethod
    endstruct


    ?
     
  2. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    A method operator is an instance-method. An instance method requires an instance, in this case an integer struct. When a native function is called (the functions that can be hooked) there is no integer index, or no "instance", so how exactly would that work?

    There may be static method hooks, but that's only because a static method is pretty much a function with different keywords.

    So, wait, you knew what a method operator was before asking this question? Personally that is the very first thing I used it for. It's basically just another way of "transforming" the interface of your code so that it is easy and understandable.
     
  3. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    You could always manually hook it:
    Code (vJASS):
    //this doesn't make much sense
    globals
        trigger hookOp_x = CreateTrigger() //trigger for hooking
        integer sTempFun = 0 //temporary instance for passing data
    endglobals

    struct Fun
        real asdf
        method operator x takes nothing returns real
            return this.asdf
        endmethod  
        method operator x= takes real value returns nothing
            set this.asdf = value //set this.asdf to the value input
            set sTempFun = this //set the tempData global to this instance
            call TriggerEvaluate(hookOp_x) //evaluate the hook
        endmethod
    endstruct

    function onhookX takes nothing returns boolean //example function for hooking
        call BJDebugMsg("X-Value: "+R2S(Fun(sTempFun).x)) //should read "5" in this case
        return false //return false, since it is a condition
    endfunction

    function blahblah takes nothing returns nothing
        call TriggerAddCondition(hookOp_x,Condition(function onhookX)) //add this func to the hooking
        set Fun(1).x=5 //modify the value to evaluate the hook
    endfunction


    But even then, it is a little weird. :p Usually you are in control when the value changes anyway. And knowing when it changes is usually what variable method operators are for, aside from simplification of interface. ;)

    Btw, that was just an example, it should work but I'm not positive. Still, tell us what you need it for and there is most likely a workaround.
     
  4. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    I suppose that too, though it is just as easy to use a method rather than a method operator in this case.
     
  5. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    I knew what operatorator overriding was but i wasn't exactly sure what it was used for. all i knew was that it could let you change the function of an operator.

    So what exactly is the typecast operator? and what is the syntax?

    i know that array structs can't have array members but can an array struct have a struct with an array member like:
    Code (vJASS):
    struct Stats
        integer array stat[21]
        integer array wins[12]
        integer array losses[12]
    endstruct
    struct P extends array
        Stats s = 0
        method Init takes nothing returns nothing
            set .s = s.create()
        endmethod
    endstruct
    //note:that is not the only part of it. i have a lot more stuff
    //but for the purposes of this example am only using those 2 structs


    so no, you can't hook methods or method operators?

    what do symbol do you use for modulo?

    if an id is an integer then why are there letters in it? is it hex because i thought hex only went from 0 - f and ive seen characters other that those. and what is with the ' ' delimiters?
     
    Last edited: Jun 14, 2010
  6. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    You can only hook native functions. The hook callback can either be a static method or a function, I believe.

    There is no modulo operator.

    Well a character is more or less an integer and there are non-numeric values in those.

    No, I believe it's actually ASCII.

    Well those delimiters indicate that the included text is to be converted to an integer. It is used on characters for dialog hot-keys as well. If you do
    call BJDebugMsg(I2S('c'))
    I believe it will return the ASCII character ID for "c".
     
  7. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    ok and what was with the copied post?

    what is ASCII?

    then what do you use for modulo?

    and you never answered the first question of that post. or the second.
     
  8. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    What the hell? I didn't realize that... must have been a lag glitch. I'll remove the second one now.

    What is Google?

    A combination of subtraction and integer division. Either that or you can use the crappy
    ModuloReal
    and
    ModuloInteger
    functions.

    This question? What the hell is a "typecast operator"? An operator is a symbol that performs specified actions. For example, an array uses the
    []
    operator in order to reference a specific index of the storage reference. You can reroute this functionality to have it do something different (typically used when the type does not already provide that type of functionality).

    So, please explain yourself a little more clearly.
     
  9. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    and the second?

    and i meant what does ASCII stand for.

    i figured. but ok
     
  10. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    If you try to give an array-struct an array member it will tell you that you're not allowed. Why don't you just try to compile it and see if it's working correctly. You can also check the JassHelper manual to determine if it is a feature of JassHelper.

    In fact, if you try to compile it then the parser will tell you "use a dynamic array instead if necessary", which is exactly what you posted.

    Code (vJASS):
    struct strarray2
        integer array i [2]
    endstruct
    struct strarray extends array
        strarray2   b
    endstruct


    This is perfectly acceptable. Keep in mind that there can only be 8191/2 instances of
    strarray2
    , which will in turn limit the amount of
    strarray
    instances there can be.
     
  11. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
  12. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    thanks.
    if a struct has an array member, why do all instances of that struct share the same variable? why doesn't it each struct have its own variable array?

    can a single struct extend multiple interfaces?
     
    Last edited: Jun 16, 2010
  13. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    No, this isn't Java. A struct can only extend one other object.
     
  14. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,033
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
  15. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    This was typed up just now in TextPad, you can do this in Java:

    Code (Text):
    interface thisInterface {

    }
    interface thatInterface {

    }

    class MegaClass implements thisInterface, thatInterface {

    }
    You can even do:

    Code (Text):
    interface thisInterface {

    }
    interface thatInterface {

    }

    class SuperMegaClass {

    }
    class MegaClass extends SuperMegaClass implements thisInterface, thatInterface {

    }
     
  16. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,033
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    And Vexorian doesn't implement this because....?
     
  17. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    i have no idea what i'm looking at. its like a whole different language. lol

    how do you set a variable equal to a preplaced object without using the variable editor?
     
  18. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    ok. is there any way to get a similar effect in vJass?

    how do you set a variable = a preplaced object without using the variable editor?
     
  19. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,033
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    In vJass terminology, the above code would appear as:

    Code (vJASS):

    interface panelA
    endinterface

    interface panelB
    endinterface

    struct parent
    endstruct

    struct child extends parent, panelA, panelB
    endstruct
     


    But that would give you a few syntax errors in vJass. The ways to achieve this in vJass are limited, but if your interface has only optional methods you can get away with it like so:

    Code (vJASS):
    struct panelA
    endstruct

    struct panelB
    endstruct

    struct parent
    endstruct

    struct child extends parent
       
        delegate panelA defaultA
        delegate panelB defaultB
       
    endstruct
     
     
  20. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    i never understood the whole delegate thing. can you give and explain an example?

    how do you set a variable equal to a preplaced object withought using the variable editor?