DMsGuild Classic
  1. #1

    How to determine when a function is fired

    I'm writing my first extension for FG, what it will do is calculate the remaining XP needed to go to the next level.

    The issue I'm having is that when I change the value of the current XP or Next Level XP fields the extension doesn't update my XP remaining field.

    Questions

    1. Did I code something wrong (no error when loading in FG)
    2. Am I using the wrong function to do the update.
    3. I have tried both Debug.console and Debug.chat to try to troubleshoot but neither will show any messages, how to find out if the function is being called
    Attached Files Attached Files

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    29,148
    Which event are you referring to?

    Loading up this extension, when I press the magnifying glass button (control = calcXpNeeded) the onButtonPress() event runs and I get a console error: Script Error: [string "calcXpNeeded"]:1: bad argument #4 to 'setValue' (number expected, got string)
    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
    Trenloe,

    Sorry about that, I uploaded the wrong version, the function I'm having problems with is the onSourceUpdate() in the XP Needed field definition.
    Attached Files Attached Files

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    29,148
    onSourceUpdate is not a predefined event. You'll need to setup specific event handlers to trigger onSourceUpdate.

    Put the following in the <script> block before the onSourceUpdate function:

    Code:
    					function onInit()
    						local nodeWin = window.getDatabaseNode();
    						DB.addHandler(DB.getPath(nodeWin, "exp"), "onUpdate", onSourceUpdate);
    						DB.addHandler(DB.getPath(nodeWin, "expneeded"), "onUpdate", onSourceUpdate);
    						
    						onSourceUpdate();
    					end
    You might also want to make the control <readonly /> so that it can't be updated through the interface.
    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!

  5. #5
    Trenloe,

    Thanks, that is what I was looking for.

    I had posted a similar question on the 5E forum, and Damned helped clarify the error you first got when you tried the extension. He also made a few suggestions

    1. Make it calculate any time you change the level, XP or Next Level values.
    2. Make it calculate when you open that window as well.
    3. You might also look at automatically setting the Next level values every time the Level changes.

    Originally I was trying to due the update via a button, but I liked suggestion #1 more so that is what is does now.

    I would like to try and do suggestions 2 & 3. I'm assuming that for suggestion 2, I would put the same onInit and onSourceUpdate code of the "charsheet_classes" windowclass. When I tried this (as is) I get a console error: Script Error: [string "charsheet_classes"]:1: attempt to index global 'window' (a nil value)

    How do I get the DatabaseNode when opening the window.

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    29,148
    Suggestion 2 is included in the code I provided. It runs onSourceUpdate as part of the onInit function when the window is opened.
    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!

  7. #7
    Thanks for clarifying that Trenloe, I was thinking the onInit was only dealing with the field it was defined on.

    As for suggestion 3, I would like to add the calc code, to code that calculates the total class level (if that is the best place to put it), do you know where I should look for that code.

  8. #8
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    29,148
    Quote Originally Posted by KlatuB View Post
    Thanks for clarifying that Trenloe, I was thinking the onInit was only dealing with the field it was defined on.
    onInit within that fields codes is only triggered when that field is initialized. But that field is initialized when the window is first opened, so it will run, setup the DB handlers for the fields it needs to monitor for changes and also with calling onSourceUpdate() it will do an initial calculation based off the other XP fields when the window is opened.

    Quote Originally Posted by KlatuB View Post
    As for suggestion 3, I would like to add the calc code, to code that calculates the total class level (if that is the best place to put it), do you know where I should look for that code.
    Look at the code in campaign\scripts\char_manager.lua - function addClassRef. There is code in there that calculates the total level - starts at the "-- Calculate total level" comment and also where "nodeList" is created earlier in the function. You can extract these few lines of code to use to calculate the total level.
    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!

  9. #9
    Trenloe,

    Thanks for all the help, I have everything working the way I want it. I will be posting the finished extension over on the 5e forum shortly.

  10. #10
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    29,148
    Quote Originally Posted by KlatuB View Post
    Trenloe,

    Thanks for all the help, I have everything working the way I want it. I will be posting the finished extension over on the 5e forum shortly.
    No worries. Pleased you got it working they way you want.
    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!

Thread Information

Users Browsing this Thread

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SWADE Playlist

Log in

Log in