Помогите, пожалуйста, найти где тут ошибка. Вообще никак не могу понять, как перебирать данные в структуре используя переменные thistype.next, thistype.prev.
code
struct data
static timer period = CreateTimer( )
thistype prev
thistype next
unit u
integer a
method destroy takes nothing returns nothing
if ( this.next != 0 ) then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if ( thistype(0).next == 0 ) then
call PauseTimer( period )
endif
call thistype.deallocate( this )
endmethod
static method iterate takes nothing returns nothing
local thistype this = thistype( 0 )
loop
set this = this.next
exitwhen ( this == 0 )
set this.a = this.a + 1
call SetUnitVertexColor( this.u, 255, 255, 255, this.a )
if ( this.a >= 255 ) then
call this.destroy( )
endif
endloop
endmethod
static method createUnit takes nothing returns thistype
local thistype this = thistype.allocate( )
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
set this.u = CreateUnit( Player(0), 'hfoo', 0.0, 0.0, 0.0 )
set this.a = 0
call SetUnitVertexColor( this.u, 255, 255, 255, 0 )
if thistype(0).next == 0 then
call TimerStart( period, 0.03125, true, function thistype.iterate )
else
set thistype(0).next.prev = this
endif
return this
endmethod
endstruct
Принятый ответ
quq_CCCP, благодарю, но всё же хотелось бы именно с thistype.next, thistype.prev.
кажется, я сделаль:
struct data
static timer period = CreateTimer( )
thistype prev
thistype next
unit u
integer a
method destroy takes nothing returns nothing
set this.prev.next = this.next
set this.next.prev = this.prev
if ( thistype(0).next == 0 ) then
call PauseTimer( period )
endif
call thistype.deallocate( this )
endmethod
static method iterate takes nothing returns nothing
local thistype this = thistype( 0 ).next
loop
exitwhen ( this == 0 )
set this.a = this.a + 1
call SetUnitVortexColor( this.u, 255, 255, 255, this.a )
if ( this.a > 255 ) then
call this.destroy( )
endif
set this = this.next
endloop
endmethod
static method createUnit takes nothing returns thistype
local thistype this = thistype.allocate( )
set this.next = 0
set this.prev = thistype(0).prev
set this.next.prev = this
set this.prev.next = this
set this.u = CreateUnit(...)
set this.a = 0
call SetUnitVortexColor( this.u, 255, 255, 255, this.a )
if ( this.prev == 0 ) then
call TimerStart( period, 0.03125, true, function thistype.iterate )
endif
return this
endmethod
endstruct
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Отредактирован Clamp
И вот тут ссылка.
Но особо увлекаться этим не вижу смысла, ну только если у вас не 300+ объектов для перебора..