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. Ride into the sunset with the 32nd Modeling Contest.
    Dismiss Notice
  4. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  5. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  6. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  7. 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.

JPAG - JASS Proper Application Guide

Discussion in 'JASS/AI Scripts Tutorials' started by Bribe, Sep 27, 2011.

  1. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Wow default return values, World Editor what have u done!
     
  2. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Hmm, it's just a theory, maybe it just crashes the thread, as said i haven't tested.

    Funny, how this is getting off-topic.

    Ok, test done :

    Code (vJASS):
    /*

    Wc3 version : 1.26.0.6401
    OS : windows 7 , 64 bits

    text displayed :

    begin

    end of condition without return value
    second condition
    end of condition without return value
    second condition
    end of condition without return value
    second condition
    end of condition without return value
    second condition

    b == false
    b2 == true
    b3 == false

    */


    function Bool takes integer i returns boolean
        if i == 0 then
            return false
        elseif i == 1 then
            return true
        endif
    endfunction

    function Cond takes nothing returns boolean
        local integer i = 42
       
        if i == 0 then
            return false
        elseif i == 1 then
            return true
        endif
        call BJDebugMsg("end of condition without return value")
    endfunction

    function Cond2 takes nothing returns boolean
        call BJDebugMsg("second condition")
        return true
    endfunction

    function Act takes nothing returns nothing
        call BJDebugMsg("actions")
    endfunction
       
    function InitTrig_test takes nothing returns nothing
        local boolean b
        local boolean b2 = true
        local boolean b3 = false
        local trigger trig = CreateTrigger()

        call TriggerAddCondition(trig,Filter(function Cond))
        call TriggerAddCondition(trig,Filter(function Cond2))
        call TriggerAddAction(trig,function Act)
        call TriggerRegisterPlayerChatEvent(trig,GetLocalPlayer(),"test",false)

        call BJDebugMsg("begin")
        call BJDebugMsg(" ")

        if TriggerEvaluate(trig) == true then
            call TriggerExecute(trig)
        endif
        if TriggerEvaluate(trig) then
            call TriggerExecute(trig)
        endif
        call TriggerEvaluate(trig)
        set b = TriggerEvaluate(trig)
        call BJDebugMsg(" ")

        if b == true then
            call BJDebugMsg("b == true")
        elseif b == false then
            call BJDebugMsg("b == false")
        else
            call BJDebugMsg("undetermined")
        endif

        set b2 = Bool(42)
        if b2 == true then
             call BJDebugMsg("b2 == true")
        elseif b2 == false then
             call BJDebugMsg("b2 == false")
        else
             call BJDebugMsg("undetermined")
        endif
        set b3 = Bool(42)
        if b3 == true then
             call BJDebugMsg("b3 == true")
        elseif b3 == false then
             call BJDebugMsg("b3 == false")
        else
             call BJDebugMsg("undetermined")
        endif
        call BJDebugMsg("end")
        call BJDebugMsg(" ")
    endfunction


    Conclusion :

    In a trigger condition, no return == false.
    I assume it's also the case in any native function filter argument, but i'm not willing to make such tests.

    In a regular function it just do nothing, it doesn't erase the previous variable value in case it's used like that : set variable = Function(...)
    So yes we can say it crashes the thread, no default values are given.
    Now, i've just realized that i have not tested something like that : if Function(...) then ..., but meh it should also crash the thread.
    But if someone else could test this last case it would be cool, i'm bored, i don't want to reboot on win again ...
     
    Last edited: Dec 19, 2011
  3. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I'm not sure what you mean by the thread crashing with no valid return value - if it displayed some values for b2 and b3 then it means the thread didn't crash. What is confusing is that it displayed b2 == true but b3 == false??? When they both called the same thing -_-
     
  4. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Check their initial value.
    If there is none, the function InitTrig_test will cause a crash because of a use of an unitialized variable (already tested and confirmed).

    Hence the reason why if FunctionWithoutAReturnWhenItWasExpected(...) should crash the thread because it's the same as an unitialized variable.

    I hope you got it now.

    PS : I've just realized that i've forgotten to add "b3 == " in the last debug messages, but that doesn't matter anyway, i will edit it later.
     
  5. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Aha, it is a very interesting thing actually. It can actually be useful for something like an "isset" function.
     
  6. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Hmm, it's also unsafe, unless you always give a default value to a variable before use it (arrays should not be concerned, but i have not tested it)
     
  7. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Well I don't think it could be used now that I think of it, because passing an unset variable as a function argument will already crash the thread.

    Ok, I guess we can say that it provides no extra functionality save for maybe saving 1 line of code while proving to be a risk, and only good for people who don't use JNGP to compile their code.
     
  8. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    OFF-topic (again) :

    Edit the flex/bison grammar is not a big deal, someone with basic C knowledge should be able to correct it.
    The source of the jass parser are available but wc3c.net seems off-line right now.
     
  9. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I would really rather not. It is hard enough to get people to download JNGP/JH let alone an update to JH which fixes the aforementioned issue and have everyone who doesn't get thrown compile errors.
     
  10. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    It's not jass helper but the jass parser (pjass)
     
  11. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I do get that but you can't have JH without pJass last I checked.
     
  12. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Yes.
    But nothing forbids you to edit pjass, now for this thing a warning should be displayed but the script still be "compiled", like in modern compilers.

    And well, about users if you think like that nothing good would be ever done.
     
  13. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Well if I am to update it I might as well rely on cohadar and/or Frotty to do it for me because too many people were disagreeing with my methods on a new parser, it was disheartening. Then I had an appendectomy in the middle of June and had to pause the plans, and when I got back from the hospital I just completely lost interest.
     
  14. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    A jass parser != a jass preprocessor.

    I mean you should be able to do what the official jass parser allows, but in the same time add warning messages, such in the case mentionned earlier.

    Official jass parser : as long there is one return (no matter if there is an if/then/elseif/... or whatever) it is allowed.

    pjass : if there is no return in the last line of a function -> warning

    I don't have more in mind for now, but i have never really used the official jass parser.

    I'm quite sure that Cohadar woudn't mind about it.
     
  15. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I really am not interested enough. There are only a few bugs that I found with pJass and we have gone over all but one, that the following two don't compile:

    Code (vJASS):
    '\\'
    '\''


    Really, such light stuff is definitely no reason to make an update. No one needs the two above and requiring a dummy "return false/0/null" is no big deal since most of the time you want that value for functionality, safety or readability anyway.
     
  16. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    I'm on vacations, i plan to learn C if i'm not too lazy.
    So, well, maybe i will do it.
     
  17. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    457
    Resources:
    0
    Resources:
    0
    Yey you can. Zoxc made JassParser and you can set up JassHelper to use this instead of PJass. I would link to the executable and the instructions but wc3c is down :(

    Edit: haha, it's back again: so, download it here and set it up like here.
     
    Last edited: Dec 19, 2011
  18. Mr.Foxy

    Mr.Foxy

    Joined:
    Dec 21, 2011
    Messages:
    234
    Resources:
    0
    Resources:
    0
    What it does?
    It nicing you?
     
  19. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,158
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    What?
     
  20. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Stop trolling.