• 🏆 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] Help with a real array

Status
Not open for further replies.
Level 4
Joined
Sep 18, 2007
Messages
104
Intro:

I've haven't touched WC3 for a while, hence I haven't touched the editor in a while. A friend asked me to help him with some triggers on a map and I am not as in touch with JASS as I used to be and I have reached a problem. Hoping someone can help, I am sure it's an easy fix, thanks in advance.

Problem:

JASS:
globals
    integer EastBattleRegion
    integer MidSouthBattleRegion
    integer NorthEastBattleRegion
    integer NorthWestBattleRegion
    integer SouthWestBattleRegion
endglobals
function Yuan_Battle_Actions takes nothing returns nothing
    local real array r
    local location loc1 = GetUnitLoc(GetTriggerUnit())
    local location loc2
    if ( IsUnitEnemy(GetTriggerUnit(), Player(0)) == true ) then
        call PauseUnit(GetTriggerUnit(), true)
        call PauseUnit(gg_unit_h006_0018, true)

                set loc2 = GetRectCenter(gg_rct_East_Battle_Region)
                set r[EastBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                set loc2 = GetRectCenter(gg_rct_MidSouth_Battle_Region)
                set r[MidSouthBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                set loc2 = GetRectCenter(gg_rct_NorthEast_Battle_Region)
                set r[NorthEastBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                set loc2 = GetRectCenter(gg_rct_NorthWest_Battle_Region)
                set r[NorthEastBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                set loc2 = GetRectCenter(gg_rct_SouthWest_Battle_Region)
                set r[SouthWestBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                if ( (r[EastBattleRegion]) <= ((r[MidSouthBattleRegion]) and (r[NorthEastBattleRegion]) and (r[NorthWestBattleRegion]) and (r[SouthWestBattleRegion])) ) then //This line causes an error
                    //Move to East Battle Region
                    
                    elseif ( (r[MidSouthBattleRegion]) <= ((r[NorthEastBattleRegion]) and (r[NorthWestBattleRegion]) and (r[SouthWestBattleRegion])) ) then //This line causes an error
                        //Move to MidSouth Battle Region
                    elseif ( (r[NorthEastBattleRegion]) <= ((r[NorthWestBattleRegion]) and (r[SouthWestBattleRegion])) ) then //This line causes an error.
                        //Move to NorthEast Battle Region 
                    elseif ( (r[NorthWestBattleRegion]) <= (r [SouthWestBattleRegion]) ) then 
                        //Move to NorthWest Battle Region
                    else
                        //Move to SouthWest Battle Region    
                    
                endif
    endif
endfunction

//===========================================================================
function XiahouYuanBattle takes nothing returns nothing
    local trigger YuanBattle = CreateTrigger()
    call TriggerRegisterUnitInRangeSimple( YuanBattle, 50.00, gg_unit_h006_0018 )
    call TriggerAddAction( YuanBattle, function Yuan_Battle_Actions )
endfunction

The synthax checker gives me the errors:
-See below(post 5)

If you need any other info, just ask.
 
Last edited:
Level 4
Joined
Sep 18, 2007
Messages
104
Ah, that was one of the problems, I forgot to declare the variables. I updated the first post with the globals and the synthax errors that are left. Thanks.
 
Level 9
Joined
Nov 28, 2008
Messages
704
if ( (r[EastBattleRegion]) <= ((r[MidSouthBattleRegion]) and (r[NorthEastBattleRegion]) and (r[NorthWestBattleRegion]) and (r[SouthWestBattleRegion])) )

This is not C++. Sorry, those have to be equal to, less than, or greater than or something. If you want to check if they "exist" like you would do in C++ (if 1) then you can try != null.

You should try to aavoid using locations, or at least clean up your links.

Your indenting on the elseifs is way off. The else ifs tabbing should be the same as the starting if block.
 
Level 4
Joined
Sep 18, 2007
Messages
104
Thanks. I have seemed to run into another problem and will post it here instead of a new thread.

I know the code is ugly, but bare with me, this is just mach code, the optimizing should come later. Towards the bottom of this trigger is the function ToEastBattleRegion , which I call in the second trigger. And yes the first trigger comes before the second trigger in the trigger editor. The problem is that the synthax error is undeclared function : ToEastBattleRegion.

The actions just repeat, one set for each region the units will spawn in.

JASS:
globals
    group EastRegionWei
    group EastRegionShu
        group MidSouthWei
        group MidSouthShu
    group NorthEastWei
    group NorthEastShu
        group NorthWestWei
        group NorthWestShu
    group SouthWestWei
    group SouthWestShu
endglobals

function EastBattle_Code takes nothing returns nothing
    call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Wei_Spawn_1 ))
endfunction

function EastBattle_Actions takes nothing returns nothing
    call ForGroup( GetRandomSubGroup(11, EastRegionWei), function EastBattle_Code )
endfunction

    function EastBattle_Code2 takes nothing returns nothing
        call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Wei_Spawn_2 ))
    endfunction

    function EastBattle_Actions2 takes nothing returns nothing
        call ForGroup( GetRandomSubGroup(10, EastRegionWei), function EastBattle_Code2 )
    endfunction
    
        function EastBattle_Code3 takes nothing returns nothing
            call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Wei_Spawn_3 ))
        endfunction

        function EastBattle_Actions3 takes nothing returns nothing
            call ForGroup( GetRandomSubGroup(10, EastRegionWei), function EastBattle_Code3 )
        endfunction
        
            function EastBattle_Code4 takes nothing returns nothing
                call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Wei_Spawn_4 ))
            endfunction

            function EastBattle_Actions4 takes nothing returns nothing
                call ForGroup( GetRandomSubGroup(10, EastRegionWei), function EastBattle_Code4 )
            endfunction
            
                function EastBattle_Code5 takes nothing returns nothing
                    call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Wei_Spawn_5 ))
                endfunction

                function EastBattle_Actions5 takes nothing returns nothing
                    call ForGroup( GetRandomSubGroup(10, EastRegionWei), function EastBattle_Code5 )
                endfunction
                //Shu...
                function EastBattle_Code6 takes nothing returns nothing
                    call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Shu_1 ))
                endfunction

                function EastBattle_Actions6 takes nothing returns nothing
                    call ForGroup( GetRandomSubGroup(11, EastRegionShu), function EastBattle_Code6 )
                endfunction
                
            function EastBattle_Code7 takes nothing returns nothing
                call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Shu_2 ))
            endfunction

            function EastBattle_Actions7 takes nothing returns nothing
                call ForGroup( GetRandomSubGroup(10, EastRegionShu), function EastBattle_Code7 )
            endfunction
            
        function EastBattle_Code8 takes nothing returns nothing
            call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Shu_3 ))
        endfunction

        function EastBattle_Actions8 takes nothing returns nothing
            call ForGroup( GetRandomSubGroup(10, EastRegionShu), function EastBattle_Code8 )
        endfunction
        
    function EastBattle_Code9 takes nothing returns nothing
        call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Shu_4 ))
    endfunction

    function EastBattle_Actions9 takes nothing returns nothing
        call ForGroup( GetRandomSubGroup(10, EastRegionShu), function EastBattle_Code9 )
    endfunction
    
function EastBattle_Code10 takes nothing returns nothing
    call SetUnitPositionLoc( GetEnumUnit(), GetRectCenter(gg_rct_East_Shu_5 ))
endfunction

function EastBattle_Actions10 takes nothing returns nothing
    call ForGroup( GetRandomSubGroup(10, EastRegionShu), function EastBattle_Code10 )
endfunction

//===========================================================================
function ToEastBattleRegion takes group a, group b returns nothing
    local trigger trig = CreateTrigger()
    set EastRegionWei = a
    set EastRegionShu = b
    call TriggerAddAction( trig, function EastBattle_Actions )
    call TriggerAddAction( trig, function EastBattle_Actions2 )
    call TriggerAddAction( trig, function EastBattle_Actions3 )
    call TriggerAddAction( trig, function EastBattle_Actions4 )
    call TriggerAddAction( trig, function EastBattle_Actions5 )
    call TriggerAddAction( trig, function EastBattle_Actions6 )
    call TriggerAddAction( trig, function EastBattle_Actions7 )
    call TriggerAddAction( trig, function EastBattle_Actions8 )
    call TriggerAddAction( trig, function EastBattle_Actions9 )
    call TriggerAddAction( trig, function EastBattle_Actions10 )
endfunction

JASS:
globals
    integer EastBattleRegion
    integer MidSouthBattleRegion
    integer NorthEastBattleRegion
    integer NorthWestBattleRegion
    integer SouthWestBattleRegion
endglobals

function Yuan_Battle_Actions takes nothing returns nothing
    local real array r
    local location loc1 = GetUnitLoc(GetTriggerUnit())
    local location loc2
    if ( IsUnitEnemy(GetTriggerUnit(), Player(0)) == true ) then
        call PauseUnit(GetTriggerUnit(), true)
        call PauseUnit(gg_unit_h006_0018, true)

                set loc2 = GetRectCenter(gg_rct_East_Battle_Region)
                set r[EastBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                set loc2 = GetRectCenter(gg_rct_MidSouth_Battle_Region)
                set r[MidSouthBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                set loc2 = GetRectCenter(gg_rct_NorthEast_Battle_Region)
                set r[NorthEastBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                set loc2 = GetRectCenter(gg_rct_NorthWest_Battle_Region)
                set r[NorthWestBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                set loc2 = GetRectCenter(gg_rct_SouthWest_Battle_Region)
                set r[SouthWestBattleRegion] = DistanceBetweenPoints(loc1, loc2)
                
                if ( ((r[EastBattleRegion]) <= (r[MidSouthBattleRegion])) and ((r[EastBattleRegion]) <= (r[NorthEastBattleRegion])) and ((r[EastBattleRegion]) <= (r[NorthWestBattleRegion])) and ((r[EastBattleRegion]) <= (r[SouthWestBattleRegion])) ) then
                    call ToEastBattleRegion(XiahouYuanUnits, ZhangFeiUnits)
                    //Move to East Battle Region
                    
                elseif ( ((r[MidSouthBattleRegion]) <= (r[NorthEastBattleRegion])) and ((r[MidSouthBattleRegion]) <= (r[NorthWestBattleRegion])) and ((r[MidSouthBattleRegion]) <= (r[SouthWestBattleRegion])) ) then
                        //Move to MidSouth Battle Region
                elseif ( ((r[NorthEastBattleRegion]) <= (r[NorthWestBattleRegion])) and ((r[NorthEastBattleRegion]) <= (r[SouthWestBattleRegion])) ) then
                        //Move to NorthEast Battle Region
                elseif ( (r[NorthWestBattleRegion]) <= (r[SouthWestBattleRegion]) ) then
                        //Move to NorthWest Battle Region
                else
                        //Move to SouthWest Battle Region    
                    
                endif
    endif
endfunction

//===========================================================================
function XiahouYuanBattle takes nothing returns nothing
    local trigger YuanBattle = CreateTrigger()
    call TriggerRegisterUnitInRangeSimple( YuanBattle, 50.00, gg_unit_h006_0018 )
    call TriggerAddAction( YuanBattle, function Yuan_Battle_Actions )
endfunction
 
Level 4
Joined
Sep 18, 2007
Messages
104
I do use JNGP. I know my indenting is terrible, but for some reason it is easier for me to read. I don't understand your first sentence, I don't think I mixed GUI variables with JASS.
 
Level 9
Joined
Nov 28, 2008
Messages
704
Those functions are not neccessarily above each other. Just because the trigger names are means nothing.

Put the one with a function that you want to call and be above it so it finds it into a library.

library somethingrather

endlibrary

Just put everything between those lines and you can call it properly.

WC3 is weird like that. Which is why we have vJass.

Edit: alternatively, use .evaluate. Ie set x = funcnname.evaluate(parameter1, parameter2) instead of set x = funcname(para1, para2)
 
Last edited:
Status
Not open for further replies.
Top