找回密码
 点一下
查看: 1808|回复: 12

用timerstart使某整数每0.02秒钟增加1的方法?

[复制链接]
发表于 2008-2-20 13:30:24 | 显示全部楼层 |阅读模式
[codes=jass]function skilltimer1 takes nothing returns nothing
      local timer skilltimer=CreateTimer()
      call TimerStart(skilltimer,0.02,false,null)
      set skilltimer=null
endfunction
//======================================================



local integer IntNum
set IntNum=0
    loop
        exitwhen IntNum > 150      
        call skilltimer1()
        set IntNum=IntNum+1
    endloop[/codes]

我知道这段jass为什么错了,但是不知道怎么改才能用``-.-
发表于 2008-2-20 13:39:33 | 显示全部楼层
额………………下面这段是什么??
timerstart后面的代码是null说明计时器到期后什么都不干………………
回复

使用道具 举报

 楼主| 发表于 2008-2-20 13:40:44 | 显示全部楼层
下面这段是为了别的技能准备的```
就是每0.02秒IntNum+1
3秒后exit
回复

使用道具 举报

发表于 2008-2-20 13:42:18 | 显示全部楼层
这个貌似不能这么写的,要用到全局变量,或者缓存
回复

使用道具 举报

 楼主| 发表于 2008-2-20 13:44:09 | 显示全部楼层
对-   -所以我想知道怎么改```

[codes=jass]function skilltimer1 takes nothing returns nothing
      local timer skilltimer=CreateTimer()
      call TimerStart(skilltimer, 0.02, true, function count)
      set skilltimer=null
endfunction
//===========================================

function count takes nothing returns nothing
    set  udg_IntergerNum=udg_IntegerNum+1
endfunction
//===========================================




loop
        exitwhen udg_IntegerNum > 150      
        call skilltimer1()
    endloop[/codes]

这样呢
回复

使用道具 举报

发表于 2008-2-20 14:36:13 | 显示全部楼层
下面的不要用loop,用if条件判断
[codes=jass]if udg_IntegerNum < 150 then
    call SkillTimer1()
else
    //如果需要的话
endif[/codes]
回复

使用道具 举报

发表于 2008-2-20 14:40:09 | 显示全部楼层
这个嘛。。。他每次循环创建150个计时器循环调用,然后每0.02秒那个变量的值+150.。。。

并且不会被释放,这个函数也只能执行一次。。
回复

使用道具 举报

 楼主| 发表于 2008-2-20 14:49:04 | 显示全部楼层
引用第5楼zhuzeitou于2008-02-20 14:36发表的  :
下面的不要用loop,用if条件判断
[codes=jass]if udg_IntegerNum < 150 then
    call SkillTimer1()
else
    //如果需要的话[/codes]
.......

照你说的改了```可是-  -为什么总说这句编译错误

[codes=jass]call TimerStart(skilltimer, 0.02, true, function count)[/codes]
回复

使用道具 举报

发表于 2008-2-20 14:52:13 | 显示全部楼层
额,仔细看了下,那个if里面根本不需要call skilltimer1()
还有,count这个函数的声明要在skilltimer1之前
回复

使用道具 举报

 楼主| 发表于 2008-2-20 14:58:39 | 显示全部楼层
于是又有个问题```

set skilltimer=null
是在循环计数150次后set,还是在每计数1次后都set

(TO 6楼```
我本来是想把计时器的循环改false的````)


[codes=jass]function count takes nothing returns nothing
    set  udg_IntergerNum=udg_IntegerNum+1
endfunction
//===========================================
function skilltimer1 takes nothing returns nothing
      local timer skilltimer=CreateTimer()
      call TimerStart(skilltimer, 0.02, true, function count)
      set skilltimer=null
endfunction
//===========================================




call skilltimer1()
if udg_IntCount< 150 then
   ...[/codes]
回复

使用道具 举报

发表于 2008-2-20 15:37:30 | 显示全部楼层
[codes=jass]function count takes nothing returns nothing
    set   udg_IntergerNum = udg_IntegerNum+1
    if udg_IntegerNum >= 150 then
        call PauseTimer(GetExpiredTimer())
        call DestroyTimer(GetExpiredTimer())
    endif
endfunction
//===========================================
function skilltimer1 takes nothing returns nothing
    local timer skilltimer = CreateTimer()
    call TimerStart(skilltimer, 0.02, true, function count)
    set skilltimer = null
endfunction
//===========================================[/codes]

这样呢??
还有,使用时udg_IntegerNum要归0
回复

使用道具 举报

 楼主| 发表于 2008-2-20 17:32:09 | 显示全部楼层
是不是call skilltimer1之后原来声明的局部变量就不能使用了```?
回复

使用道具 举报

发表于 2008-2-20 19:07:45 | 显示全部楼层
函数中的局部变量只在本次执行中有效
如果一个函数在同时被执行两次,其中的局部变量是互不干扰的
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-28 03:22 , Processed in 0.063720 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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