| 01-29-2006, 01:31 AM | #1 |
after several hours I gladly finished a custom ability based off immolation and animate dead. It's supposed to increase the power of blighted ground around undead buildings: Enemy units take 2 hp damage over time, and with a certain chance some are directly converted into these purple undead. (animate death with targets allowed alive, ground, organic) One hour later I even finished my custom icons. Neat, and plays fine: At some point in game the converted units wouldn't belong to me any more, but to the computer opponent funny, init?Five minutes later I get a super-special Error Message the Memory could not be read, Warcraft has to be closed. that's the story. my script is pretty simple, but maybe there's something not correct with it. Better check it out yourself... Code:
function touchoevil takes nothing returns nothing
local real x
local real y
local player p
local unit u
if IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == true and UnitHasBuffBJ( GetTriggerUnit(), 'B004') == true and IsUnitType(GetAttacker(), UNIT_TYPE_HERO) == false and IsUnitType(GetAttacker(), UNIT_TYPE_FLYING) == false and IsUnitType(GetAttacker(), UNIT_TYPE_MECHANICAL) == false then
call DisableTrigger( gg_trg_touchoevil )
set p = GetOwningPlayer(GetTriggerUnit())
set x = GetUnitX(GetTriggerUnit())
set y = GetUnitY(GetTriggerUnit())
set u = CreateUnit( p, 'n007', x, y, 0.00 )
call TriggerSleepAction( 1.00 )
call IssueImmediateOrderBJ( u, "creepanimatedead" )
call TriggerSleepAction( 15.00 )
call RemoveUnit( u )
set u = null
set p = null
set x = 0
set y = 0
call EnableTrigger( gg_trg_touchoevil)
endif
endfunction
//===========================================================================
function InitTrig_touchoevil takes nothing returns nothing
set gg_trg_touchoevil = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_touchoevil, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddAction( gg_trg_touchoevil, function touchoevil)
endfunction |
| 01-29-2006, 01:52 AM | #2 |
I can't find a good reason for a crash but the condition of the if is at least ambiguous (I don't know what is the and affecting, the result of == or the true . And the code was horrible. There was no reason at all for the x,y and p variables and you were not making needed variables for things like GetTriggerUnit or GetAttacker() , few people knows that if you are going to use an event response 2 or more times you have to make a loca - makes the code easier to read and it is faster. You were seting x and y to 0 there is no reason at all to do so. You were using Evil BJ functions like IssueImmediateOrderBJ or UnitHasBuffBJ JASS:function touchoevil takes nothing returns nothing local unit u=GetTriggerUnit() local unit a =GetAttacker() if IsUnitType(u, UNIT_TYPE_STRUCTURE) and (GetUnitAbilityLevel(u, 'B004')>0) and (not IsUnitType(a, UNIT_TYPE_HERO)) and (IsUnitType(a, UNIT_TYPE_FLYING)) and (IsUnitType(a, UNIT_TYPE_MECHANICAL)) then call DisableTrigger( gg_trg_touchoevil ) set u = CreateUnit( GetOwningPlayer(u), 'n007', GetUnitY(u), GetUnitX(u), 0.00 ) call TriggerSleepAction( 1.0 ) call IssueImmediateOrder( u, "creepanimatedead" ) call TriggerSleepAction( 15.0 ) call RemoveUnit( u ) call EnableTrigger( gg_trg_touchoevil) endif set a=null set u=null endfunction //=========================================================================== function InitTrig_touchoevil takes nothing returns nothing set gg_trg_touchoevil = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_touchoevil, EVENT_PLAYER_UNIT_ATTACKED ) call TriggerAddAction( gg_trg_touchoevil, function touchoevil) endfunction And finally you were using [code] tags instead of [jass] tags |
| 01-29-2006, 12:59 PM | #3 |
Thanks Vex! it runs stable now. I'm glad about that! 2 things: - X coordinate comes first - for some reason the conditions have to be compared with the boolean equivalents. I don't know why, but according to my text message it wouldn't pass the "if" otherwise |
| 01-29-2006, 06:55 PM | #4 |
on if statements it should work fine. If you end doing something as awful as comparing things to boolean equivalents thne at least use brackets ( ) to aboid ambigiousness |
