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

Artificial

Without Intelligence
Reaction score
326
> [ljass]set this.increment = (endAlpha - startAlpha) / R2I( time * T32_PERIOD )[/ljass]
[ljass]R2I(2.5 * 0.03125)[/ljass] kinda like might possibly be 0, and dividing by 0 ain't quite nice. So just do the R2I elsewhere, either when setting the unit's vertex color ([ljass]call SetUnitVertexColor(..., R2I(this.alpha))[/ljass]) or like this:
[ljass]set this.increment = R2I((endAlpha - startAlpha) / time * T32_PERIOD)[/ljass]
 

Komaqtion

You can change this now in User CP.
Reaction score
469
So, you mean those variables should be reals then ? :S
And I convert it to integer in the [ljass]call SetUnitVertexColoring()[/ljass] line ? :eek:

EDIT: Ok, so now the debug msg'es is showing, though the unit is still disappearing...
And, also, the msg'es are showing numbers like -10000.00 and are still decreasing...
So I discovered, by adding another debug msg, that the increment of this becomes -640.00, and that's a bit too small...

And, now I mixed that line a bit, and I just simply replaced the "/" with "*" and now it's a movre reasonable size, -3.9.....
Though, now there are no debug msg'es showing, except the ones in the .create method...
The .periodic method doesn't seem to run :(

JASS:
    struct SmoothFade
    
        private real alpha
        private real increment
        private real endAlpha
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.alpha = this.alpha + this.increment
            
            if this.alpha > this.endAlpha then
                call this.destroy()
                
                return true
            endif
            
            call SetUnitVertexColor( this.u, 255, 255, 255, R2I( this.alpha ) )
            //call BJDebugMsg( R2S( this.alpha ) )
            call BJDebugMsg( R2S( this.increment ) )
            call BJDebugMsg( "Hellu!" )
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit u, real startAlpha, real 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 ) * ( time * T32_PERIOD )
            
            call this.startPeriodic()
            call BJDebugMsg( R2S(this.alpha))
            call BJDebugMsg( R2S(this.increment))
            
            return this
        endmethod
        
    endstruct
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok... I've extended this snippet/system quite a bit now, though I might remove some stuff XD

Well, anyways there are some "Why"s I want to get answers to:
  • Why is the unit I'm scaling becoming enormous when I use the "Scale Inc" trigger below ?
  • Why is the debug messages I put in there showing two times with the same value ?
  • When I use my "Fade Dec/Inc" triggers, I can't seem to more exact values than, 245,313 when I want 255 and 53,125 when I want 50. Why ?
  • And the same as 2 questions above, why am I getting two values from the debug messages, whan I'm supposed to get one ?
  • And how do I make a "callback feature" for my methods ? Like you type (As a "take") either a string, or code, and when the fade/scale is over that function runs ?

Here's the code for the snippet/system:

JASS:
library ScaleAndFade uses KT

    globals
        private constant real PERIOD = 0.03125
    endglobals

    struct SmoothScale
    
        private unit u
        private real scale
        private real endScale
        private real increment
        //private code userFunc
        
        private static method periodic takes nothing returns boolean
            local SmoothScale this = KT_GetData()
            
            set this.scale = this.scale + this.increment
            
            if ( this.scale < this.endScale and this.increment > 0 ) or ( this.scale > this.endScale and this.increment < 0 ) then
                call this.destroy()
                //call this.userFunc.execute()
                
                return true
            endif
            
            call SetUnitScale( this.u, this.scale, 1., 1. )
            
            debug call BJDebugMsg( R2S( this.scale ) )
                        
            return false
        endmethod
        
        static method create takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns thistype
            local thistype this = thistype.allocate()
            local real tick = Time * PERIOD
            
            set this.u = Scaler
            set this.scale = startScale
            set this.endScale = endScale
            //set this.userFunc = userFunc
            
            
            if Period <= 0 then
                set this.increment = ( endScale - startScale ) / tick
                
                call KT_Add( function thistype.periodic, this, PERIOD )
            else
                set tick = Time * Period
                set this.increment = ( endScale - startScale ) / tick
                
                call KT_Add( function thistype.periodic, this, Period )
            endif
            
            debug call BJDebugMsg( R2S( this.scale ) )
            
            return this
        endmethod
        
    endstruct
    
    function ScaleSimple takes unit Scaler, real startScale, real endScale, real Time returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, 0., null )
    endfunction
    
    function ScaleSimplePeriod takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, Period, null )
    endfunction
    
    function ScaleEx takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, 0., userFunc )
    endfunction
    
    function ScaleExPeriod takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, Period, userFunc )
    endfunction
    
    struct SmoothFade
    
        private real rincrement
        private real gincrement
        private real bincrement
        private real alpha
        private real increment
        private real endAlpha
        private unit u
        
        private static method periodic takes nothing returns boolean
            local SmoothFade this = KT_GetData()
            
            set this.alpha = this.alpha + this.increment
            
            if ( this.alpha > this.endAlpha and this.increment > 0 ) or ( this.alpha < this.endAlpha and this.increment < 0 ) then
                call this.destroy()
                
                return true
            endif
            
            if this.rincrement == 0 and this.gincrement == 0 and this.bincrement == 0 then
                call SetUnitVertexColor( this.u, 255, 255, 255, R2I( this.alpha ) )
            else
                call SetUnitVertexColor( this.u, R2I( this.rincrement ), R2I( this.gincrement ), R2I( this.bincrement ), R2I( this.alpha ) )
            endif
            
            debug call BJDebugMsg( R2S( this.alpha ) )
            
            return false
        endmethod
        
        static method create takes unit Fader, boolean StaticRGB, real startAlpha, real endAlpha, real Time, real Period, real Red, real Green, real Blue  returns thistype
            local thistype this = thistype.allocate()
            local real tick = Time * PERIOD
            
            set this.u = Fader
            set this.alpha = startAlpha
            set this.endAlpha = endAlpha
            
            if Period <= 0 then
                set this.increment = ( endAlpha - startAlpha ) * tick
                
                    if not( StaticRGB ) then
                        set this.rincrement = Red * tick
                        set this.gincrement = Green * tick
                        set this.bincrement = Blue * tick
                    endif
                
                call KT_Add( function thistype.periodic, this, PERIOD )
            else
                set tick = Time * Period
                set this.increment = ( endAlpha - startAlpha ) * tick
                set this.rincrement = Red * tick
                set this.gincrement = Green * tick
                set this.bincrement = Blue * tick
                
                call KT_Add( function thistype.periodic, this, Period )
            endif
            
            return this
        endmethod
        
    endstruct
    
    function FadeSimple takes unit Fader, real startAlpha, real endAlpha, real Time returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, 0., 0., 0., 0. )
    endfunction
    
    function FadeSimplePeriod takes unit Fader, real startAlpha, real endAlpha, real Time, real Period returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, Period, 0., 0., 0. )
    endfunction
    
    function FadeEx takes unit Fader, real startAlpha, real endAlpha, real Time, real Red, real Green, real Blue returns SmoothFade
        return SmoothFade.create( Fader, false, startAlpha, endAlpha, Time, 0., Red, Green, Blue )
    endfunction
    
    function FadeExStatic takes unit Fader, real startAlpha, real endAlpha, real Time, real Red, real Green, real Blue returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, 0., Red, Green, Blue )
    endfunction
    
    function FadeExPeriod takes unit Fader, real startAlpha, real endAlpha, real Time, real Period, real Red, real Green, real Blue returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, Period, Red, Green, Blue )
    endfunction
    
    function FadeExPeriodStatic takes unit Fader, real startAlpha, real endAlpha, real Time, real Period, real Red, real Green, real Blue returns SmoothFade
        return SmoothFade.create( Fader, false, startAlpha, endAlpha, Time, Period, Red, Green, Blue )
    endfunction

endlibrary


And here are my test triggers:

Trigger:
  • Test Scale Dec
    • Events
      • Player - Player 1 (Red) types a chat message containing scale de as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothScale.create( GetEnumUnit(), 1., .5, 2.5, 0., null )
      • Custom script: call DestroyGroup(udg_TempGroup)


Trigger:
  • Test Scale Inc
    • Events
      • Player - Player 1 (Red) types a chat message containing scale in as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothScale.create( GetEnumUnit(), 1., 1.5, 2.5, 0., null )
      • Custom script: call DestroyGroup(udg_TempGroup)


Trigger:
  • Test Fade Dec
    • Events
      • Player - Player 1 (Red) types a chat message containing fade de as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothFade.create( GetEnumUnit(), true, 100. , 50., 2.5, 0., 0., 0, 0 )
      • Custom script: call DestroyGroup(udg_TempGroup)


Trigger:
  • Test Fade Inc
    • Events
      • Player - Player 1 (Red) types a chat message containing fade in as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothFade.create( GetEnumUnit(), true, 100. , 255., 2.5, 0., 0., 0, 0 )
      • Custom script: call DestroyGroup(udg_TempGroup)


Sorry for all the code, but I want you to have all the information you'll need ;)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, so I've fixed nearly all of those problems I had in my last post, these are the current ones:

  • I still don't know how to add a callback... I've tried with those commented line, but then the error say that codes can't be arrays :(
  • I got a suggetion from Vikuuna (At wc3c.net in this case) that I should somehow attach these scale/fade values to the unit, using (One of the many) Unit Indexing systems... How would I go about doing this, and which one should I use ?

And, that's about it ;)

Just one more question: Does this code contain too many "takes" and stuff ?
Maybe I can somehow decrease that value ? :S
And also, do you think that all those functions are useful, or are they too many or what ? :S

JASS:
library ScaleAndFade requires KT

    globals
        private constant real PERIOD = 0.03125
    endglobals

    struct SmoothScale
    
        private unit u
        private real scale
        private real endScale
        private real increment
        //private code userFunc
        
        private static method periodic takes nothing returns boolean
            local SmoothScale this = KT_GetData()
            
            set this.scale = this.scale + this.increment
            
            if ( this.scale > this.endScale and this.increment > 0 ) or ( this.scale < this.endScale and this.increment < 0 ) then
                call this.destroy()
                //call this.userFunc.execute()
                
                return true
            endif
            
            call SetUnitScale( this.u, this.scale, 1., 1. )
            
            debug call BJDebugMsg( R2S( this.scale ) )
                        
            return false
        endmethod
        
        static method create takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns thistype
            local thistype this = thistype.allocate()
            local real period
            
            if Period > 0 then
                set period = Period
            else
                set period = PERIOD
            endif
            
            set this.u = Scaler
            set this.scale = startScale
            set this.endScale = endScale
            //set this.userFunc = userFunc
            set this.increment = ( ( ( endScale - startScale ) * period ) / Time )
                
            call KT_Add( function thistype.periodic, this, period )
            
            return this
        endmethod
        
    endstruct
    
    function ScaleSimple takes unit Scaler, real startScale, real endScale, real Time returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, 0., null )
    endfunction
    
    function ScaleSimplePeriod takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, Period, null )
    endfunction
    
    function ScaleEx takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, 0., userFunc )
    endfunction
    
    function ScaleExPeriod takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, Period, userFunc )
    endfunction
    
    struct SmoothFade
    
        private real rincrement
        private real gincrement
        private real bincrement
        private real alpha
        private real increment
        private real endAlpha
        private unit u
        
        private static method periodic takes nothing returns boolean
            local SmoothFade this = KT_GetData()
            
            set this.alpha = this.alpha + this.increment
            
            if ( this.alpha > this.endAlpha and this.increment > 0 ) or ( this.alpha < this.endAlpha and this.increment < 0 ) then
                call this.destroy()
                
                return true
            endif
            
            if this.rincrement == 0 and this.gincrement == 0 and this.bincrement == 0 then
                call SetUnitVertexColor( this.u, 255, 255, 255, R2I( this.alpha ) )
            else
                call SetUnitVertexColor( this.u, R2I( this.rincrement ), R2I( this.gincrement ), R2I( this.bincrement ), R2I( this.alpha ) )
            endif
            
            debug call BJDebugMsg( R2S( this.alpha ) )
            
            return false
        endmethod
        
        static method create takes unit Fader, boolean StaticRGB, real startAlpha, real endAlpha, real Time, real Period, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns thistype
            local thistype this = thistype.allocate()
            local real period
            
            if Period > 0 then
                set period = Period
            else
                set period = PERIOD
            endif
            
            set this.u = Fader
            set this.alpha = startAlpha
            set this.endAlpha = endAlpha
            set this.increment = ( ( ( endAlpha - startAlpha ) * period ) / Time )
                
            if StaticRGB != true then
                set this.rincrement = ( ( ( endRed - startRed ) * period ) / Time )
                set this.gincrement = ( ( ( endGreen - startGreen ) * period ) / Time )
                set this.bincrement = ( ( ( endBlue - startBlue ) * period ) / Time )
            endif
                
            call KT_Add( function thistype.periodic, this, period )
            
            return this
        endmethod
        
    endstruct
    
    function FadeSimple takes unit Fader, real startAlpha, real endAlpha, real Time returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, 0., 255., 255., 255., 255., 255., 255. )
    endfunction
    
    function FadeSimplePeriod takes unit Fader, real startAlpha, real endAlpha, real Time, real Period returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, Period, 255., 255., 255., 255., 255., 255. )
    endfunction
    
    function FadeEx takes unit Fader, real startAlpha, real endAlpha, real Time, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns SmoothFade
        return SmoothFade.create( Fader, false, startAlpha, endAlpha, Time, 0., startRed, startGreen, startBlue, endRed, endGreen, endBlue )
    endfunction
    
    function FadeExStatic takes unit Fader, real startAlpha, real endAlpha, real Time, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, 0., startRed, startGreen, startBlue, endRed, endGreen, endBlue )
    endfunction
    
    function FadeExPeriod takes unit Fader, real startAlpha, real endAlpha, real Time, real Period, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, Period, startRed, startGreen, startBlue, endRed, endGreen, endBlue )
    endfunction
    
    function FadeExPeriodStatic takes unit Fader, real startAlpha, real endAlpha, real Time, real Period, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns SmoothFade
        return SmoothFade.create( Fader, false, startAlpha, endAlpha, Time, Period, startRed, startGreen, startBlue, endRed, endGreen, endBlue )
    endfunction

endlibrary
 

Viikuna

No Marlo no game.
Reaction score
265
Just use T32 intsead of KT2, because this fading is something that requires smooth fast periodic timer, and not dynamic periods.

You should probably have some struct for units appereance stuff, to make changes stackable.


JASS:
struct unitAppereance // create one of these for every unit
   
    private unit unit

   static thistype array Appereances // this array is for storing instances, uses unit id as an index
   
   // values, such as scale and colour values, maybe timeScale too

   real scale

endstruct

function ModifyUnitScale takes unit u, real addend returns nothing
    local unitAppereance this=Appereances[ GetUnitId( u ) ]
    set .scale=.scale+addend
    call SetUnitScale( .unit, .scale, 0,0 )
endfunction
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well... Why ? :S
Can't I leave it ? :S

Anyways... What is it that you're saying with that script there ? :S
You want my entire code to look like that ? :S
That small ? XD

I want it to be versatile too, you know :p
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well... Why ? :S
Can't I leave it ? :S

Anyways... What is it that you're saying with that script there ? :S
You want my entire code to look like that ? :S
That small ? XD

I want it to be versatile too, you know :p
 

Viikuna

No Marlo no game.
Reaction score
265
Well, your system ideeed does fading nicely and everything, but the problem is that people cant use SetUnitVertexColor while fading is in process or SetUnitScale when units is growing or shrinking.

With some unit indexing system and a struct like that I posted, you can easily fix that.

Then just change SetUnitScale in your fading triggers to ModifyUnitScale, for example.

You see what I mean?

edit. Also UnitModifyScale and UnitModifyVertexColor will be useful at their own too. They should probably be their own library, which is required by your fading library or something.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, sure :D
(I am still trying to figure out how to use unit indexing systems, but I'll try ;))

Which of all the systems would you suggest I use for this ? :eek:

Btw, weird that I double-posted there :S
Didn't post twice, I believe...

Ok, did this now:
JASS:
library ModifyAppearance initializer Init

    private function Filters takes nothing returns boolean
        return true
    endfunction

    struct unitAppereance // create one of these for every unit
   
        unit unit

        static thistype array Appereances // this array is for storing instances, uses unit id as an index
   
   // values, such as scale and colour values, maybe timeScale too

        real scale
        integer alpha
        integer red
        integer green
        integer blue

    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        local unitAppereance this = Appereances[ GetUnitId( u ) ]
        
        set this.scale = this.scale + addscale
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    function ModifyUnitVertexColor takes unit u, integer addred, integer addgreen, integer addblue, integer addalpha returns nothing
        local unitAppereance this = Appereances[ GetUnitId( u ) ]
        
        set this.alpha = this.alpha + addalpha
        set this.red = this.red + addred
        set this.green = this.green + addgreen
        set this.blue = this.blue + addblue
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
    private function Init takes nothing returns nothing
        local group g = CreateGroup()
        local unit u
        
        call GroupEnumUnitsInRect( g, bj_mapInitialPlayableArea, Filter( function Filters ) )
        
        loop
            set u = FirstOfGroup(g)
        exitwhen u == null
            call unitAppereance.create()
        endloop
        
    endfunction
endlibrary

(Not done yet :p)

But I get two errors on both these lines:
JASS:
local unitAppereance this = Appereances[ GetUnitId( u ) ]


Saying:
Undeclared function GetUnitId
and
Undeclared variable Appearances

And I have UnitIndexingUtils by Rising_Dusk, as indexing system :D
 

Viikuna

No Marlo no game.
Reaction score
265
You could try Jesus4Lyfs AIDS for example. It has enter and leave events, so you can easily create and destroy appereance structs. AutoIndex is also pretty cool.

edit. I havent used Dusks system, but Im sure its cool too. Dusk makes cool systems.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, in my opinion, AIDS is way too complicated for me XD
I just can't seem to understand a thing of how it works :(
But, if you wanna help me, I might get it to work ! :D

But, anyways... Here's what I have now:
JASS:
library ModifyAppearance

    private function Filters takes nothing returns boolean
        return true
    endfunction

    struct unitAppearance // create one of these for every unit
   
        unit unit

        static thistype array Appearances // this array is for storing instances, uses unit id as an index
   
   // values, such as scale and colour values, maybe timeScale too

        real scale = 1.
        integer alpha = 255
        integer red = 255
        integer green = 255
        integer blue = 255
        
        private static method onInit takes nothing returns nothing
            local group g = CreateGroup()
            local unit u
            
            call GroupEnumUnitsInRect( g, bj_mapInitialPlayableArea, Filter( function Filters ) )
            
            loop
                set u = FirstOfGroup(g)
                exitwhen u == null
                call thistype.allocate()
            endloop
        endmethod

    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        local unitAppearance this = unitAppearance.Appearances[ GetUnitUserData( u ) ]
        
        set this.scale = this.scale + addscale
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    function ModifyUnitVertexColor takes unit u, integer addred, integer addgreen, integer addblue, integer addalpha returns nothing
        local unitAppearance this = unitAppearance.Appearances[ GetUnitUserData( u ) ]
        
        set this.alpha = this.alpha + addalpha
        set this.red = this.red + addred
        set this.green = this.green + addgreen
        set this.blue = this.blue + addblue
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
endlibrary


But I try to use this to test it, but it shows 0, when it's supposed to be 1.0 :(:
Trigger:
  • Test Unit Appearance
    • Events
      • Player - Player 1 (Red) types a chat message containing appear as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call BJDebugMsg( I2S( unitAppearance.Appearances[ GetUnitUserData( GetEnumUnit() ) ].alpha ) )
      • Custom script: call DestroyGroup(udg_TempGroup)


So, how do I use the values the unit contains ? :S
 

Viikuna

No Marlo no game.
Reaction score
265
Well, for example, this is how it would be done with AutoIndex and StatusEvents:

JASS:
library ModifyAppearance initializer Init requires StatusEvents, AutoIndex


    struct Appearance // create one of these for every unit
   
        readonly unit unit

        
        static Appearance array array // this array is for storing instances, uses unit id as an index
   
   // values, such as scale and colour values, maybe timeScale too

        real scale = 1.
        
        integer alpha = 255
        integer red = 255
        integer green = 255
        integer blue = 255
        
        static method create takes unit u returns Appearance
            local Appearance this=Appearance.allocate()
            set .unit=u
            return this
        endmethod
        
    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        local Appearance this = Appearance.array[ GetUnitId( u ) ]
        
        set this.scale = this.scale + addscale
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    function ModifyUnitVertexColor takes unit u, integer addred, integer addgreen, integer addblue, integer addalpha returns nothing
        local Appearance this = Appearance.array[ GetUnitId( u ) ]
        
        set this.alpha = this.alpha + addalpha
        set this.red = this.red + addred
        set this.green = this.green + addgreen
        set this.blue = this.blue + addblue
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
    
    /* These functions are used to create and destroy appearance structs
    
    CreateAppearance also stores struct instance to array,
    using units id as an index.  */
    
    private function CreateAppearance takes unit u returns nothing
        local Appearance a=Appearance.create(u)
        set Appearance.array[ GetUnitId( u ) ] = a
    endfunction
    
    private function DestroyAppearance takes unit u returns nothing
        call Appearance.array[ GetUnitId( u ) ].destroy()
    endfunction
    
    private function Init takes nothing returns nothing
         /* These are events from StatusEvent.
         
         They are used to call CreateAppearance and DestroyAppearance 
         functions whenever some unit enters or leaves the map */
         
         call OnUnitEnter(CreateAppearance,true) 
         call OnUnitLeave(DestroyAppearance,true)
    endfunction
    
endlibrary
 

Jesus4Lyf

Good Idea™
Reaction score
397
And here's the above, ported to AIDS. I guarantee you every method and function is more efficient, as well as how much less code there is. :thup:
JASS:
library ModifyAppearance /*initializer Init*/ requires AIDS//StatusEvents, AutoIndex

    struct Appearance extends array // create one of these for every unit
        //! runtextmacro AIDS()
        
        //readonly unit unit
        //static Appearance array array // this array is for storing instances, uses unit id as an index
   
        // values, such as scale and colour values, maybe timeScale too

        real scale //= 1.
        
        integer alpha //= 255
        integer red //= 255
        integer green //= 255
        integer blue //= 255
        
        /*static method create takes unit u returns Appearance
            local Appearance this=Appearance.allocate()
            set .unit=u
            return this
        endmethod*/
        private method AIDS_onCreate takes nothing returns nothing
            set this.scale = 1.
            
            set this.alpha = 255
            set this.red = 255
            set this.green = 255
            set this.blue = 255
        endmethod
        
    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        //local Appearance this = Appearance.array[ GetUnitId( u ) ]
        local Appearance this = Appearance[ u ]
        
        set this.scale = this.scale + addscale
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    function ModifyUnitVertexColor takes unit u, integer addred, integer addgreen, integer addblue, integer addalpha returns nothing
        //local Appearance this = Appearance.array[ GetUnitId( u ) ]
        local Appearance this = Appearance[ u ]
        
        set this.alpha = this.alpha + addalpha
        set this.red = this.red + addred
        set this.green = this.green + addgreen
        set this.blue = this.blue + addblue
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
    
    /* These functions are used to create and destroy appearance structs
    
    CreateAppearance also stores struct instance to array,
    using units id as an index.  */
    
    /*private function CreateAppearance takes unit u returns nothing
        local Appearance a=Appearance.create(u)
        set Appearance.array[ GetUnitId( u ) ] = a
    endfunction*/
    
    /*private function DestroyAppearance takes unit u returns nothing
        call Appearance.array[ GetUnitId( u ) ].destroy()
    endfunction*/
    
    /*private function Init takes nothing returns nothing
         /* These are events from StatusEvent.
         
         They are used to call CreateAppearance and DestroyAppearance 
         functions whenever some unit enters or leaves the map */
         
         call OnUnitEnter(CreateAppearance,true) 
         call OnUnitLeave(DestroyAppearance,true)
    endfunction*/
    
endlibrary

Thanks Viikuna for calling the unit "unit". Made it easy.

As you can see all I did was delete code, and move the initial values into the AIDS_onCreate method.

Edit: Oh.
>Thanks Viikuna for calling the unit "unit". Made it easy.
I mean Komaqtion.

And you should learn AIDS structs. ;)
They're the point of AIDS, really.
 

Viikuna

No Marlo no game.
Reaction score
265
Well, it is indeed shorter to type, thanks to that textmacro thingy.

Anyways, AutoIndex and AIDS work in different ways.

AIDS uses fast periodic timer, and AutoIndex trigger events to find out when units leaves the game. I might be wrong, but I think AutoIndex method is better performance wise in general, dont you think?

edit
Yea:
Detecting removing units to free their indexes is O(1), and less costly to performance than a timer scanning the map for removed units, as some other unit indexing systems use.

I thought you were one of those guys who like O(1) stuff.

endedit

And yea, AIDS structs are pretty awesome.

edit2. Oh yea, it seems that AutoIndex has some AutoData module, so you can use that Appearance[ u ] syntax thingy.

JASS:
library ModifyAppearance initializer Init requires StatusEvents, AutoIndex


    struct Appearance // create one of these for every unit
   
        readonly unit unit
        
        implement AutoData // this implement module does that array attaching thingy for us

   // values, such as scale and colour values, maybe timeScale too

        real scale = 1.
        
        integer alpha = 255
        integer red = 255
        integer green = 255
        integer blue = 255
        
        static method create takes unit u returns Appearance
            local Appearance this=Appearance.allocate()
            set .unit=u
            return this
        endmethod
        
    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        local Appearance this = Appearance[ u ]
        
        set this.scale = this.scale + addscale
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    function ModifyUnitVertexColor takes unit u, integer addred, integer addgreen, integer addblue, integer addalpha returns nothing
        local Appearance this = Appearance[ u ]
        
        set this.alpha = this.alpha + addalpha
        set this.red = this.red + addred
        set this.green = this.green + addgreen
        set this.blue = this.blue + addblue
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
    
    /* These functions are used to create and destroy appearance structs
    
    CreateAppearance also stores struct instance to array,
    using units id as an index.  */
    
    private function CreateAppearance takes unit u returns nothing
        local Appearance a=Appearance.create(u)
        set Appearance[ u ] = a
    endfunction
    
    private function DestroyAppearance takes unit u returns nothing
        local Appearance a=Appearance[ u ]
        call a.destroy() 
    endfunction
    
    private function Init takes nothing returns nothing
         /* These are events from StatusEvent.
         
         They are used to call CreateAppearance and DestroyAppearance 
         functions whenever some unit enters or leaves the map */
         
         call OnUnitEnter(CreateAppearance,true) 
         call OnUnitLeave(DestroyAppearance,true)
    endfunction
    
endlibrary


edit3.

>Thanks Viikuna for calling the unit "unit". Made it easy.
I mean Komaqtion.

Well, it was me. I like to call units unit and timers timer and groups group and stuff like that. It makes code look more colourful here in TheHelpers Jass tags.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, thanks both of you for all the help !!!!

And you should learn AIDS structs.
They're the point of AIDS, really.

Hehe, yeah XD I'll try ;)

But, which one of these should I use then ? AutoIndex, or AIDS ? :S
 

Viikuna

No Marlo no game.
Reaction score
265
They both should work just fine, so in practice it doesnt really matter.

I suggest you to learn to use both of them and decide after that. If you for example find that those AIDS structs make coding easier for you, then use AIDS. If AutoIndex and StatusEvents stuff feels nicer, then you should use those.

Later when you have more knowledge about all this complex Jass stuff you can start to argue with other people about whats the best method to do stuff.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, I'll probably use AIDS then, since it's only one library XD

Later when you have more knowledge about all this complex Jass stuff you can start to argue with other people about whats the best method to do stuff.

Hehe XD Yeah, I definately will :p

Btw, should I "uncomment" those functions in the bottom, or what should I have them for ? :S
 

Viikuna

No Marlo no game.
Reaction score
265
Comments dont affect the functionality of the code, just readability.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah, I meant the functions at the bottom, the Init function and such...
They seem like they should be used :S
 

Viikuna

No Marlo no game.
Reaction score
265
Nope, those are not related to AIDS, they are StatusEvents stuff he commented out.

You should probably read AIDS thread to learn more. Those AIDS structs are like automaticly "created" for units when they get indexed. ( Well not actually created, since those are array structs, but still. )
 
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