• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

JPAG - JASS Proper Application Guide

Level 17
Joined
Apr 27, 2008
Messages
2,455
Wow default return values, World Editor what have u done!

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 :

JASS:
/*

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:
Level 17
Joined
Apr 27, 2008
Messages
2,455
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 -_-

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.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
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.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
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.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
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.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
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:

JASS:
'\\'
'\''

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.
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
I do get that but you can't have JH without pJass last I checked.

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:
Level 2
Joined
Oct 25, 2010
Messages
8
I'm sorry I read only the first couple pages of this topic. I very rarely post on this forum, but this topic is total BS. Honestly it's like arguing toe ma toe or toe may toe. I don't care how Blizzard wrote their code, and I'm sure a bunch of others don't care either. Just looking at the first few pages of my C Programming Book, it says there are multiple ways to write code. Blizzard never said this, nor did it say we had to write code a certain way. So that means its up to us? Your not us, neither am I.

However, I think it's probably best that the writer of the code just keeps consistency. As long as he/she does not make some globals all caps and some all lower case. Same for constants and functions. People are smart enough to figure code out, and it will even help them if they are going into a Computer Science related field.
 
While this has been subject to a lot of controversy/debate, I think that it being renamed to a "guide" rather than a "standard" should relieve everyone's complaints. It is useful to those who do not know of the standard jass conventions. I remember when I first started coding in JASS--I would write as I pleased and toyed with several styles, trying to find one that looked good. If only this guide had been there before.

Approved.

(It is true that the initializer part is a bit dated since cohadar's release, but I'll wait until it becomes a bit more public before requiring an update)
 
Level 18
Joined
Nov 1, 2006
Messages
1,612
Do you know how annoying it is to lose track of parenthesis while coding? Better to just rely on precedence.

This is less of a problem when you're using an IDE that highlights corresponding parentheses. Your point is taken though. I think this one may just be a matter of preference. Personally, I find calculations inside parentheses to be easier to follow. Thanks for the response.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
AMENDMENT:

Creation and destruction of artificial types should match the naming conventions set by Blizzard and Vexorian. Struct methods should be named "create" or "destroy". Other functions which try to serve the same purpose should begin with Create or Destroy.

There is another naming convention which should be encouraged: adding and removing. These should be reserved for container-type syntax. In JASS, you have GroupAddUnit, GroupRemoveUnit, ForceAddPlayer, ForceRemovePlayer and others. The naming convention should contain the words add and/or remove when you are working with structures like linked list, linear stacks, Tables and any other "containing" element which may be utilized or invented.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
From an IM sent to Bribe concerning the add/remove bit

I think that we need to have a discussion with the JASS experts in the community before we decide on a naming convention for add/remove.


I can give examples of resources from the wc3c snobs that use standard operation names and add/remove names.

JASS only uses add/remove because each of their collections only supports one operation. In the case of a collection that supports only a single add operation and a single remove operation, add/remove do indeed make sense. I think that justifying add/remove be part of all collections given the limited scope of the collections present in JASS is a weak assertion at best.


create/destroy and allocate/deallocate are obvious because they are the standard method names used by jasshelper. It doesn't make sense to use new/delete in this case because the language that these operations are being written for use different names.

I am also going to point out that there are 2 collections that have multiple add operations, these add operations being based on type. Instead of Add, they use Save/Store.



I would stay away from trying to enforce collection operation names unless we get a pretty overwhelming consensus from the community on what the names should be, like with the case of create/destroy.

I also don't know that the "math" spacing thing should be in the JPAG, or rather if it is, it should be marked as optional. There is no overwhelming consensus on how math operations should be spaced.


I recommended "Ex" because this has been used in every case when expanding on an existing function. I'm not sure who started it, but everyone uses it now. The same can't be said for add/remove, either in the JASS language, in jasshelper, or in the users of the language.


Thanks, ^_^
 

Deleted member 219079

D

Deleted member 219079

Is there stance on inverse comparison logic:
exitwhen null == FoG vs exitwhen FoG == null
 

Deleted member 219079

D

Deleted member 219079

Then I will use the first one, thanks for answering.
 
Top