# [JASS] Help with a real array

Discussion in 'Triggers & Scripts' started by chaoslord301, Jan 29, 2010.

1. ### chaoslord301

Joined:
Sep 18, 2007
Messages:
105
Resources:
0
Resources:
0
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:

Trigger
Code (vJASS):

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: Jan 29, 2010
2. ### Marcelo Hossomi

Joined:
Dec 31, 2005
Messages:
710
Resources:
3
Models:
2
Spells:
1
Resources:
3
Where have you declared these variables?

If they're globals, remember you have to use udg_ prefix for them: udg_EastBattleRegion.

3. ### chaoslord301

Joined:
Sep 18, 2007
Messages:
105
Resources:
0
Resources:
0
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.

4. ### Mooglefrooglian

Joined:
Nov 28, 2008
Messages:
701
Resources:
0
Resources:
0
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.

5. ### chaoslord301

Joined:
Sep 18, 2007
Messages:
105
Resources:
0
Resources:
0
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.

To Battle
Code (vJASS):
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

Battle Measure
Code (vJASS):
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

6. ### Anachron

Joined:
Sep 9, 2007
Messages:
6,221
Resources:
66
Icons:
49
Packs:
2
Tools:
1
Maps:
3
Spells:
9
Tutorials:
1
JASS:
1
Resources:
66
You have mixed GUI variables with JASS?
You also have a really bad indenting.
Also, use JNGP. It displays errors better.

7. ### chaoslord301

Joined:
Sep 18, 2007
Messages:
105
Resources:
0
Resources:
0
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.

8. ### Mooglefrooglian

Joined:
Nov 28, 2008
Messages:
701
Resources:
0
Resources:
0
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: Jan 30, 2010
9. ### Reaper2008

Joined:
Jul 27, 2008
Messages:
1,117
Resources:
1
Spells:
1
Resources:
1
Just put everything except the initializers in the map header, or merge their triggers and initializers.

10. ### chaoslord301

Joined:
Sep 18, 2007
Messages:
105
Resources:
0
Resources:
0
Thanks, it worked. Totally forgot about libraries.