找回密码
 点一下
查看: 1301|回复: 3

关于Timer召唤函数的问题

[复制链接]
发表于 2011-9-3 07:55:33 | 显示全部楼层 |阅读模式
RT,打个比方,我要每隔1秒在玩家1的字幕上显示数字1,那么是这样写
[jass]function A takes nothing returns nothing
    call DisplayTextToPlayer( Player(0) , 0 , 0 , I2S(1) )
endfunction

function B takes nothing returns nothing
    local timer t = CreateTimer()
        call TimerStart( t , 1.00 , true , function A )
    set t = null
endfunction[/jass]
如果函数A变成了
[jass]function A takes integer i returns nothing
    call DisplayTextToPlayer( Player(0) , 0 , 0 , I2S(i) )
endfunction[/jass]
那么函数B的TimerStart函数应该怎么写?还是函数A不能这样写?
发表于 2011-9-3 10:15:08 | 显示全部楼层
[jass]
    globals
        integer I=0
    endglobals  //如果编辑器不支持这个请在变量管理器里面创建~

    function A takes nothing returns nothing
        call DisplayTextToPlayer( Player(0) , 0 , 0 , I2S(I) )
    endfunction
     
    function B takes integer i returns nothing
        set I=i
        call TimerStart( CreateTimer() , 1.00 , true , function A )
    endfunction[/jass]
全局变量~


[jass]
    globals
        gamecache gc=InitGameCache("⑨")
    endglobals

    function H2I takes handle h returns integer
        return h
        return 0
    endfunction

    function A takes nothing returns nothing
        call DisplayTextToPlayer( Player(0) , 0 , 0 , I2S(GetStoredInteger(gc, I2S(H2I(GetExpiredTimer())), "value") ))
    endfunction
     
    function B takes integer i returns nothing
        local timer t=CreateTimer()
        call StoreInteger( gc, I2S(H2I(t)), "value", i )
        call TimerStart( t , 1.00 , true , function A )
        set t=null
    endfunction[/jass]
缓存~

[jass]    globals
        hashtable ht=InitHashtable()
    endglobals

    function A takes nothing returns nothing
        call DisplayTextToPlayer( Player(0) , 0 , 0 , I2S(LoadInteger(ht,GetHandleId(GetExpiredTimer()),0)) )
    endfunction
     
    function B takes integer i returns nothing
        local timer t=CreateTimer()
        call SaveInteger(ht, GetHandleId(t), 0, i);
        call TimerStart( t , 1.00 , true , function A )
        set t=null
    endfunction[/jass]
哈希表~

唔.....手写的米有检查过对错,仅供参考的说~
回复

使用道具 举报

 楼主| 发表于 2011-9-3 10:37:17 | 显示全部楼层
好吧,只好去学HT了,不过还是要感谢LZ
回复

使用道具 举报

发表于 2011-9-3 10:45:12 | 显示全部楼层
引用第2楼xxy769506457于2011-09-03 10:37发表的  :
好吧,只好去学HT了,不过还是要感谢LZ
感谢LZ……


夜星把LZ的B函数参数改掉了
如果LZ不想改的话就参照下面这个吧~
[jass]globals
    hashtable ht = InitHashtable()
endglobals

function A takes nothing returns nothing
    local integer i = LoadInteger( ht, GetHandleId( GetExpiredTimer() ), 1 )
    call DisplayTextToPlayer( Player(0), 0, 0, I2S(i) )
endfunction

function B takes nothing returns nothing
    local timer t = CreateTimer()
    local integer i = ? // 自己设置数值,如果是要用别的函数改这个数值则推荐用全局或者用夜星的方法
        call SaveInteger( ht, GetHandleId( t ), 1, i )
        call TimerStart( t, 1, true, function A )
    set t = null
endfunction[/jass]
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-10-5 20:20 , Processed in 0.029264 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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