5E Product Walkthrough Playlist
Page 1 of 2 12 Last
  1. #1

    How to validate "databasenode = { }"

    I've a bit of code that I need to check the value of a node.

    Code:
    Runtime Notice: s'manager_effect.lua' | s'adnd_processEffect' | s'nodeEffect' | databasenode = {  }
    When the value of nodeEffect is "{ }" I need to do something... the problem is I can't figure out a good way to test nodeEffect and that it equals { }.

    The best way I could figure out was to do this.

    Code:
        -- check if effect still exists. removed in fCustomOnEffectActorStartTurn() probably
        -- we check the .getPath() through pcall and if it fails then just end this run.
        if not pcall(function () nodeEffect.getPath() end) then 
          Debug.console("manager_effect_adnd.lua","adnd_processEffect","nodeEffect removed in-line",nodeEffect);    
          return;
        end
    It works by running the .getPath() on the nodeEffect and if it returns an error through pcall I do what I need to do.

    Is there a better way to handle this or is this the best?

    The reason this happens... is during the effects processing on a players turn, they might "die" from "DMGO" effects. If that happens, in the manager_action_damage code I remove the DMGO effect (this is part of death's door for AD&D) but when it comes back here from running the custom function the effect is gone... so I test for it and continue or end this effects loop as necessary.

    I could just leave the effect on the dead player and let it keep ticking and make my life easier but this does what I want (allows me to remove the effect and then apply a dead effect on them). I'm considering going that way because I had to override a bit of CoreRPG code to do this...
    ---
    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.

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    Quote Originally Posted by celestian View Post
    I've a bit of code that I need to check the value of a node.

    Code:
    Runtime Notice: s'manager_effect.lua' | s'adnd_processEffect' | s'nodeEffect' | databasenode = {  }
    When the value of nodeEffect is "{ }" I need to do something... the problem is I can't figure out a good way to test nodeEffect and that it equals { }.
    So, it's a LUA table. Maybe check for an empty table? A quick google gives this as a possible solution (the one with the green check mark): https://stackoverflow.com/questions/...ins-no-entries

    Using if next(myTable) == nil then
    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
    So, it's a LUA table. Maybe check for an empty table?
    I had actually tried that (tho I wasn't hopeful) and the error when trying that was....

    Code:
    Runtime Notice: Reloading ruleset
    Script Error: [string "scripts/manager_effect_adnd.lua"]:564: bad argument #1 to 'next' (table expected, got userdata)
    The type() of the variable is databasenode so I am pretty sure that's why it barfed.
    ---
    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
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    Quote Originally Posted by celestian View Post
    The type() of the variable is databasenode so I am pretty sure that's why it barfed.
    Ah, OK. I was misreading your debug. So it's an empty databasenode, but not nil.

    What does if nodeEffect do? Does it return true or false?
    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
    Quote Originally Posted by Trenloe View Post
    Ah, OK. I was misreading your debug. So it's an empty databasenode, but not nil.

    What does if nodeEffect do? Does it return true or false?
    When its the listed debug output it returns true using "if nodeEffect" because it's not nil. Infact it always returns true because it's never "nil".
    ---
    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.

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    Yeah, then you're left to variations on what you're doing. How about DB.getType(nodeEffect) - what does that return?
    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
    Quote Originally Posted by Trenloe View Post
    Yeah, then you're left to variations on what you're doing. How about DB.getType(nodeEffect) - what does that return?
    Returns "node" as the type but if it's { } it bombs, the same type I was trying to avoid.
    ---
    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.

  8. #8
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    Looks like your code is good enough then!
    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
    Quote Originally Posted by Trenloe View Post
    Looks like your code is good enough then!
    Heh, was hoping someone had a better idea than that.

    It would be useful if we had a DB.exists(nodeEffect) or similar function perhaps.

    After all this I think I might just pull it all out and just leave the effect on the dead character. In the long run I think it'll be better that I don't override CoreRPG code (in this case EffectManager.processEffect()).
    ---
    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.

  10. #10
    How are you getting a node with no path? Was it deleted during the script?

    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
  •  
DICE PACKS BUNDLE

Log in

Log in