找回密码
 点一下
查看: 2121|回复: 9

DestroyCondition的用法?

[复制链接]
发表于 2008-8-30 02:21:48 | 显示全部楼层 |阅读模式
起初我以为是这样用,但这是不对的

[jass]
set cfunc = Condition(function func)
call DestroyCondition(cfunc )
[/jass]
发表于 2008-8-30 10:58:25 | 显示全部楼层
错了吗?
回复

使用道具 举报

发表于 2008-8-30 11:10:46 | 显示全部楼层
cfunc的类型是什么呢??
一般用boolexpr,然后DestroyBoolExpr就好了,如果用的是conditionfunc的话就DestroyCondition吧
回复

使用道具 举报

 楼主| 发表于 2008-8-30 12:16:54 | 显示全部楼层
这不是关键啊
[jass]
type conditionfunc extends boolexpr
native Condition        takes code func returns conditionfunc
native DestroyCondition takes conditionfunc c returns nothing
native DestroyBoolExpr  takes boolexpr e returns nothing
[/jass]

是boolexpr类型自然只能用DestroyBoolExpr  ,如果是conditionfunc,用DestroyCondition和DestroyBoolExpr语法上都没错,但用DestroyCondition是不对的,上面已经说过了.....
回复

使用道具 举报

 楼主| 发表于 2008-8-30 12:22:02 | 显示全部楼层
为什么DestroyCondition这样用不对呢

可以测试下这段代码
[jass]
function Test_Condition_A takes nothing returns boolean
    return false
endfunction

function Test_Condition_B takes nothing returns boolean
    return false
endfunction

function Test_Action_01 takes nothing returns nothing
    local conditionfunc A = Condition(function Test_Condition_A)
    local conditionfunc B = Condition(function Test_Condition_B)

    call BJDebugMsg(H2S(A))
    call BJDebugMsg(H2S(B))
    call BJDebugMsg("----------")

    set A = null
    set B = null
endfunction

function Test_Action_02 takes nothing returns nothing
    local conditionfunc A = Condition(function Test_Condition_A)
    local conditionfunc B = Condition(function Test_Condition_B)

    call BJDebugMsg(H2S(A))
    call BJDebugMsg(H2S(B))
    call BJDebugMsg("----------")

    call DestroyCondition(A)
    call DestroyCondition(B)

    set A = null
    set B = null
endfunction

function Test_Action_03 takes nothing returns nothing
    local conditionfunc A = Condition(function Test_Condition_A)
    local conditionfunc B = Condition(function Test_Condition_B)

    call BJDebugMsg(H2S(A))
    call BJDebugMsg(H2S(B))
    call BJDebugMsg("----------")

    call DestroyBoolExpr(A)
    call DestroyBoolExpr(B)


    set A = null
    set B = null
endfunction

//===========================================================================
function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( t, Player(0), "1", true )
    call TriggerAddAction( t, function Test_Action_01 )

    set t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( t, Player(0), "2", true )
    call TriggerAddAction( t, function Test_Action_02 )

    set t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( t, Player(0), "3", true )
    call TriggerAddAction( t, function Test_Action_03 )
endfunction
[/jass]

如果用了Condition,而什么都不干,下次再使用,不会重复创造新的值
如用了DestroyCondition,直接泄露了..........
如用了DestroyBoolExpr ,handle了正常删除
回复

使用道具 举报

发表于 2008-8-30 12:24:29 | 显示全部楼层
好吧,关键就是继承关系,被继承类型出可以用所有继承者代入,而反过来就不可以,最常用的例子就是return bug,H2I的参数handle可以用任何继承handle的类型,但反过来I2U之类就要分开写
回复

使用道具 举报

 楼主| 发表于 2008-8-30 12:30:01 | 显示全部楼层
你再看清楚它们之间的继承关系,按照声明DestroyCondition才是正确的写法,之所以DestroyBoolExpr也能用,就是你上面所说的原因。但是现在是正牌的不对,冒牌的对

或许DestroyCondition不该这样用,或者它是其他功能,这就是我这个贴的问题
回复

使用道具 举报

发表于 2008-8-30 12:32:17 | 显示全部楼层
继承关系是conditionfunc继承自boolexpr,我记得很清楚,也看得很清楚,谢谢
回复

使用道具 举报

 楼主| 发表于 2008-8-30 12:35:22 | 显示全部楼层
那我后面的话,你就无视了   
回复

使用道具 举报

发表于 2008-8-30 12:39:05 | 显示全部楼层
后面的话我没想好回什么,而且貌似也灭东西好回,于是就不会咯………………
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-7-21 06:23 , Processed in 0.120598 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表