HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

is there any way to simplify this?

06-02-2003, 07:47 AM#1
Ultramagnetic
This code is converted straight from GUI to JASS. Since I couldn't do it any other way in GUI, this is how it turned out, but I'm sure there's gotta be a way to clean all this code up somehow... Then again maybe not. It would be great if somebody could show me a simplified version of it... Here's the code:


function Trig_MistActions_LvL_1_trig_Func001001 takes nothing returns boolean
return ( udg_SpellLVL == 1 )
endfunction

function Trig_MistActions_LvL_1_trig_Func004002003 takes nothing returns boolean
return ( IsUnitAlly(GetTriggerUnit(), Player(0)) == true )
endfunction

function Trig_MistActions_LvL_1_trig_Func006002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

function Trig_MistActions_LvL_1_trig_Func008002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

function Trig_MistActions_LvL_1_trig_Func010002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

function Trig_MistActions_LvL_1_trig_Func012002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

function Trig_MistActions_LvL_1_trig_Func014002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

function Trig_MistActions_LvL_1_trig_Func016002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

function Trig_MistActions_LvL_1_trig_Actions takes nothing returns nothing
if ( Trig_MistActions_LvL_1_trig_Func001001() ) then
call CreateNUnitsAtLocFacingLocBJ( 1, 'eC00', Player(0), GetOrderPointLoc(), GetUnitLoc(GetTriggerUnit()) )
set udg_MistHealer = GetLastCreatedUnit()
set udg_MistTargs[1] = GetUnitsInRangeOfLocMatching(250.00, GetUnitLoc(udg_MistHealer), Condition(function Trig_MistActions_LvL_1_trig_Func004002003))
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func006002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func008002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func010002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func012002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func014002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func016002 )
call KillUnit( udg_MistHealer )
else
call DoNothing( )
endif
endfunction

//===========================================================================
function InitTrig_MistActions_LvL_1_trig takes nothing returns nothing
set gg_trg_MistActions_LvL_1_trig = CreateTrigger( )
call TriggerAddAction( gg_trg_MistActions_LvL_1_trig, function Trig_MistActions_LvL_1_trig_Actions )
endfunction
06-02-2003, 12:31 PM#2
Guest
First, rename your functions so they have a name that makes sense. Also, you have a repeated function, which you can combine into one and then call using a loop

Code:
function Trig_MistActions_LvL_1_trig_Func006002 takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

and all the ones that look like that, execpt with a different name, can be combined into one. Delete 5 of the 6, and change the last one to

Code:
function Trig_MistActions_LvL_1_trig_[b]IncreaseHealth[/b] takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

And then change all the function calls. You have a repeat here, so just use a loop.
On the first line, add
Code:
local integer i = 0

This will be used for counting purposes. Replace

Code:
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func006002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func008002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func010002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func012002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func014002 )
call TriggerSleepAction( 1.00 )
call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_Func016002 )

With
Code:
loop
    exitwhen i = 6
    call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_IncreaseHealth )
    call TriggerSleepAction( 1.00 )
    set i = i + 1
endloop

You can also replace some of those function conditions with direct conditions.

Here would be your function with the loop bit added in and one of the functions replaced.
Code:
function Trig_MistActions_LvL_1_trig_IsAlly takes nothing returns boolean
return ( IsUnitAlly(GetTriggerUnit(), Player(0)) == true )
endfunction

function Trig_MistActions_LvL_1_trig_IncreaseHealth takes nothing returns nothing
call SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 15.00 ) )
endfunction

function Trig_MistActions_LvL_1_trig_Actions takes nothing returns nothing
local integer i = 0
if ( udg_SpellLVL == 1 ) then
call CreateNUnitsAtLocFacingLocBJ( 1, 'eC00', Player(0), GetOrderPointLoc(), GetUnitLoc(GetTriggerUnit()) )
set udg_MistHealer = GetLastCreatedUnit()
set udg_MistTargs[1] = GetUnitsInRangeOfLocMatching(250.00, GetUnitLoc(udg_MistHealer), Condition(function Trig_MistActions_LvL_1_trig_IsAlly))

loop
    exitwhen i = 6
    call ForGroup( udg_MistTargs[1], function Trig_MistActions_LvL_1_trig_IncreaseHealth )
    call TriggerSleepAction( 1.00 )
    set i = i + 1
endloop
    call KillUnit( udg_MistHealer )
else
    call DoNothing( )
endif
endfunction
You can try to figure the rest out.
06-02-2003, 10:29 PM#3
Ultramagnetic
Thanks, and all that seems to work fine, but when I go to save it gives me

line 43: Expected "=="


figured it out . In the loop "exitwhen i = 6" should be "exitwhen i == 6"
06-03-2003, 12:49 AM#4
Guest
Sorry about that.
06-03-2003, 01:13 AM#5
Ultramagnetic
another thing... I have an integer variable that's part of that same block of actions. One I use to detect spell lvl.


is that 'local integer i = 0' function going to mess with it? Because it looks like it is when I test my spell and the actions of each lvl look like they're one lvl behind. IE: lvl 1 works fine, lvl 2 does lvl 1 actions, and lvl 3 does lvl 2 actions.