DICE PACKS BUNDLE
Page 1 of 2 12 Last
  1. #1

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247

    Has User.onIdentityActivation Been Removed/Changed?

    Greetings,

    I have been overriding the User.onIdentityActivation function successfully, however after the last update, it is failing.

    To test to see if something was going wrong, I simply tried to print out (Debug.chat) the User.onIdentityActivation function, without overriding and it is returning 'nil'.

    So has the name of this function changed? I am going by https://fantasygroundsunity.atlassia...tityActivation

    Has anything changed?
    Thanks In Advance,
    D

  2. #2
    Several global scripts in CoreRPG use the User.onIdentityActivation handler registration. You can not use Debug to get the value, because you are actually using that call to register a handler function. It's not a function definition. This handles things like adding the character portraits on the top left, which is still working for me.

    You'll need to put Debug statements in your override function to see what is happening when it is called.

    Regards,
    JPG

  3. #3

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Okay ... I have debugged within my override as well ...

    It simply does not work anymore ... I perform the following code to override ...

    Code:
    function OverrideOnIdentityActivation( )
    	Debug.chat("Original Function", User.onIdentityActivation)
    
    	self.PreviousOnIdentityActivation = User.onIdentityActivation
    	User.onIdentityActivation = self.OnIdentityActivation
    
    	Debug.chat("Overriding Activation", self.PreviousOnIdentityActivation, User.onIdentityActivation)
    end
    
    function OnIdentityActivation( identity , user , activated )
    	Debug.chat("We have an Activation",identity,user,activated)
            Debug.chat("Previous is",self.OnIdentityActivation, self.PreviousOnIdentityActivation)
            self.PreviousOnIdentityActivation( identity , user , activated )
    end
    This overrides the function, however it does not store the previous one.

    As you can see I am attempting to store the previous version as good programming practice, and in addition I call the previous version (or attempt to) to keep any operations within it active since in the ruleset I am using (Savage Worlds) it overrides onIdentityActivation in four different locations in templates - not sure how that works.

    How do I store/call the previous function?
    Last edited by UrsaTeddy; October 14th, 2022 at 23:16. Reason: Clarification attempt
    Thanks In Advance,
    D

  4. #4
    You can't override a previous onIdentityActivation handler. Handlers may look like a simple assignment, but they are not. They are a way to register a function for an event; not setting/getting a function value.

    It was never able to be referenced like that.

    Regards,
    JPG

  5. #5

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Okay ... so then how do I store the previous function ... or is this not possible?

    This is something that is important if I just want to "add on" some functionality without disturbing previous onIdentityActivation code from, for example, another ruleset or another extension.
    Thanks In Advance,
    D

  6. #6
    You would have to change the function in that global script before it assigns itself to the handler, if the script is written to allow it.

    If the script assigns the event in the onInit, then you can't; because you have no guarantee of initialization order.
    If the script assigns the event in a separate handler tied to onDesktopInit (or in an onTabletopInit function in v4.3), then you can override the function in a separate onInit global script.

    For example, in the CoreRPG CharacterListManager and LanguageManager, the handler registrations are done in onDesktopInit, which means you could theoretically override those functions before they are registered.
    Code:
    function onInit()
        PreviousOnIdentityActivation = CharacterListManager.onIdentityActivation;
        CharacterListManager.onIdentityActivation = OnIdentityActivation;
    end
    function OnIdentityActivation(sIdentity, sUser, bActivated)
        PreviousOnIdentityActivation(sIdentity, sUser, bActivated);
        <Your New Code>
    end
    Regards,
    JPG

  7. #7

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Okay, so I am obviously missing something.

    You have overridden the function in multiple locations, so how would I ensure that all of those functions are executed as they are expected to be?

    For example your CharacterList manager does not call a previous version of onIdentityActivation, so if I override the standard version with User.onIdentityActivation = MyFunction, it will not interfere with your CharacterList manager?
    Thanks In Advance,
    D

  8. #8
    A handler is not the same as a function assignment. It may look similar, but under the hood, it is handled completely differently. These events can not be accessed to retrieve them. You have to capture in advance as in my example post above.

    In fact, this particular part of the API is confusing enough that I've been working on replacement APIs for v4.3 to make this more obvious that you're registering a handler for an event.
    (Ex: User.addEventHandler("onIdentityActivation", DiceSkinManager.onUserIdentityActivate)

    Regards,
    JPG

  9. #9

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Okay so the addEventHandler function will queue up my onUserIdentityActivation for execution? Is that what you are stating?
    Thanks In Advance,
    D

  10. #10
    Yes.

    If you just need to be notified of the event and trigger independent actions, then just register your own event handler. (i.e. CoreRPG does this with LanguageManager and CharacterListManager)
    If you need to specifically override another function that's being used as an event handler to change the behavior, then all the previous stuff we talked about applies.

    Regards,
    JPG

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in