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

    io.open ... is there a way to enable this?

    I need the ability to both write and read from an external .txt file from within the lua code. When I try this I get:

    Code:
    lua attempt to index global 'io' (a nil value)
    Here is my implementation in the code:

    Code:
    local file = io.open( "StoredTableResults.txt", "a+" )
    Can I enable the use of the io library? Any help will be GREATLY appreciated.

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,402
    There are a lot of LUA libraries specifically not allowed in the FG API for security reasons. Giving direct access to the io library would be a major security issue.

    More info here: https://fantasygroundsunity.atlassia...ic-Lua-Changes
    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
    Thanks Trenloe- quick question after reading that article:

    It sounds like I can read and write to the Campaign Registry? If so, where can I learn more about how to do that?

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,402
    Quote Originally Posted by JimSocks View Post
    It sounds like I can read and write to the Campaign Registry? If so, where can I learn more about how to do that?
    It's basically a set of LUA tables that get stored in a specific file when the campaign exits, and read back in when the campaign loads again.

    As mentioned in that article - they're CampaignRegistry and GlobalRegistry - the former is campaign specific and data for the campaign is stored in <FG app data>\campaigns\<campaign name>\CampaignRegistry.lua and the latter covers all campaigns and is stored in <FG app data>\GlobalRegistry.lua

    Do a "find in files" in the CoreRPG ruleset for examples of how to store and access data in those LUA tables. A good example to look at is CampaignRegistry.sidebar which stores which buttons were displayed in the sidebar when the campaign exited.
    Last edited by Trenloe; November 5th, 2020 at 20:45.
    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
    Amazing. Thanks again good Sir!

    I’ll be digging into that right after dinner!

  6. #6
    So, I have found instances where the original code seems to write to the campaign registry through very simple syntax like:

    Code:
    CampaignRegistry.keyname = "value string"
    But when I try to do this, it seems to have no effect, and nothing is added to CampaignRegistry.lua

    I have to call it a night for now, but any suggestions you have would be greatly appreciated!

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,402
    Have you exited the campaign and then checked the file contents? It doesn't write to the file when the campaign's running.
    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
    Quote Originally Posted by Trenloe View Post
    Have you exited the campaign and then checked the file contents? It doesn't write to the file when the campaign's running.
    It doesn’t!? Well crap. That’s not gonna work anyways for what I need it for. Back to the drawing board.

    I am trying to store a table of keys and values during an entire play session, even if the story template window is closed. I have tried putting the table outside of the onButtonPress() function (within CoreRPG/campaign/scripts/story_template_generate.lua) and even setting it as global, but for some reason it seems to be erased each time the storytemplate window is exited.

    Do I maybe need to fiddle with it at the window class level in the xml? Hmm...

  9. #9
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,402
    Quote Originally Posted by JimSocks View Post
    It doesn’t!? Well crap. That’s not gonna work anyways for what I need it for.
    That's what I mentioned in my post above: "It's basically a set of LUA tables that get stored in a specific file when the campaign exits, and read back in when the campaign loads again." But that's just the file, the data is stored in memory. Only use CampaignRegistry if you need to persist data from one session to the next.

    Quote Originally Posted by JimSocks View Post
    I am trying to store a table of keys and values during an entire play session, even if the story template window is closed. I have tried putting the table outside of the onButtonPress() function (within CoreRPG/campaign/scripts/story_template_generate.lua) and even setting it as global, but for some reason it seems to be erased each time the storytemplate window is exited.
    Take a look at script block scope: https://fantasygroundsunity.atlassia...pt-Block-Scope

    If a script is tied to a control or a windowclass then data in the associated scripts will only be available while that control/window is open. If you close it, the scope also closes and with it all of the variables and data from that scope.

    If you want a set of variables to persist throughout a session then setup a global script package (declared in base.xml of a ruleset, or extension.xml of an extension), setup a data structure and store/read data to/from that package. DataCommon is an example global package used for storing data.
    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!

  10. #10
    Then I would suggest a global LUA table. Something similar to DataCommon. You can keep this table static or insert or remove from the list to keep it ongoing.

    Edit: Trenloe's response breaks it down better than I have. It didn't show when I was responding.
    Last edited by superteddy57; November 10th, 2020 at 13:37.
    Dominic Morta
    Ruleset Developer
    Smiteworks

    How to zip up your campaign if the Developers ask for it-How to zip up your campaign if the Developers ask for it

    How to provide an Unity Connection issue?-Connection Issues and What to Provide

    Unity Updater issue?-Updater Issues

    Classic and Unity Port Forwarding?-Fantasy Grounds Connections Explained

    Comcast or Cox ISP User?-Comcast XFinity and Cox Users

    Have a suggestion?-Feature Request

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