• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,337
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,337
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