找回密码
 点一下
查看: 1832|回复: 4

局部变量问题.缺少数组引索

[复制链接]
发表于 2010-6-15 15:32:18 | 显示全部楼层 |阅读模式
我不太懂J.现在处于用T写好触发,再转J.然后替换全局变量为局部变量.
有个很大的疑问.
就是我发现.我在函数的action动作中声明局部变量后.接下来如果有循环动作,或者IF/THEN之类的分隔型动作的时候----我之前在函数开头声明的局部变量会无效....情况不一而论,结果都是不能用.....我自己想不明白.特地请教一下.
下面是个例子:     
local location  array xhd 这个局部变量出问题....

function Trig____________________001______________u_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A09S' ) ) then
        return false
    endif
    return true
endfunction
function Trig____________________001______________u_Actions takes nothing returns nothing
    local integer  array dian
    local location  array xhd
    local location  dian2
    local unit danwei
    set danwei = GetTriggerUnit()
    set dian2= GetUnitLoc(danwei)
    set dian[0] = ( GetHeroStr(GetSpellAbilityUnit(), true) + ( GetHeroAgi(GetSpellAbilityUnit(), true) + GetHeroInt(GetSpellAbilityUnit(), true) ) )
    set dian[1] = GetUnitLevel(GetSpellAbilityUnit())
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set xhd[0] = PolarProjectionBJ(dian, 600.00, ( 36.00 * I2R(GetForLoopIndexA()) ))
        call CreateNUnitsAtLoc( 1, 'e006', GetOwningPlayer(danwei), xhd[0], ( 36.00 * I2R(GetForLoopIndexA()) ) )
        call UnitApplyTimedLifeBJ( 3.00, 'BHwe', GetLastCreatedUnit() )
        call RemoveLocation( xhd[0] )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call TriggerSleepAction( 2.00 )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set xhd[1] = PolarProjectionBJ(dian, 500.00, ( 36.00 * I2R(GetForLoopIndexA()) ))
        call CreateNUnitsAtLoc( 1, 'e007', GetOwningPlayer(danwei), xhd[1], ( 36.00 * I2R(GetForLoopIndexA()) ) )
        call UnitApplyTimedLifeBJ( 3.00, 'BHwe', GetLastCreatedUnit() )
        call RemoveLocation( xhd[1] )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set xhd[2] = PolarProjectionBJ(dian, -300.00, GetUnitFacing(danwei))
    call CreateNUnitsAtLoc( 1, 'e008', GetOwningPlayer(danwei), xhd[2], GetUnitFacing(danwei) )
    call UnitApplyTimedLifeBJ( 3.00, 'BHwe', GetLastCreatedUnit() )
    call RemoveLocation( xhd[2] )
    call TriggerSleepAction( 1.00 )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 30
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set xhd[3] = PolarProjectionBJ(dian, ( 60.00 * I2R(GetForLoopIndexA()) ), GetUnitFacing(danwei))
        call AddSpecialEffectLocBJ( xhd[3], "Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl" )
        call UnitDamagePointLoc( GetSpellAbilityUnit(), 0, 500, xhd[3], I2R(( dian[0] * dian[1] )), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL )
        call RemoveLocation( xhd[3] )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 30
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set xhd[4] = PolarProjectionBJ(dian, ( 60.00 * I2R(GetForLoopIndexA()) ), ( GetUnitFacing(danwei) - 45.00 ))
        call AddSpecialEffectLocBJ( xhd[4], "Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl" )
        call UnitDamagePointLoc( GetSpellAbilityUnit(), 0, 500, xhd[4], I2R(( dian[0] * dian[1] )), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL )
        call RemoveLocation( xhd[4] )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 30
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set xhd[5] = PolarProjectionBJ(dian, ( 60.00 * I2R(GetForLoopIndexA()) ), ( GetUnitFacing(danwei) + 45.00 ))
        call AddSpecialEffectLocBJ( xhd[5], "Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl" )
        call UnitDamagePointLoc( GetSpellAbilityUnit(), 0, 500, xhd[5], I2R(( dian[0] * dian[1] )), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL )
        call RemoveLocation( xhd[5] )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call RemoveLocation( dian2)
endfunction
//===========================================================================
function InitTrig____________________001______________u takes nothing returns nothing
    set gg_trg____________________001______________u = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg____________________001______________u, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg____________________001______________u, Condition( function Trig____________________001______________u_Conditions ) )
    call TriggerAddAction( gg_trg____________________001______________u, function Trig____________________001______________u_Actions )
endfunction
发表于 2010-6-15 19:20:26 | 显示全部楼层
观望
回复

使用道具 举报

发表于 2010-6-15 21:26:00 | 显示全部楼层
T中的if是以一个函数的返回值来执行的,function Trig____________________001______________u_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A09S' ) ) then
        return false
    endif
    return true
endfunction
这个就是一个例子,你在调用它的上一级函数中,将调用函数名修改成这个返回Boolean的函数中的if比较内容即可。
记住,局域变量只在当前声明的函数有效,t转j后要合并触发才行。
单位组的函数也这样
回复

使用道具 举报

 楼主| 发表于 2010-6-16 15:47:08 | 显示全部楼层
t转j后要合并触发才行
请问楼上,如何合并?.......需要懂得技术并手动吧...
回复

使用道具 举报

发表于 2010-6-16 22:36:07 | 显示全部楼层
合并函数,不是触发,就是把全部的动作函数合并一起,或者用存储系统传递
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-23 17:39 , Processed in 0.046251 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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