• 🏆 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!

jass is so disgusting looking

Status
Not open for further replies.
Level 4
Joined
Aug 18, 2013
Messages
71
I'm having an issue finding all my ifs and end ifs. I had everything nice and indented. but after adding about 10 lines of code, its all fucked up. Now I have to start from scratch because the code is missing end ifs/end loops, even though they are there. Why is jass so shitty structurally compared to other languages like c++

the bracket system is so much more organized
Code:
int main(params)
{
   while(condition)//loop
   {
       if(condition)
       {
        function(u,0,0);//random function thingy
       }//end if
       else
       {
        other shit going on;
       }//end else
    }//end while
return 0;
}//end function
compared to
JASS:
function derp take nothing returns nothing
   loop
   exitwhen conditon
       if(condition) then
           function(u,0,0);//random function thingy
       else
           other shit going on;
       endif
    endloop
endfunction


anyone get mad at this system because its virtually impossible to find out what you mixed up?

JASS:
function Trig_SufferingPriest_Loop_Actions takes nothing returns nothing//
    local integer rand = GetRandomInt(0,100)
    local integer chance = 0
    local boolean silence = false
    set udg_Gen_CIndex = 1
    loop//
        exitwhen udg_Gen_CIndex > udg_Gen_MIndex
        set udg_Gen_Counter[udg_Gen_CIndex] = ( udg_Gen_Counter[udg_Gen_CIndex] + 1 )
        call CreateNUnitsAtLoc( 1, 'e007', udg_Gen_Player[udg_Gen_CIndex], GetUnitLoc(udg_Gen_Caster[udg_Gen_CIndex]), bj_UNIT_FACING )
        set udg_Gen_Dummy[udg_Gen_CIndex] = GetLastCreatedUnit()
        // Affliction
        if ( udg_Gen_Abil[udg_Gen_CIndex] == 'A03Z'() ) then //4
            if ( udg_Gen_AbilLevel[udg_Gen_CIndex] == 1 ) then//3
                set chance = 7
                else
                    if ( udg_Gen_AbilLevel[udg_Gen_CIndex] == 2 ) then //2
                        set chance = 10
                    else
                        if ( udg_Gen_AbilLevel[udg_Gen_CIndex] == 3 ) then //1
                            set chance = 14
                            else
                                set chance = 20
                        endif//end level 3 and 4 //1
                    endif//end level 2 //2
                endif//end level 1 //3
            endif//4
            if(chance >= rand)then
                set udg_Gen_Damage[udg_Gen_CIndex] = udg_Gen_Damage[udg_Gen_CIndex]+ (GetHeroInt(udg_Gen_Caster[udg_Gen_CIndex],true)/2)
                set silence = true
                call UnitAddAbility(udg_Gen_D,'A047')
            endif//end chance //
        endif//
        call ForGroupBJ( udg_Gen_TargetG[udg_Gen_CIndex], function Trig_SufferingPriest_Loop_Func001Func005Func002A )
        // Affliction END
        set udg_Gen_CIndex = udg_Gen_CIndex + 1
    endloop//
endfunction//
cant figure this shit out for my life

PS: before people tell me i'm using BJ and other inefficient code I know. But Its converted gui. I'm just finishing what I wanted to get done first, then I was gonna go back and change everything
 
You have an extra endif. Btw, it really isn't that bad if you indent properly:
JASS:
function Trig_SufferingPriest_Loop_Actions takes nothing returns nothing//
    local integer rand = GetRandomInt(0,100)
    local integer chance = 0
    local boolean silence = false
    set udg_Gen_CIndex = 1
    
    loop//
        exitwhen udg_Gen_CIndex > udg_Gen_MIndex
        set udg_Gen_Counter[udg_Gen_CIndex] = ( udg_Gen_Counter[udg_Gen_CIndex] + 1 )
        call CreateNUnitsAtLoc( 1, 'e007', udg_Gen_Player[udg_Gen_CIndex], GetUnitLoc(udg_Gen_Caster[udg_Gen_CIndex]), bj_UNIT_FACING )
        set udg_Gen_Dummy[udg_Gen_CIndex] = GetLastCreatedUnit()

        // Affliction
        if ( udg_Gen_Abil[udg_Gen_CIndex] == 'A03Z'() ) then //4
            if ( udg_Gen_AbilLevel[udg_Gen_CIndex] == 1 ) then//3
                set chance = 7
            else
                if ( udg_Gen_AbilLevel[udg_Gen_CIndex] == 2 ) then //2
                    set chance = 10
                else
                    if ( udg_Gen_AbilLevel[udg_Gen_CIndex] == 3 ) then //1
                        set chance = 14
                    else
                        set chance = 20
                    endif//end level 3 and 4 //1
                endif//end level 2 //2
            endif//end level 1 //3
        endif//4

        if(chance >= rand)then
            set udg_Gen_Damage[udg_Gen_CIndex] = udg_Gen_Damage[udg_Gen_CIndex]+ (GetHeroInt(udg_Gen_Caster[udg_Gen_CIndex],true)/2)
            set silence = true
            call UnitAddAbility(udg_Gen_D,'A047')
        endif//end chance //

        call ForGroupBJ( udg_Gen_TargetG[udg_Gen_CIndex], function Trig_SufferingPriest_Loop_Func001Func005Func002A )
        // Affliction END
        set udg_Gen_CIndex = udg_Gen_CIndex + 1
    endloop//
endfunction//

Spacing helps too.

Also, I highly recommend using JNGP for coding in JASS because it has a built-in syntax highlighter (unless you're already using it).

And yes, the verbosity of JASS is kind of annoying when you are used to some other programming language. If you want brackets and junk, you should look into Zinc:
http://www.wc3c.net/vexorian/zincmanual.html
(similar to vJASS, a more c-like syntax)
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
I do not get it? In your c++ example, you have not consistently indented either. And there is no structural difference other than that jass automatically opens a block and that it requires you to put the delimiters in separate lines (which you have done in your c++ example as well).

The differently named end-expressions are cumbersome to write and I do not know why you need to put a "then" after ifs but they make the block level more easily identifyable.

What do you think of indention-based blocks? Wurst by Frotty/peq swings that way.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
It's not that ugly, you're just not used to it. The if blocks aren't helping either, just use vertical spacing more often to alleviate the strain on the eyes. I always try to avoid the usage of if blocks if there are alternative ways of doing it.
 
I suggest you start using vJass (or at least Zinc like purge suggested) because the code can be much more organized.
Also, that code is converted from a GUI trigger which will result in really ugly code (it's generated ..), so you can't really blame the language for that.

Now, this is how your code should look;

JASS:
scope Trigger initializer Init

    globals
        private constant integer MAX_INDEX = 10
        private constant integer DUMMY_ID  = 'e007'
    endglobals
    
    private function Actions takes nothing returns nothing
        local integer rand    = GetRandomInt(0,100)
        local integer chance  = 0
        local integer i       = 1
        local integer array c
        local boolean silence = false
        
        loop
            exitwhen i > MAX_INDEX
            set c[i] = c[i] + 1
            set udg_Gen_Dummy[i] = CreateUnit(udg_Gen_Player[i], DUMMY_ID, GetUnitX(udg_Gen_Caster[i]), GetUnitY(udg_Gen_Caster[i]), 0)
            
            // Affliction
            if udg_Gen_Abil[i] == 'A03Z'() and udg_Gen_AbilLevel[i] == 1  then 
                set chance = 7
            elseif udg_Gen_AbilLevel[i] == 2 then
                set chance = 10
            elseif udg_Gen_AbilLevel[i] == 3 then
                set chance = 14
            else
                set chance = 20
           endif//end level 3 and 4 //1
                
            if(chance >= rand)then
                set udg_Gen_Damage[i] = udg_Gen_Damage[i]+ (GetHeroInt(udg_Gen_Caster[i],true)/2)
                set silence = true
                call UnitAddAbility(udg_Gen_D,'A047')
            endif
                
            endif
            
            call ForGroup( udg_Gen_TargetG[udg_Gen_CIndex], function Trig_SufferingPriest_Loop_Func001Func005Func002A )

            set i = i + 1
        endloop
    endfunction
    
    private function Init takes nothing returns nothing
        // EVENT
    endfunction

endscope

I'm not sure if it compiles, but you get the idea.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Agree with WaterKnight, there really is no difference using "}" or "end****". Actually the latter is even more informative since it tells you which kind of block is closed (endfunction, endif, endloop, endstruct...).

About ZinC i disagree. Was a nice idea but the result sucked.
- Its dead, nobody works on zinc or even thinks about updating it
- Not 100% compatible to vJass
- There are language features missing (compared to vjass)
- Less support since everyone us using vJass

And that only a little less verbosity and some shortcuts? No thank you...
 
Status
Not open for further replies.
Top