Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Jasshelper 2011-12-19

Discussion in 'Warcraft Editing Tools' started by cohadar, Dec 19, 2011.

  1. cohadar

    cohadar

    Joined:
    Jun 16, 2007
    Messages:
    234
    Resources:
    0
    Resources:
    0
    Jasshelper 2012-03-10

    Latest version of jasshelper: 2012-03-10
    Previous version was: 2012-02-10

    Code (vJASS):

    // while unit has some buff do some healing
    while GetUnitAbilityLevel(whichUnit, 'Bhea') > 0
        call SetWidgetLife(whichUnit, GetWidgetLife(whichUnit) + 10.)
        call TriggerSleepAction(0.1)
    endwhile

    // print out numbers from 1 to 10 with for loop
    for i = 1 to 10
        call BJDebugMsg(I2S(i))
    endfor

    // print only 1 2 3
    for i = 1 to 10
        call BJDebugMsg(I2S(i))
        if i == 3 then
            break
        endif
    endfor

    // print out numbers from 10 downto 1
    for i = 10 downto 1
        call BJDebugMsg(I2S(i))
    endfor

    // kill all units in a group
    for enumUnit in someGroup
        call KillUnit(enumUnit)
    endfor
    // WARNING: groups are empty after for loop
     


    Changelog:
     

    Attached Files:

    Last edited: Mar 10, 2012
  2. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,375
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I agree with all above changes. One of the biggest improvements which can be made to the parser is to avoid annoying module-initializer blocks, basically something like this:

    Code (vJASS):
    initblock
        //Do stuff
    endinitblock

    //which compiles to:

    private module initblockmod<random number>
        private static method onInit takes nothing returns nothing
            //Do stuff
        endmethod
    endmodule
    private struct initblock<random number> extends array
        implement initblockmod<random number>
    endstruct
     
  3. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    also, vexorian said for the longest time that he'd update modules to take arguments like macros.
     
  4. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,003
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Cool.

    It's going to be hard to get everyone to update to this though ;/
     
  5. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    why te hell is endwhile,endfor,to not bold? XD...

    EDIT:
    I wish the parser is faster this time...
     
  6. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,429
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    @mckill:It is because they are not native to the normal jasshelper. Those are features that cohadar added so ofc they won't be bolded yet neither by the jass tags nor by the editor. ;)

    Also, as far as I know, cohadar isn't working on optimization (yet) so the parser will probably be about the same speed.

    @Mag: If someone repackages jass newgen as a new version, then everyone will update. (the new update would have the rtc bug removed, the updated jass helper, and it would have the latest grimext hotfix)
     
    Last edited: Dec 20, 2011
  7. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,003
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Can we also get a fix on that parsing bug that changes this:

    private constant integer UNITS_UNIT_EVENT = 'n!!!'

    to this:

    constant integer UnitEvent___UNITS_UNIT_EVENT = 'UnitEvent___n!!!'


    >_>
     
  8. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    I'm not even sure that 'UnitEvent___n!!!' is a valid integer.
    Last time i check it has to be one or 4 characters.
    And special characters counts to one, such as the line break :'/n'

    Anyway it's a pjass bug, in the token.l file :

    UNITTYPEINT (['][\x01-\x26\x29-\x5B\x5D-\x7F]([\x01-\x26\x29-\x5B\x5D-\x7F][\x01-\x26\x29-\x5B\x5D-\x7F][\x01-\x26\x29-\x5B\x5D-\x7F])?['])

    It's not a jasshelper one.

    No to mention that it won't be the same expected value and probably would overflow even if it's a valid syntax.
    Now a valid fix would be to convert such integers in decimal value, but really pJass should be fixed, not add some new stuff for jasshelper preprocessor.

    EDIT : Oh wait, i got it, meh i won't delete my post, if there is someone which is willing to update pJass, because this is allowed in jass, but not for pJass :

    local integer i = '/n'
     
  9. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,375
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Well the bug Mag mentioned is definitely vJass because of the way it gets privatized there.
     
  10. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Yeah i've realized that, see my edit.
     
  11. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,375
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Well it's pretty much anything with a "\" character is not allowed with pJass inside those rawcodes. I don't think '\\\\\\\\' compiles with it last I checked.

    @Cohadar, I think it's not useful to have a "break" keyword when "exitwhen true" works just fine. Sometimes having less keywords is a better option.
     
  12. cohadar

    cohadar

    Joined:
    Jun 16, 2007
    Messages:
    234
    Resources:
    0
    Resources:
    0
    That is already fixed.

    @Bribe
    break is simply better than exitwhen true.
    Besides I added it to be consistent,
    every programming language that has for and while loops also has a break.

    When I get someone to update TESH so new keywords are bolded properly there will be a new JNGP release, until than please download and test this.
     
  13. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    I really like this improvement, but can I do this?...
    Code (vJASS):

    for enumUnit in someGroup
        //dooooooooo...
        call GroupAddUnit(someGroup, enumUnit)
    endfor
     


    coz I really dont like this >>> // WARNING: groups are empty after for loop...
     
  14. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,375
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I'm pretty sure that is going to be a wrapper for a FirstOfGroup loop, so no you can't, that will cause an infinite loop divide by 0!

    Though anonymous functions would be cool. People have supported that in the past but it could lead to some serious spaghetti.
     
  15. cohadar

    cohadar

    Joined:
    Jun 16, 2007
    Messages:
    234
    Resources:
    0
    Resources:
    0
    Bribe is right, so if you need to do something with a group after loop you will simply have to use ForGroup native and enum function.
     
  16. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,128
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    This is incorrect behaviour of how an iterator should work. The contense of the group should remain unchanged after the loop completes unless code within the loop performs changes.

    The way you are currently treating it is more like a buffer. Where you pop each element out of it until all elements are processed and the container is empty. As far as I know people never use a for loop with a buffer in a way that would be fesible to compile to efficient JASS.

    You would better off making a special keyword for this behaviour such as..

    Code (vJASS):
    // kill all units in a group
    destructive for enumUnit in someGroup
        call KillUnit(enumUnit)
    endfor
    // WARNING: groups are empty after destructive for loop

    // kill all units in a group
    for enumUnit in someGroup
        call KillUnit(enumUnit)
    endfor
    // group contense untouched after for structure.
     
     
  17. cohadar

    cohadar

    Joined:
    Jun 16, 2007
    Messages:
    234
    Resources:
    0
    Resources:
    0
    I agree, but it is also the most optimized way to implement a group loop.
    (FirstOfGroup + GroupRemoveUnit)

    In almost all cases in mapmaking you don't need a group after the loop.
    (groups are usually destroyed after the loop anyways)

    When you do need a group to stay intact you will just need to use ForLoop native and enum function.

    EDIT:
    of course if someone finds a way to implement for loop that does not remove units from group I will just recode implementation and everyone will be happy. (it has to be fast, so no dumb solutions with copying the whole group and similar are acceptable)
     
    Last edited: Dec 22, 2011
  18. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,128
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    The problem is you are violating standard programming logic with that instruction which could potentially confuse people about its behaviour. It is implicit that a for loop will not change the contense of the structure it is itterating through for anyone who has used a language like python or java. Yours however does not do so.

    Instead of fighting programming conventions, just change the syntax of the structure to something like "destructive for" and then throw a syntax error with a normal "for" used in that situation stating it is unsupported due to inefficient implementation and that the scripter should use the inbuilt enum in that situation.

    Groups are usually never destroyed for efficiency reasons. A lot of common uses can share the same global constant group for the reasons you stated (as they always end up emptry after the function finishes execution). The only time groups are dynamicly allocated and destroyed is when their content needs to persist or more than 1 is required at the same time.
     
  19. cohadar

    cohadar

    Joined:
    Jun 16, 2007
    Messages:
    234
    Resources:
    0
    Resources:
    0
    jass is neither java nor C, it has its own programming conventions and a lot of them are a lot more weird than a for that clears the group.

    In fact this type of loop that clears the group is already used by and known by everybody in the community so I don't really see a problem here.

    The syntax stays the way it is.
     
  20. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    I agree with both of you :p

    Yeah that doesn't make sense that a for automatically removes its member, but jass is enough weird to add a such stuff.
    Now, for usual ForGroup call, anonymous functions would be cool)