offline
Опыт:
6,290
Активность:
|
Функции с вложенными циклами
В триггере выполняется длиннейшая последовательность действий(из-за вложенных функций). Известно, что после некоторого количества действий в одном триггере его выполнение обрывается на середине. Это лечится вставлением в него TriggerSleepAction. Есть какой-то другой способ, чтоб без вэйтов? С таймерами не выйдет, т.к. функции, возвращающие значения.
В одном триггере например есть
Код:
local hashtable h
local string Code
set h=Nums2LI()
set Code=LI2S(h)
...
и собственно функции
Код:
function I2LI takes integer a returns hashtable
local hashtable h=InitHashtable()
local integer l=0
loop
exitwhen a==0
set l=l+1
call SaveInteger(h,0,l,ost(a,10))
set a=a/10
endloop
call SaveInteger(h,0,0,l)
return h
endfunction
function LI2I takes hashtable h,integer a,integer b returns integer //áåðåò ñî çíàêà a äî çíàêà b ÷èñëî(b<a)
local integer c=0
local integer d=1
loop
exitwhen a==b
set c=c+d*LoadInteger(h,0,a)
set a=a+1
set d=d*10
endloop
return c
endfunction
function Sum takes hashtable h1,hashtable h2 returns hashtable
local hashtable h=I2LI(0)
local integer l=max(GetLILength(h1),GetLILength(h2))+1
local integer o
local integer a=0
loop
set a=a+1
exitwhen a==l
set o=LoadInteger(h1,0,a)+LoadInteger(h2,0,a)+LoadInteger(h,0,a)
call SaveInteger(h,0,a,ost(o,10))
call SaveInteger(h,0,a+1,o/10)
endloop
if LoadInteger(h,0,a)>0 then
call SetLILength(h,l)
else
call SetLILength(h,l-1)
endif
return h
endfunction
function Add takes hashtable h1,hashtable h2 returns hashtable
local hashtable h=I2LI(0)
local integer o
local integer o2
local integer a=0
local integer b
local integer l2=GetLILength(h2)
local integer l1=GetLILength(h1)
local integer c
loop
set a=a+1
exitwhen a>l2
set b=0
loop
set b=b+1
exitwhen b>l1
set o=LoadInteger(h2,0,a)*LoadInteger(h1,0,b)+LoadInteger(h,0,a+b-1)
set o2=o/10
set o=o-o2*10
call SaveInteger(h,0,a+b-1,o)
set c=a+b
loop
set o2=o2+LoadInteger(h,0,c)
set o=o2/10
set o2=ost(o2,10)
call SaveInteger(h,0,c,o2)
set o2=o
set c=c+1
exitwhen o2==0
endloop
endloop
endloop
set o2=l2+l1+2
loop
set o=LoadInteger(h,0,o2)
if o>0 or o2==0 then
call SetLILength(h,o2)
endif
exitwhen o>0 or o2==0
set o2=o2-1
endloop
return h
endfunction
function Div takes hashtable h1,integer i returns hashtable
local hashtable h=I2LI(0)
local integer a=i
local integer q
local integer l=GetLILength(h1)
local integer il=l+1
local integer o=0
local integer o2
local integer z=0
loop
exitwhen a==0
set a=a/10
set z=z+1
endloop
loop
set il=il-1
exitwhen il==0
set o2=o*10+LoadInteger(h1,0,il)
set z=o2/i
set o=ost(o2,i)
call SaveInteger(h,0,il,z)
endloop
loop
set o=LoadInteger(h,0,l)
if o>0 or l==0 then
call SetLILength(h,l)
endif
exitwhen o>0 or l==0
set l=l-1
endloop
return h
endfunction
function LI2S takes hashtable h1 returns string
local string s=""
local hashtable h=Sum(h1,I2LI(0))
local hashtable h2
local integer i
local string s2
local integer c=0
loop
set i=GetLILength(h)
exitwhen i==0
set s2=IntToChar(Mod(h,35))
set s=s2+s
set h2=Div(h,35)
call FlushParentHashtable(h)
set h=h2
set c=c+1
if ost(c,10)==0 then
//call TriggerSleepAction(0.)
call PolledWait(0.1)
endif
endloop
call FlushParentHashtable(h)
//call FlushParentHashtable(h2)
set h=null
set h2=null
return s
endfunction
function Nums2LI takes nothing returns hashtable
local integer b
local hashtable h=I2LI(0)
local hashtable h2
local hashtable h3
local integer c=0
local integer w=udg_SaveVersion
set b=LoadInteger(udg_CSB,w,0)
loop
set h2=I2LI(udg_SaveInt[b])
set h3=Sum(h,h2)
call FlushParentHashtable(h2)
call FlushParentHashtable(h)
set h=h3
set b=b-1
exitwhen b==0
set h2=I2LI(LoadInteger(udg_CSB,w,b))
set h3=Add(h,h2)
call FlushParentHashtable(h2)
call FlushParentHashtable(h)
set h=h3
set c=c+1
if ost(c,10)==0 then
//call TriggerSleepAction(0.)
call PolledWait(0.1)
endif
endloop
set h2=null
set h3=null
return h
endfunction
|