T32, how to use the ".startperiodic" method ? :S

Komaqtion

You can change this now in User CP.
Reaction score
469
Hi!

I'm trying to make a kind of fade/scale system/snippet, and I thought I'd use T32 for easy and efficient scaling/fading over time...

Though, I've never use T32 before, so this is what I have atm:
JASS:
library ScaleandFade uses T32

    globals
        private integer TempStruct
    endglobals

    struct SaF
    
        real ex
        real ey
        real ez
        real xincrement
        real yincrement
        real zincrement
        unit u
        boolean bx = true
        boolean by = true
        boolean bz = true
        
        private static method Filters takes nothing returns boolean
            return IsUnit(SaF(TempStruct).u, DUMMY) != true
        endmethod
    
        private method periodic takes nothing returns boolean
            local boolean b = false
            local real x
            local real y
            local real z
            
            call BJDebugMsg(" Tick! ")
            
            if .u != null and (.xincrement != 0 or .yincrement != 0 or .zincrement != 0) and thistype.Filters() then
            
                if .bx == true then
                    set x = x + .xincrement
                endif
                
                if .by == true then
                    set y = y + .yincrement
                endif
                
                if .bz == true then
                    set z = z + .zincrement
                endif
                
                call SetUnitScale(.u, x, y, z)
                
                if x == .ex then
                    set .bx = false
                endif
                
                if y == .ey then
                    set .by = false
                endif
                
                if z == .ez then
                    set .bz = false
                endif
                
            else
            
                if .u == null then
                    debug call BJDebugMsg(" The scaling unit is not valid! ")
                    
                    set b = true
                    
                elseif .xincrement == 0 then
                    debug call BJDebugMsg(" You'll need to specify different start/end x-values to scale a unit! ")
                    
                    set b = true
                    
                elseif .yincrement == 0 then
                    debug call BJDebugMsg(" You'll need to specify different start/end y-values to scale a unit! ")
                    
                    set b = true
                    
                elseif .zincrement == 0 then
                    debug call BJDebugMsg(" You'll need to specify different start/end z-values to scale a unit! ")
                    
                    set b = true
                endif
                    
            endif
            
            return b
        endmethod
        
        implement T32
        
        static method create takes real startscale_x, real startscale_y, real startscale_z,real endscale_x, real endscale_y, real endscale_z,  unit scaled returns thistype
            local thistype this = thistype.allocate()
            
            set .ex = endscale_x
            set .ey = endscale_y
            set .ez = endscale_z
            set .xincrement = (endscale_x - startscale_x) * T32_PERIOD
            set .yincrement = (endscale_y - startscale_y) * T32_PERIOD
            set .zincrement = (endscale_z - startscale_z) * T32_PERIOD
            set .u = scaled
            set TempStruct = this
            
            call BJDebugMsg(R2S(.xincrement))
            call BJDebugMsg(R2S(.yincrement))
            call BJDebugMsg(R2S(.zincrement))
            call BJDebugMsg(GetUnitName(.u))
            
            return this
        endmethod
        
    endstruct
    
    /*private function Descaling takes nothing returns boolean
        local boolean b
        
        if d.scale > 1. then
            set d.scale = d.scale - 0.05
            call SetUnitScale(d.caster, d.scale, d.scale, d.scale)
            set b = false
        else
            set b = true
        endif
        
        return b
    endfunction

    private function Scaling takes nothing returns boolean
        local boolean b
        
        if d.scale < SCALE then
            set d.scale = d.scale + 0.05
            call SetUnitScale(d.caster, d.scale, d.scale, d.scale)        
            set b = false
        else
            set b = true
        endif
        
        return b
    endfunction*/

endlibrary


And this is how I test it:
Trigger:
  • Test Scale
    • Events
      • Player - Player 1 (Red) types a chat message containing scale as An exact match
    • Conditions
    • Actions
      • Custom script: local SaF s
      • Set TempGroup = (Units owned by (Triggering player))
      • Custom script: set s = SaF.create(1., 1., 1., 1.5, 1.5, 1.5, FirstOfGroup(udg_TempGroup))
      • Custom script: call DestroyGroup(udg_TempGroup)


So, now I wonder where to put the .startperiodic() line :S
I tried to put it behind all stuff in the "test-trigger", but that didn't work :(
 

Jesus4Lyf

Good Idea™
Reaction score
397
Stick it in your .create method - before "return this" add "call this.startPeriodic()".

But your periodic method has thread terminations!
JASS:
            local real x
            local real y
            local real z
            
            call BJDebugMsg(" Tick! ")
            
            if .u != null and (.xincrement != 0 or .yincrement != 0 or .zincrement != 0) and thistype.Filters() then
            
                if .bx == true then
                    set x = x + .xincrement // Thread terminate for referencing uninitialized local variable "x".
                endif

set x = x + .xincrement - what is "x" meant to hold by then?

Questions like this should be asked in the T32 thread, imho. ;)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Stick it in your .create method - before "return this" add "call this.startPeriodic()".

Ok, thanks ;)

But your periodic method has thread terminations!
JASS:
local real x
            local real y
            local real z
            
            call BJDebugMsg(" Tick! ")
            
            if .u != null and (.xincrement != 0 or .yincrement != 0 or .zincrement != 0) and thistype.Filters() then
            
                if .bx == true then
                    set x = x + .xincrement // Thread terminate for referencing uninitialized local variable "x".
                endif


set x = x + .xincrement - what is "x" meant to hold by then?

Huh ?!
Why would that terminate the thread ? :S
 

Azlier

Old World Ghost
Reaction score
461
x doesn't have a value of 0. It has no value. What happens when you try to add to what doesn't exist? (In the computer world, of course.)
 

Azlier

Old World Ghost
Reaction score
461
[lJASS]local real x = 0 //Fix'd.[/lJASS]
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Hehe XD Thanks ;)

Ok, well at least the "Tick!" messages appear now (Thanks again ! ;)).
Though, now the unit just simply dissapears when I test it...

(I use this to test it:)
Trigger:
  • Test Scale
    • Events
      • Player - Player 1 (Red) types a chat message containing scale as An exact match
    • Conditions
    • Actions
      • Custom script: local SaF s
      • Set TempGroup = (Units owned by (Triggering player))
      • Custom script: set s = SaF.create(1., 1., 1., 1.5, 1.5, 1.5, 2.5, FirstOfGroup(udg_TempGroup))
      • Custom script: call DestroyGroup(udg_TempGroup)


And here's the code again.
JASS:
library ScaleandFade uses T32

    globals
        private integer TempStruct
    endglobals

    struct SaF
    
        real ex
        real ey
        real ez
        real xincrement
        real yincrement
        real zincrement
        unit u
        boolean bx = true
        boolean by = true
        boolean bz = true
        
        private static method Filters takes nothing returns boolean
            return IsUnit(SaF(TempStruct).u, DUMMY) != true
        endmethod
    
        private method periodic takes nothing returns boolean
            local boolean b = false
            local real x = 0
            local real y = 0
            local real z = 0
            
            call BJDebugMsg(" Tick! ")
            
            if .u != null and (.xincrement != 0 or .yincrement != 0 or .zincrement != 0) and thistype.Filters() then
            
                if .bx == true then
                    set x = x + .xincrement
                endif
                
                if .by == true then
                    set y = y + .yincrement
                endif
                
                if .bz == true then
                    set z = z + .zincrement
                endif
                
                call SetUnitScale(.u, x, y, z)
                
                if x == .ex then
                    set .bx = false
                endif
                
                if y == .ey then
                    set .by = false
                endif
                
                if z == .ez then
                    set .bz = false
                endif
                
            else
            
                if .u == null then
                    debug call BJDebugMsg(" The scaling unit is not valid! ")
                    
                    set b = true
                    
                elseif .xincrement == 0 then
                    debug call BJDebugMsg(" You'll need to specify different start/end x-values to scale a unit! ")
                    
                    set b = true
                    
                elseif .yincrement == 0 then
                    debug call BJDebugMsg(" You'll need to specify different start/end y-values to scale a unit! ")
                    
                    set b = true
                    
                elseif .zincrement == 0 then
                    debug call BJDebugMsg(" You'll need to specify different start/end z-values to scale a unit! ")
                    
                    set b = true
                endif
                    
            endif
            
            return b
        endmethod
        
        implement T32
        
        static method create takes real startscale_x, real startscale_y, real startscale_z,real endscale_x, real endscale_y, real endscale_z, real time, unit scaled returns thistype
            local thistype this = thistype.allocate()
            
            set this.ex = endscale_x
            set this.ey = endscale_y
            set this.ez = endscale_z
            set this.xincrement = (endscale_x - startscale_x) / ( 1 / T32_PERIOD )
            set this.yincrement = (endscale_y - startscale_y) / ( 1 / T32_PERIOD )
            set this.zincrement = (endscale_z - startscale_z) / ( 1 / T32_PERIOD )
            set this.u = scaled
            set TempStruct = this
            
            call BJDebugMsg(R2S(this.xincrement))
            call BJDebugMsg(R2S(this.yincrement))
            call BJDebugMsg(R2S(this.zincrement))
            call BJDebugMsg(GetUnitName(this.u))
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    /*private function Descaling takes nothing returns boolean
        local boolean b
        
        if d.scale > 1. then
            set d.scale = d.scale - 0.05
            call SetUnitScale(d.caster, d.scale, d.scale, d.scale)
            set b = false
        else
            set b = true
        endif
        
        return b
    endfunction

    private function Scaling takes nothing returns boolean
        local boolean b
        
        if d.scale < SCALE then
            set d.scale = d.scale + 0.05
            call SetUnitScale(d.caster, d.scale, d.scale, d.scale)        
            set b = false
        else
            set b = true
        endif
        
        return b
    endfunction*/

endlibrary


Is there some maths faults I've made, or what ? :(
 

Azlier

Old World Ghost
Reaction score
461
I think that [lJASS]SetUnitScale[/lJASS] takes percentages.

IE: 0.5 = 50% size.

So... adding 1.5 will make it'll grow so fast it'll disappear.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Don't think so, as there is a BJ which does that, and it's called
[ljass]SetUnitScalePercentage[/ljass] ;)

But, maybe the [ljass]SetUnitScale]/ljass] ranges from 0 - 100. or something, instead of 0 - 1. as I thought. :S
 

Azlier

Old World Ghost
Reaction score
461
It seems that I was correct. It ranges from 0-1. Adding 1.5 is a huge size addition. Try... 0.015.

Using the BJ, 100 is default size. The BJ calls the native with the arguments multiplied by 0.01. So, 100 becomes 1.

BTW: The y and z in your snippet do nothing. Only x actually works in SetUnitScale.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, well I just tried with using 100 and 150 instead of 1 and 1.5 and that made the unit instantly bigger, but then while there were still "Tick!" messages showing, nothing happened :(

So, how should I do this then ? :S
 

Azlier

Old World Ghost
Reaction score
461
Instead of 1 and 1.5 use 0.01 and 0.015.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
That also just made my hero disappear :(

Any other ideas ? :S

This is the code atm (Thanks for saying only "x" is needed, that really shortened the code !! ;)):

JASS:
library ScaleandFade uses T32

    globals
        private integer TempStruct
    endglobals

    struct SaF
    
        real ex
        real xincrement
        unit u
        boolean bx = true
        
        private static method Filters takes nothing returns boolean
            return IsUnit(SaF(TempStruct).u, DUMMY) != true
        endmethod
    
        private method periodic takes nothing returns boolean
            local boolean b = false
            local real x = 0
            
            call BJDebugMsg(" Tick! ")
            
            if .u != null and .xincrement != 0 and thistype.Filters() then
            
                if .bx == true then
                    set x = x + .xincrement
                endif
                
                call SetUnitScale(.u, x, 1., 1.)
                
                if x == .ex then
                    set .bx = false
                endif
                
            else
            
                if .u == null then
                    debug call BJDebugMsg(" The scaling unit is not valid! ")
                    
                    set b = true
                    
                elseif .xincrement == 0 then
                    debug call BJDebugMsg(" You'll need to specify different start/end x-values to scale a unit! ")
                    
                    set b = true
                endif
                    
            endif
            
            return b
        endmethod
        
        implement T32
        
        static method create takes real startscale_x, real endscale_x, real time, unit scaled returns thistype
            local thistype this = thistype.allocate()
            
            set this.ex = endscale_x
            set this.xincrement = (endscale_x - startscale_x) / ( time / T32_PERIOD )
            set this.u = scaled
            set TempStruct = this
            
            call BJDebugMsg(R2S(this.xincrement))
            call BJDebugMsg(GetUnitName(this.u))
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    /*private function Descaling takes nothing returns boolean
        local boolean b
        
        if d.scale > 1. then
            set d.scale = d.scale - 0.05
            call SetUnitScale(d.caster, d.scale, d.scale, d.scale)
            set b = false
        else
            set b = true
        endif
        
        return b
    endfunction

    private function Scaling takes nothing returns boolean
        local boolean b
        
        if d.scale < SCALE then
            set d.scale = d.scale + 0.05
            call SetUnitScale(d.caster, d.scale, d.scale, d.scale)        
            set b = false
        else
            set b = true
        endif
        
        return b
    endfunction*/

endlibrary


I really wanna know if this is correct :
[ljass] set this.xincrement = (endscale_x - startscale_x) / ( time / T32_PERIOD )[/ljass]

Ok, I just remembered that I have two debug msg'es in the "create" method too, I just didn't see it for all the "Tick!" stuff...
And it shows 0.000, meaning that either it get nulled, or it's too small to use :(
( I'd say it get too small, since ( 1.5 - 1. ) / ( 2.5 / 0.03125 ) = 0.00625 )
 

Jesus4Lyf

Good Idea™
Reaction score
397
You need to study JASS more, your code makes little sense.
[LJASS].xincrement != 0[/LJASS]
Why the hell would the struct exist if this is 0? XD

"Filters" should be a non-static method (you're passing with a global? o_O).

Try rewriting this from scratch and then post it again. ;)
(My suggestion.)

Edit: Example (uncompiled, untested):
JASS:
struct ScaleSlide
    private unit u
    private real scale
    private real endScale
    private real increment
    private method periodic takes nothing returns boolean
        set this.scale=this.scale+this.increment
        call SetUnitScale(this.u,this.scale,1,1)
        if this.scale>=this.endscale then
            call this.destroy()
            return true
        endif
        return false
    endmethod
    implement T32
    static method create takes unit u, real startScale, real endScale, real time returns thistype
        local thistype this=thistype.allocate()
        set this.u=u
        set this.scale=startScale
        set this.endScale=endScale
        set this.increment=(endScale-startScale)/time*T32_PERIOD
        call this.startPeriodic()
        return this
    endmethod
endstruct
 

Komaqtion

You can change this now in User CP.
Reaction score
469
You need to study JASS more, your code makes little sense.
.xincrement != 0
Why the hell would the struct exist if this is 0? XD

Well, it's just for safety reasons, so that it doesn't take up memory, if it doesn't do anything...

"Filters" should be a non-static method (you're passing with a global? o_O).

It needs to be a "static method", since otherwise it doesn't compile... :S

Edit: Example (uncompiled, untested):
But, isn't that almost exactly the same as what I have already ? :S

Ok, so did "some" rewriting, but still doesn't work :(

JASS:
library ScaleandFade uses T32

    globals
        private integer TempStruct
    endglobals

    struct SaF
    
        real endScale
        real increment
        real Scale
        unit u
        
        private static method Filters takes nothing returns boolean
            return IsUnit(SaF(TempStruct).u, DUMMY) != true
        endmethod
    
        private method periodic takes nothing returns boolean
            local boolean b = false
            
            set .Scale = .Scale + .increment
            
            //call BJDebugMsg(" Tick! ")
            
            if .u != null and .increment != 0 and thistype.Filters() then
                
                call SetUnitScale(.u, .Scale, 1., 1.)
                
                if .Scale == .endScale then
                    set b = true
                    call this.destroy()
                endif
                
            else
            
                if .u == null then
                    debug call BJDebugMsg(" The scaling unit is not valid! ")
                    
                    set b = true
                    
                elseif .increment == 0 then
                    debug call BJDebugMsg(" You'll need to specify different start/end x-values to scale a unit! ")
                    
                    set b = true
                endif
                    
            endif
            
            return b
        endmethod
        
        implement T32
        
        static method create takes real startScale, real endScale, real time, unit scaled returns thistype
            local thistype this = thistype.allocate()
            
            set this.endScale = endScale
            set this.increment = (endScale - startScale) / ( time / T32_PERIOD )
            set this.u = scaled
            set TempStruct = this
            
            call BJDebugMsg(R2S(this.increment))
            call BJDebugMsg(GetUnitName(this.u))
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct

endlibrary
 

saw792

Is known to say things. That is all.
Reaction score
280
>It needs to be a static method else it doesn't compile
[ljass]if .u != null and .increment != 0 and thistype.Filters() then[/ljass]
to
[ljass]if .u != null and .increment != 0 and .Filters() then[/ljass]

Changing the Filters() method to use this instead of tempstruct, of course.
 

Jesus4Lyf

Good Idea™
Reaction score
397
I gave you an example to study.
JASS:
struct ScaleSlide
    private unit u
    private real scale
    private real endScale
    private real increment
    private method periodic takes nothing returns boolean
        set this.scale=this.scale+this.increment
        call SetUnitScale(this.u,this.scale,1,1)
        if this.scale>=this.endscale then
            call this.destroy()
            return true
        endif
        return false
    endmethod
    implement T32
    static method create takes unit u, real startScale, real endScale, real time returns thistype
        local thistype this=thistype.allocate()
        set this.u=u
        set this.scale=startScale
        set this.endScale=endScale
        set this.increment=(endScale-startScale)/time*T32_PERIOD
        call this.startPeriodic()
        return this
    endmethod
endstruct
Anything different to this is wrong, including anything you do for "safety"? (Assuming it compiles.)

You have to understand, even comparing real values if they're small doesn't work, 0.0001==0. in WC3 off memory.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
It works now !!! :D:D:D

I used 0.001 as the startScale and 0.0015 as the endScale, and it was supposed to be 1. and 1.5 :D:D

EDIT2: Why isn't this debug msg displayed ? :S

Trigger:
  • Test Fade
    • Events
      • Player - Player 1 (Red) types a chat message containing fade as An exact match
    • Conditions
    • Actions
      • Custom script: local SmoothFade s
      • Set TempGroup = (Units owned by (Triggering player))
      • Custom script: set s = SmoothFade.create(FirstOfGroup(udg_TempGroup), 100 , 50, 2.5)
      • Custom script: call BJDebugMsg("Hi !!")
      • Custom script: call DestroyGroup(udg_TempGroup)


(I'm making the same thing as "SmoothScale" niow, but with fade instead... ;))

Here's the entire code again:
JASS:
library ScaleandFade uses T32

    struct SmoothScale
    
        private unit u
        private real scale
        private real endScale
        private real increment
        
        private method periodic takes nothing returns boolean
            set this.scale = this.scale + this.increment
            
            call SetUnitScale(this.u,this.scale,1.,1.)
            debug call BJDebugMsg( R2S(this.scale))
            
            if this.scale >= this.endScale then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit u, real startScale, real endScale, real time returns thistype
            local thistype this=thistype.allocate()
            
            set this.u = u
            set this.scale = startScale
            set this.endScale = endScale
            set this.increment = (endScale - startScale) / time * T32_PERIOD
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    struct SmoothFade
    
        private unit u
        private integer alpha
        private integer endAlpha
        private integer increment
        
        private method periodic takes nothing returns boolean
            set this.alpha = this.alpha + this.increment
            
            call SetUnitVertexColor(this.u, 255, 255, 255, this.alpha)
            call BJDebugMsg( I2S(this.alpha))
            call BJDebugMsg( "Hellu!" )
            
            if this.alpha >= this.endAlpha then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit u, integer startAlpha, integer endAlpha, real time returns thistype
            local thistype this=thistype.allocate()
            
            set this.u = u
            set this.alpha = startAlpha
            set this.endAlpha = endAlpha
            set this.increment = (endAlpha - startAlpha) / R2I( time * T32_PERIOD )
            
            call this.startPeriodic()
            call BJDebugMsg( I2S(this.alpha))
            call BJDebugMsg( I2S(this.increment))
            call BJDebugMsg( "Hellu!" )
            
            return this
        endmethod
        
    endstruct

endlibrary


And, if I move the message line 'above' the custom script "set s = ..." it works :S
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top