找回密码
 点一下
查看: 1273|回复: 13

JASS不能用循环的嵌套么??

[复制链接]
发表于 2010-5-8 10:42:34 | 显示全部楼层 |阅读模式
function Trig____________________001_Actions takes nothing returns nothing
local integer i
set i=0
set bj_forLoopAIndex=0
set bj_forLoopAIndexEnd=10
loop
exitwhen i>1
loop
exitwhen bj_forLoopAIndex>bj_forLoopAIndexEnd
call CreatUnitAtLoc(Player(0),udg_a[udg_i], GetRandomLocInRect(gg_rct______________000), 0)
       call TriggerSleepAction( 2 )
        set bj_forLoopAIndex = bj_forLoopAIndex +1   
    endloop
     set i=i+1
    endloop
endfunction


//===========================================================================
function InitTrig____________________001 takes nothing returns nothing
    set gg_trg____________________001 = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg____________________001, 5 )
    call TriggerAddAction( gg_trg____________________001, function Trig____________________001_Actions )
endfunction

为什么变量i的值没改变呢??明明有i=i+1啊 我是想刷10个udg_a[0], 再刷10个udg_a[1], 结果一直在刷udg_a[0],悲剧啊
发表于 2010-5-8 10:47:29 | 显示全部楼层
call TriggerSleepAction( 2 )
循环里不能用等待
   容易BUG的
  非要每隔2秒创建单位
  还是用计时器吧
回复

使用道具 举报

 楼主| 发表于 2010-5-8 10:49:22 | 显示全部楼层
可以等待的,刷一个怪等2秒再刷一个,我试过的,问题是变量I不变啊,刷了10个怪怎么还不变呢
回复

使用道具 举报

发表于 2010-5-8 11:00:30 | 显示全部楼层
问题是[udg_i]
  创建单位那条J

还是建议你用计时器  
loop的循环
选取单位组做动作
选取物做动作 都类似的
用等待的话肯定要出问题的
回复

使用道具 举报

发表于 2010-5-8 11:40:14 | 显示全部楼层
循环嵌套肯定可以的= =
你的循环整数A没还原成0,第二次直接从10开始,直接跳出循环了
回复

使用道具 举报

 楼主| 发表于 2010-5-8 12:09:41 | 显示全部楼层
我崩溃了,它怎么一直在刷啊,不是刷10个就结束么??function Trig____________________003_Actions takes nothing returns nothing
    local integer i
    local integer n
    set i=0
    set n=1
    loop
        exitwhen n> 10
call  CreateUnitAtLoc( Player(0), udg_a, GetRandomLocInRect(gg_rct______________000), 0 )
call TriggerSleepAction(2)
        set n = n+ 1
    endloop
set i=i+1
endfunction

//===========================================================================
function InitTrig____________________003 takes nothing returns nothing
    set gg_trg____________________003 = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg____________________003, 5 )
    call TriggerAddAction( gg_trg____________________003, function Trig____________________003_Actions )
endfunction
回复

使用道具 举报

发表于 2010-5-8 12:10:31 | 显示全部楼层
好吧,我地下室有更新了下,指出问题了,你再看下吧
回复

使用道具 举报

 楼主| 发表于 2010-5-8 12:29:58 | 显示全部楼层
是这样改么??直接崩溃了 function Trig____________________001_Actions takes nothing returns nothing
local integer i
set i=0
set bj_forLoopAIndex=0
set bj_forLoopAIndexEnd=10
loop
exitwhen i>1
loop
exitwhen bj_forLoopAIndex>bj_forLoopAIndexEnd
call CreatUnitAtLoc(Player(0),udg_a, GetRandomLocInRect(gg_rct______________000), 0)
       call TriggerSleepAction( 2 )
        set bj_forLoopAIndex = bj_forLoopAIndex +1     
    endloop
     set i=i+1
    set bj_forLoopAIndex=0
    endloop
endfunction

//===========================================================================
function InitTrig____________________001 takes nothing returns nothing
    set gg_trg____________________001 = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg____________________001, 5 )
    call TriggerAddAction( gg_trg____________________001, function Trig____________________001_Actions )
endfunction
回复

使用道具 举报

发表于 2010-5-8 12:33:06 | 显示全部楼层
----------------
回复

使用道具 举报

 楼主| 发表于 2010-5-8 12:51:31 | 显示全部楼层
这样的话还是嵌套么??
回复

使用道具 举报

发表于 2010-5-8 12:58:50 | 显示全部楼层
顶楼的语句结构没什么问题但是,你的变量你自己弄清楚了么?



function Trig____________________001_Actions takes nothing returns nothing
local integer i &#160;<-----这里是局部变量 &#160;
set i=0
set bj_forLoopAIndex=0
set bj_forLoopAIndexEnd=10
loop
exitwhen i>1
loop
exitwhen bj_forLoopAIndex>bj_forLoopAIndexEnd
call CreatUnitAtLoc(Player(0),udg_a[udg_i], GetRandomLocInRect(gg_rct______________000), 0) &#160;<---这里又是全局变量,刷出来的东西怎么可能变!!!&#160;
       call TriggerSleepAction( 2 )
        set bj_forLoopAIndex = bj_forLoopAIndex +1   
    endloop
     set i=i+1
    endloop
endfunction

//===========================================================================
function InitTrig____________________001 takes nothing returns nothing
    set gg_trg____________________001 = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg____________________001, 5 )
    call TriggerAddAction( gg_trg____________________001, function Trig____________________001_Actions )
endfunction
回复

使用道具 举报

发表于 2010-5-8 13:03:29 | 显示全部楼层
function Trig____________________001_Actions takes nothing returns nothing
local integer i = 0
local integer j = 0
loop
exitwhen i>10
     loop
            exitwhen j>10
                  call CreatUnitAtLoc(Player(0),udg_a, GetRandomLocInRect(gg_rct______________000), 0)
                   call TriggerSleepAction( 2 )
                  set j = j + 1
     endloop
     set j = 0
     set i=i+1
endloop
endfunction

好吧,我错了.....
回复

使用道具 举报

发表于 2010-5-8 13:07:17 | 显示全部楼层
[jass]
function Trig____________________001_Actions takes nothing returns nothing&#160;
local integer i = 0
local integer j = 0
loop
exitwhen i>10
&#160;&#160;&#160;&#160; loop
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;exitwhen j>10
&#160; &#160; &#160; &#160; &#160; &#160; call CreatUnitAtLoc(Player(0),udg_a, GetRandomLocInRect(gg_rct______________000), 0)&#160;
&#160; &#160; &#160; &#160; &#160; &#160; call TriggerSleepAction( 2 )
&#160; &#160; &#160; &#160; &#160; &#160; set j = j + 1
&#160;&#160;&#160;&#160; endloop
&#160;&#160;&#160;&#160; set j = 0
&#160;&#160;&#160;&#160; set i=i+1
endloop
endfunction
[/jass]
回复

使用道具 举报

 楼主| 发表于 2010-5-8 13:40:54 | 显示全部楼层
终于做好了,谢谢你们
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-25 19:43 , Processed in 0.063693 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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