Hi All,
I'm going to try to describe this as best I can, but I'm aware it's both a complex and unusual problem. Here we go...
Some background, to help explain how I got here... I have a script (
https://github.com/manix84/discord_gmod_addon/blob/master/lua/autorun/shared.lua) which stores a Table as JSON, containing {"SteamID":"DiscordID"}. This table drives a bot which Mutes players in Discord when they die in TTT/TTT2/Murder/etc. I've finished the script and I'm relatively happy with it, even if it needs some major cleanup. This is my first GMod addon, and my first time playing with (G)Lua.
Recently I've been trying to add ULX menu support. I successfully managed to add the commands (see:
https://imgur.com/Mm17dmY), which gave me something of a boost in confidence, as I've been mostly reading other developers code, and trying to understand it. My next step was to try to introduce a settings menu (similar to how the TTT and Randomat ULX menus work). After some trial and error, I actually managed it, and added a new menu under Settings (see:
https://imgur.com/qjtIImn). Again, I was elated, as this was hugely laborious work, reading through other examples, and even the source code for ULX itself.
The issue came when I tried to create a user friendly method for Admin's to add Discord ID's against Steam ID's, in the ULX menu system. What I want to do, is add a list of users who are connected, with the Discord ID listed next to there names (see:
https://imgur.com/ZDkKIOU, sorry i scrubbed my ID for reasons). This works so far, when I hard code the ID JSON (EG: {"SteamID":"DiscordID"}). However, inside (
https://github.com/manix84/discord_gmod_addon/blob/master/lua/ulx/xgui/settings/discord.lua), when I try to collect the cache of ID's from the file system, I get back Nil. Even when using the exact same util function (see:
https://github.com/manix84/discord_gmod_addon/blob/master/lua/utils/connectionTable.lua) from the Shared.lua script. However, if I write to the file first, and then read from it, I can see the JSON, but it doesn't match the JSON in the file on the server.
What seems to be happening is File.Read/Write and ULib.fileRead/fileWrite, when in the XGUI folder, seem to be writing to some kind of Memcache layer. I don't know if this is true or not, as my experience is very small, but the evidence is pointing to that.
Side Note on why I want admins to add the connections manually from the menu: The issue comes from my own experience running a server for after work games, and a lot of these extremely intelligent programmers, don't understand how to type "!discord MyDiscordName" into chat without a lot of hand holding. Night now, I have to manually edit the connections_cache.json file and add the SteamID: DiscordID connections for new team members playing. I wanted to get away from that if I could.
If ANYONE can give me a hand figuring this out, I would be extremely grateful.
-Manix84
TL;DR: I want to read and write a json file on my server. I can't seem to read/write the same file from inside
lua/autorun/shared.lua and
lua/ulx/xgui/settings/discord.lua. I'm really confused. For a better explanation, read above.