HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

how to attach booleans

11-23-2006, 01:51 AM#1
slivling
to test what i have learned about scripting and cscache, i have tried to replicate the dota-allstars ability "morph"

i created a unit that has an ability based on essence of blight, and replenish. now i have these scripts.

Collapse JASS:
function Trig_morph_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'Hamg' ) ) then
        return false
    endif
    return true
endfunction

function Trig_morph_Actions takes nothing returns nothing
local unit t = GetTriggerUnit()
local string morphstr
local string morphagi 
local timer morphtimer = CreateTimer()

if ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishlifeon") ) ) then
call AttachBoolean(t, morphstr, true)
call AttachBoolean(t, morphagi, false)

elseif ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaon") ) ) then
call AttachBoolean(t, morphstr, false)
call AttachBoolean(t, morphagi, true)
elseif ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaoff") ) ) then
call AttachBoolean(t, morphstr, false)
call AttachBoolean(t, morphagi, false)
elseif ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaoff") ) ) then
call AttachBoolean(t, morphstr, false)
call AttachBoolean(t, morphagi, false)
endif

set t = null
set morphstr = null
set morphagi = null
set morphtimer = null

endfunction

//===========================================================================
function InitTrig_morph takes nothing returns nothing
    set gg_trg_morph = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_morph, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerAddCondition( gg_trg_morph, Condition( function Trig_morph_Conditions ) )
    call TriggerAddAction( gg_trg_morph, function Trig_morph_Actions )
endfunction


this script works fine as far as i know. but i dont know how to actually return the boolean i stored. i tried this

Collapse JASS:
if ( not (  GetAttachedBoolean(GetTriggerUnit(), morphagi) == true ) ) then
call DisplayTimedTextToForce( GetPlayersAll(), 30, "agility" )
endif

but it gets a syntax error. how to i properly return the stored variable? thanks in advance.

a econd question, is there some tutorial for effectively using cscache?
11-23-2006, 03:06 AM#2
Vexorian
I would say you are doing everything wrong.

You are not initializing the strings. I think that you got the stuff wrong, badly.

I think that this is what you want to do:

Collapse JASS:
function Trig_morph_Actions takes nothing returns nothing
local unit t = GetTriggerUnit()
local timer morphtimer = CreateTimer()

if ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishlifeon") ) ) then
call AttachBoolean(t, "morphstr", true)
call AttachBoolean(t, "morphagi", false)

elseif ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaon") ) ) then
call AttachBoolean(t, "morphstr", false)
call AttachBoolean(t, "morphagi", true)
elseif ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaoff") ) ) then
call AttachBoolean(t, "morphstr", false)
call AttachBoolean(t, "morphagi", false)
elseif ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaoff") ) ) then
call AttachBoolean(t, "morphstr", false)
call AttachBoolean(t, "morphagi", false)
endif

set t = null
endfunction

And then:

Collapse JASS:
if ( not (  GetAttachedBoolean(GetTriggerUnit(), "morphagi" ) == true ) ) then
call DisplayTimedTextToForce( GetPlayersAll(), 30, "agility" )
endif
11-25-2006, 04:49 PM#3
slivling
well, after toying with the script for a bit, i decided booleans wouldnt be the way to go. here is my current script for the spell.

Collapse JASS:
function Trig_morph_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'Hamg' ) ) then
        return false
    endif
    return true
endfunction

function morphstrcancel_conditions takes nothing returns boolean
    if ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishlifeoff") ) ) then
        return true
    endif
    if ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaon") ) ) then
        return true
    endif
    return false
endfunction

function morphagicancel_conditions takes nothing returns boolean
    if ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishlifeon") ) ) then
        return true
    endif
    if ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaoff") ) ) then
        return true
    endif
    return false
endfunction

function morphstrcancel_actions takes nothing returns nothing
call PauseTimer( GetAttachedTimer(GetTriggeringTrigger(), "morphtimer"))
call DestroyTimer( GetAttachedTimer(GetTriggeringTrigger(), "morphtimer"))
call DestroyTrigger( GetAttachedTrigger(GetTriggeringTrigger(), "morphstr"))
call DestroyTrigger( GetTriggeringTrigger() )
endfunction

function morphagicancel_actions takes nothing returns nothing
call PauseTimer( GetAttachedTimer(GetTriggeringTrigger(), "morphtimer"))
call DestroyTimer( GetAttachedTimer(GetTriggeringTrigger(), "morphtimer"))
call DestroyTrigger( GetAttachedTrigger(GetTriggeringTrigger(), "morphagi"))
call DestroyTrigger( GetTriggeringTrigger() )
endfunction

function morphstrloop takes nothing returns nothing
call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_035" )
endfunction

function morphagiloop takes nothing returns nothing
call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_034" )
endfunction

function Trig_morph_Actions takes nothing returns nothing
local unit m = GetTriggerUnit()
local timer morphtimer
local trigger morphstrcancel 
local trigger morphagicancel
local trigger morphstr
local trigger morphagi

if ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishlifeon") ) then
set morphtimer = CreateTimer( )
call StartTimerBJ( morphtimer, true, 1.00 )
set morphstrcancel = CreateTrigger(  )
call TriggerRegisterAnyUnitEventBJ( morphstrcancel, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddCondition( morphstrcancel, Condition( function morphstrcancel_conditions ) )
call TriggerAddAction( morphstrcancel, function morphstrcancel_actions )
set morphstr = CreateTrigger(  )
call AttachObject(morphstrcancel, "morphstr", morphstr)
call AttachObject(morphstrcancel, "morphtimer", morphtimer)
call TriggerRegisterTimerExpireEvent( morphstr, ( GetAttachedTimer(morphstrcancel, "morphtimer")) )


endif

if ( GetIssuedOrderIdBJ() == String2OrderIdBJ("replenishmanaon") ) then
set morphtimer = CreateTimer( )
call StartTimerBJ( morphtimer, true, 1.00 )
set morphagicancel = CreateTrigger(  )
call TriggerRegisterAnyUnitEventBJ( morphagicancel, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddCondition( morphagicancel, Condition( function morphagicancel_conditions ) )
call TriggerAddAction( morphagicancel, function morphagicancel_actions )
set morphagi = CreateTrigger(  )
call AttachObject(morphagicancel, "morphagi", morphagi)
call AttachObject(morphagicancel, "morphtimer", morphtimer)
call TriggerRegisterTimerExpireEvent( morphagi, ( GetAttachedTimer(morphagicancel, "morphtimer")) )
endif

set morphtimer = null
set morphstrcancel = null
set morphagicancel = null
set morphstr = null
set morphagi = null
set m = null
endfunction

//===========================================================================
function InitTrig_morph takes nothing returns nothing
    set gg_trg_morph = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_morph, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerAddCondition( gg_trg_morph, Condition( function Trig_morph_Conditions ) )
    call TriggerAddAction( gg_trg_morph, function Trig_morph_Actions )
endfunction


what i am trying to do, is when the unit is ordered to turn the autocast on on its abilities, it is to start a loop that is ended when the autocast is turned off, or another autocast turned on. if you are familiar with the dota-allstars ability "morph" this should make more sense.

any help would be appreciated. i just read the jass tutorials a few days ago, and i could use a little clarification on how i might be using the cache system wrong.