-
November 5th, 2020, 19:54 #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)
Code:local file = io.open( "StoredTableResults.txt", "a+" )
-
November 5th, 2020, 19:58 #2
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-ChangesPrivate 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!
-
November 5th, 2020, 20:26 #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?
-
November 5th, 2020, 20:41 #4
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!
-
November 5th, 2020, 23:10 #5
Amazing. Thanks again good Sir!
I’ll be digging into that right after dinner!
-
November 10th, 2020, 05:56 #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"
I have to call it a night for now, but any suggestions you have would be greatly appreciated!
-
November 10th, 2020, 08:07 #7
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!
-
November 10th, 2020, 12:25 #8
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...
-
November 10th, 2020, 13:33 #9
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.
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!
-
November 10th, 2020, 13:33 #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