• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How to get the value of a unit's scaling?

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

Suppose I made this call

JASS:
call SetUnitScale(u, 2.0, 2.0, 2.0)

Now suppose at some later point I want to increase my units scaling by .50. How do I find the current value of the scaling?

JASS:
call SetUnitScale(u, GetUnitScaleX(u) + 0.50, GetUnitScaleY(u) + 0.50, GetUnitScaleZ(u) + 0.50)
 
Unfortunately, you can't. Just make a struct wrapper, have a Table instance or use an indexer and store the value. That relies on you to use the struct to change the scaling though, of course. There is no native way though, so that is the best route. :)
JASS:
struct UnitScale extends array
    private static Table data = 0

    static method operator []= takes unit u, real value returns nothing
        call SetUnitScale(u, value, value, value)
        set data.real[GetHandleId(u)] = value
    endmethod

    static method operator [] takes unit u returns real
        local integer id = GetHandleId(u)
        if data.real.has(id) then
            return data.real[id]
        endif
        return 1.
    endmethod

    private static method onInit takes nothing returns nothing
        set data = Table.create()
    endmethod
endstruct

// usage:
//
//    local unit u = GetTriggerUnit()
//    set UnitScale[u] = 1.25
//    call BJDebugMsg(R2S(UnitScale[u])) -- should print 1.25
//

Something like that. That is how I'd do it. maybe. untested. You can also just write basic methods to do it instead of doing the operators on []= and [], but that isn't cool enough.

(•_•)
( •_•)>⌐■-■
(⌐■_■)
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Ah right I sometimes forget about doing things like that.

I think I'll just op for a real valued variable inside the struct I'm using (already got a wrapper around a unit).

Thanks for reminding me!
 
Status
Not open for further replies.
Top