Attributes at runtime

  • June 20, 2017 at 19:58 #21085
    Lukas
    Participant

    Is there a way to set a units attribute/s at runtime/creation?

    Cheers
    Lukas

    June 20, 2017 at 21:41 #21087
    Geminior
    Keymaster

    Since the UnitFacade does not expose a setter, you will have to either expose that or explicitly get a reference to the attributed component (UnitComponent), e.g.

    Have a look at the AttributeManipulatingTrigger class as well.

    June 21, 2017 at 09:03 #21089
    Lukas
    Participant

    I actually figured AttributeComponent out myself, but wasn’t sure this was the correct way to do it because strange things are happening when I set my attributes that way:

    If I have { friend=2, enemy=3 } in my unit types, I have to set c.attributes to double the value (4 for friend, 6 for enemy) for it to work. I tried this with the ExempleUnitTypes and also a custom one.

    June 21, 2017 at 12:28 #21100
    Geminior
    Keymaster

    The Attribute property is a mask. This means that your enum should be a Flags enum and each value should be a power of 2, e.g. 0, 1, 2, 4, 8 etc.

    June 21, 2017 at 16:17 #21104
    Lukas
    Participant

    I had no idea. Thank you for clarifying.

    June 21, 2017 at 20:31 #21114
    Lukas
    Participant

    I actually spoke too soon. My unit types are {None=0, Freund=1, Feind=2}. To set the units attribute to “Freund” I have to set the attributes to 2, for “Feind” to 4 for the unit to have the correct attributes.

    August 1, 2017 at 13:38 #21590
    Geminior
    Keymaster

    It appears we missed this post, sorry about that. I don’t quite understand you question though.
    As long as 0 represents None, 0, 1, 2 are perfectly valid values, 2^0 = 1, 2^1 = 2 etc.

You must be logged in to reply to this topic.

Topic Tags