|
[codes=jass]
API:
function RunFunc takes string func,integer COUNT,real p returns timer
参数:
func---------------字符串形的函数名
COUNT--------------函数要执行的次数
p------------------执行间隔
作用:
每隔p秒,执行函数func一次,一共执行COUNT次。
注意:
第一次执行次在p秒后。
函数在另一个线程中执行,所以不要调用TriggerSleepAction
不要调用错误的函数名,不然后果难以想像
如果COUNT设为0,函数执行无限次,下面有函数可以终止之。
API:
function EndFunc takes timer t returns nothing
参数:
t-----------------由RunFunc返回产生的一个timer
作用:
终止周期调用函数。一般用于COUNT=0这种设置的无限循环函数。
也可以用于COUNT≠0
//-------------------------------RunFunc-------------------------
globals
gamecache udg_WR_Cache
endglobals
function H2I takes handle h returns integer
return h
return 0
endfunction
function WR_GameCache takes nothing returns gamecache
if udg_WR_Cache==null then
call FlushGameCache(InitGameCache("WriteRead.vx"))
set udg_WR_Cache=InitGameCache("WriteRead.vx")
endif
return udg_WR_Cache
endfunction
function FlushHandle takes handle key returns nothing
call FlushStoredMission(WR_GameCache(),I2S(H2I(key)))
endfunction
function WriteInt takes handle h, string label, integer x returns nothing
local string k=I2S(H2I(h))
if x==0 then
call FlushStoredInteger(WR_GameCache(),k,label)
else
call StoreInteger(WR_GameCache(),k,label,x)
endif
endfunction
function ReadInt takes handle h, string label returns integer
if (label=="") then
return 0
endif
return GetStoredInteger(WR_GameCache(), I2S(H2I(h)), label)
endfunction
function WriteString takes handle h, string label, string x returns nothing
local string k=I2S(H2I(h))
if x=="" then
call FlushStoredString(WR_GameCache(),k,label)
else
call StoreString(WR_GameCache(),k,label,x)
endif
endfunction
function ReadString takes handle h, string label returns string
if (label=="") then
return ""
endif
return GetStoredString(WR_GameCache(),I2S(H2I(h)),label)
endfunction
function RunFunc_Child takes nothing returns nothing
local timer t=GetExpiredTimer()
local integer count=ReadInt(t,"count")
local integer COUNT=ReadInt(t,"COUNT")
local string func =ReadString(t,"func")
call ExecuteFunc(func)
set count=count+1
call WriteInt(t,"count",count)
if(count==COUNT) then
call FlushHandle(t)
call PauseTimer(t)
call DestroyTimer(t)
return
endif
endfunction
function RunFunc takes string func,integer COUNT,real p returns timer
local timer t=CreateTimer()
if(COUNT<0) then
return null
endif
call WriteInt(t,"count",0)
call WriteInt(t,"COUNT",COUNT)
call WriteString(t,"func",func)
call TimerStart(t,p,true,function RunFunc_Child)
return t
endfunction
function EndFunc takes timer t returns nothing
call FlushHandle(t)
call PauseTimer(t)
call DestroyTimer(t)
endfunction
[/codes] |
|