HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Is this script useless?

03-06-2009, 11:21 PM#1
TriggerHappy
Attaching structs to units?

I made this fairly quickly, and haven't researched if there were any other systems of the like.

Don't be harsh.

Collapse JASS:
library USA

private struct usa

    integer oldUserData
    integer Struct
    
    static method create takes unit a, integer i returns usa
        local usa u = usa.allocate()
        set u.oldUserData = GetUnitUserData(a)
        call SetUnitUserData(a, i)
        set u.Struct = i
        return u
    endmethod
    
endstruct

function USAStore takes unit a, integer s returns nothing
    local usa u = usa.create(a,s)
endfunction

function USAGet takes unit u returns integer
    return usa(GetUnitUserData(u)).Struct
endfunction

function USAReset takes unit u returns nothing
    call SetUnitUserData(u, usa(GetUnitUserData(u)).oldUserData)
    call usa(GetUnitUserData(u)).destroy()
endfunction
 
endlibrary
03-06-2009, 11:23 PM#2
Bobo_The_Kodo
Look in the resource section; theres at least 5 scripts/systems for this purpose.
03-06-2009, 11:24 PM#3
Vexorian
It's not useless as in.. the idea is not useless.

However, it is kind of useless.

Notice units are public objects. Therefore a lot of things will want to access them. It could be a spell applying a single buff or your map's main system.

So, how would you control two things trying to access information in a unit? you would either need to add more fields to the struct or think of something else.

For snow and hazards I did this to store each unit's information struct.
03-06-2009, 11:24 PM#4
TriggerHappy
Alright, thanks.

No problem, took me 5 minutes to make this, i'll throw it away.