|
今天发布电子书,征集书中的BUG;随后有朋友给我消息,说Return Bug+GameCache的应用(一)中,老狼的代码加入图中会导致崩溃,于是,我看了下这段代码:
[codes=jass]
function H2I takes handle h returns integer
return h
return 0
endfunction
function I2TC takes integer i returns triggercondition
return i
return null
endfunction
function I2TG takes integer i returns trigger
return i
return null
endfunction
function DestroyTriggerAllById takes integer t returns nothing
call TriggerRemoveCondition(I2TG(t),I2TC(GetStoredInteger (udg_GC,I2S(t),"TriggerCondition")))
call DestroyTrigger(I2TG(t))
call FlushStoredMission(udg_GC,I2S(t))
endfunction
function DestroyTriggerAll takes trigger trg returns nothing
call TriggerRemoveCondition(trg,I2TC(GetStoredInteger(udg_GC,I2S(H2I(trg)),"TriggerCondition")))
call DestroyTrigger(trg)
call FlushStoredMission(udg_GC,I2S(H2I(trg)))
endfunction
//========================================================
function RegisterUnitAmortCond takes nothing returns nothing
call SetUnitInvulnerable(GetTriggerUnit(), true)
call DestroyTriggerAll(GetTriggeringTrigger())
endfunction
function RegisterUnitAmortEvent takes unit witchUnit returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterUnitStateEvent(trg, witchUnit, UNIT_STATE_LIFE, LESS_THAN_OR_EQUAL, 50)
call StoreInteger(udg_GC,I2S(H2I(trg)),"TriggerCondition",H2I (TriggerAddCondition(trg,Condition(function RegisterUnitAmortCond))))
set trg = null
endfunction[/codes]
这段代码横看竖看都没问题,于是我把它加进地图,果然,弹出来了.于是我暂时把代码中的条件换成了动作
[codes=jass]
function H2I takes handle h returns integer
return h
return 0
endfunction
function I2TA takes integer i returns triggeraction
return i
return null
endfunction
function I2TG takes integer i returns trigger
return i
return null
endfunction
function DestroyTriggerAllById takes integer t returns nothing
call TriggerRemoveAction(I2TG(t),I2TA(GetStoredInteger (udg_GC,I2S(t),"Triggeraction")))
call DestroyTrigger(I2TG(t))
call FlushStoredMission(udg_GC,I2S(t))
endfunction
function DestroyTriggerAll takes trigger trg returns nothing
call TriggerRemoveAction(trg,I2TA(GetStoredInteger(udg_GC,I2S(H2I(trg)),"Triggeraction")))
call DestroyTrigger(trg)
call FlushStoredMission(udg_GC,I2S(H2I(trg)))
endfunction
//========================================================
function RegisterUnitAmortAction takes nothing returns nothing
call SetUnitInvulnerable(GetTriggerUnit(), true)
call DestroyTriggerAll(GetTriggeringTrigger())
endfunction
function RegisterUnitAmortEvent takes unit witchUnit returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterUnitStateEvent(trg, witchUnit, UNIT_STATE_LIFE, LESS_THAN_OR_EQUAL, 50)
call StoreInteger(udg_GC,I2S(H2I(trg)),"Triggeraction",H2I (TriggerAddAction(trg,function RegisterUnitAmortAction)))
set trg = null
endfunction[/codes]
运行下,没有问题;因此朋友交给我的任务完成了.不过为何用动作没有问题,而用条件会弹出游戏呢.经过尝试,发现个非常有趣的BUG,大家看这行代码
[codes=jass]
function H2I takes handle h returns integer
return h
return 0
endfunction
function I2TC takes integer i returns triggercondition
return i
return null
endfunction
function I2TG takes integer i returns trigger
return i
return null
endfunction
function DestroyTriggerAllById takes integer t returns nothing
call TriggerRemoveCondition(I2TG(t),I2TC(GetStoredInteger (udg_GC,I2S(t),"TriggerCondition")))
call DestroyTrigger(I2TG(t))
call FlushStoredMission(udg_GC,I2S(t))
endfunction
function DestroyTriggerAll takes trigger trg returns nothing
call TriggerRemoveCondition(trg,I2TC(GetStoredInteger(udg_GC,I2S(H2I(trg)),"TriggerCondition")))
call DestroyTrigger(trg)
call FlushStoredMission(udg_GC,I2S(H2I(trg)))
call BJDebugMsg(I2S(0))
endfunction
//========================================================
function RegisterUnitAmortCond takes nothing returns nothing
call SetUnitInvulnerable(GetTriggerUnit(), true)
call DestroyTriggerAll(GetTriggeringTrigger())
endfunction
function RegisterUnitAmortEvent takes unit witchUnit returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterUnitStateEvent(trg, witchUnit, UNIT_STATE_LIFE, LESS_THAN_OR_EQUAL, 50)
call StoreInteger(udg_GC,I2S(H2I(trg)),"TriggerCondition",H2I (TriggerAddCondition(trg,Condition(function RegisterUnitAmortCond))))
set trg = null
endfunction[/codes]
大家看这段代码有什么不同,无非是加了段call BJDebugMsg(I2S(0)),这个纠错函数,其实就是显示个字符在屏幕上,并不会影响程序运行,但不可思议的事发生了,这段代码加入后,游戏不会弹出了.
或许你还没明白我在说什么,我想说的是,将一个语法上百分百没有错误的代码,加入到地图后百分百会弹出,但加了个百分百没有用的call BJDebugMsg(I2S(0))后,游戏就不会出错.
是不是一个很有趣的BUG~
放上演示,大家不妨试试,去掉代码中的call BJDebugMsg(I2S(0)),就会弹出游戏. |
|