5E Product Walkthrough Playlist
Page 1 of 2 12 Last
  1. #1
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075

    When does onClose() for a Windowless lua script get called?

    ** Edit: Oop, please ignore “Windowless” above, I wondered why people assumed that when I was referring to a file script used by char_main.xml file. It is a script attached to windowclass not global - Sorry **

    I tried to set it up like a good little C++ boy and then to test I put trace code and only saw it register on onInit but never deregister.

    Under what conditions does anything call onClose()? If not normally deterministic, is there a way to request it to test my code a la java force GC type hints?

    Code:
    function onClose()
    	local nodeChar = getDatabaseNode();
    
    	DB.removeHandler(DB.getPath(nodeChar, "abilities.*.score"), "onUpdate", updateAbilityScoreDependencies);
    	DB.removeHandler(DB.getPath(nodeChar, "abilities.*.baseautomod"), "onUpdate", updateAbilityScore);
    	DB.removeHandler(DB.getPath(nodeChar, "abilities.*.baseracemod"), "onUpdate", updateAbilityScore);
    	
    	OptionsManager.unregisterCallback("HouseRule_SavingThrowMethod", onSavingThrowsOptionChanged);
    end
    Last edited by Varsuuk; August 9th, 2019 at 22:20.

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    onClose is based on a windowinstance: https://www.fantasygrounds.com/refdo...ce.xcp#onClose So it doesn't make sense in a script scope that is windowless.

    Maybe provide some context of what you're trying to do?
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    Quote Originally Posted by Trenloe View Post
    onClose is based on a windowinstance: https://www.fantasygrounds.com/refdo...ce.xcp#onClose So it doesn't make sense in a script scope that is windowless.

    Maybe provide some context of what you're trying to do?
    I'm guessing he's talking about a "global script". While you can have an onClose() for those there really isn't a need unless you want to dump out something to file? Far as I know when you close/go back to campaign select all of those handlers/registers are removed.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  4. #4
    Ikael's Avatar
    Join Date
    Jan 2008
    Location
    Finland/Joensuu
    Posts
    2,383
    If you need to do something when desktop/vtt is closing you can use https://www.fantasygrounds.com/refdo...onDesktopClose

    But in general no cleaning is required for Global scripts.
    "Alright, you primitive screwheads, listen up: THIS... is my BOOMSTICK!" -- Ash Williams, Army of Darkness

    Post your SavageWorlds ruleset feature requests and issue reports here!

  5. #5
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Thanks guys. I just wasn’t sure since I saw that sort of addhandler/removehander registercallback/inregcallback, etc behavior in 5E’s char.lua, 3.5’e charmain and of course a more full reg/unreg in Celestian’s fine 2e which I looked at a lot at the start before deciding to go minimal and add.

    It appears in what I posted above I didn’t include info I listed in the prior thread I started, sorry.


    In the Breaking up Lua file thread, I listed which lua file I was working on:
    Code:
    <root>	
    	<windowclass name="charsheet_main">
    		<script file="campaign/scripts/char_main.lua" />
    I’m sorry, I was flying that day with crazy delays and probably forgot what thread was on (got home today 3:25am)

    So this lua file is supposedly not global it is attached to the charsheet_main window.

    I ran across this because I was moving my handler for Options from a control to the more general window lua script. I wanted to test set it up right and added the logging on init/close

    Side note to Moon (if see): I THINK I was seeing the same multiple messages when I hit the options choices - more on that when I look up my old post here where you said I think it was a big to look at. I want to see the orig case and make sure still seeing it before start a new thread)

  6. #6
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    PS - I don’t “need” to do anything of my own accord. Just trying to match existing patterns. Obviously from a C++ POV, I expect this sort of thing and patterns like RAII.

    So if told not called, fine be me if that’s right. I haven’t added code I needed for my work - just for what I thought was proper plumbing.

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    Saying "windowless" in the thread header threw everyone...
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  8. #8
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Argh - you are RIGHT, I was thinking of the CharManager to be honest when started writing and hen realized it was the window lass one.

    I totally wasted everyone’s time in confusion. That day was hell. Dying to leave work to go get some sleep. <3 hours so far 30hours hurts


    So yeah, It didn’t SEEM (sleep deprivation?) to call onClose() as my Devug.console(“onInit”) prints but not Debug.console(“onClose”)

    I won’t get a chance prob to look today as I will prob crash early. Thanks all.

  9. #9
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Hmmm ... this got "fixed" for me too...

    Moon, was this also changed from like March of this year on?
    Right now, notice the onClose() printouts that I had for the Windowclass are now logging as I hit reload and before I removed them the ones for globals threw errors saying unavailable global index or something on Debug

    Darn softlinks...

  10. #10
    It's because window instances are closed (and trigger onClose event), before global packages are unloaded. Global packages (both built-in and custom) are unloaded all together, which is why Debug package calls in onClose of a global package will throw an error in many cases (because Debug unloaded first). In FGU, I believe I already fixed it so that custom global scripts are loaded after built-in packages, and unloaded before built-in packages.

    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
  •  
FG Spreadshirt Swag

Log in

Log in