Rick Posted February 9, 2016 Share Posted February 9, 2016 It looks like this doesn't write to file until the exe closes. Is there any way to flush this write to happen whenever we need it to? Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 9, 2016 Share Posted February 9, 2016 what file does this write to? Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rick Posted February 9, 2016 Author Share Posted February 9, 2016 Looks like a config file in AppData/Local/yourgame Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 9, 2016 Share Posted February 9, 2016 Ok, I see what you are saying that it doesn't appear to write to the cfg file until after game closes. But is still appears that setting a property in game allows for you to get that value via GetProperty() while in the same session. So what are you trying to do that requires it to write immediately? 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rick Posted February 9, 2016 Author Share Posted February 9, 2016 Interesting that when I send the results directly from GetProperty() to Print() it errors but if I assign it to a variable first it works. System:Print(System:GetProperty("profile1")) vs local r = System:GetProperty("profile1") System:Print(r) The other thing is that I'm saving a table that I convert to string so it might be because of that. The jist that I'm trying to do is save a lua table to string, then read it back and convert it back to a table using loadstring() so I can treat this as a way to save game data, but so far the loadstring() is returning nil after reading the table back in. This is the code I'm using to convert table to string and it seems to work well. function serializeTable(val, name, skipnewlines, depth) skipnewlines = skipnewlines or false depth = depth or 0 local tmp = string.rep(" ", depth) if name then tmp = tmp .. name .. " = " end if type(val) == "table" then tmp = tmp .. "{" .. (not skipnewlines and "\n" or "") for k, v in pairs(val) do tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "") end tmp = tmp .. string.rep(" ", depth) .. "}" elseif type(val) == "number" then tmp = tmp .. tostring(val) elseif type(val) == "string" then tmp = tmp .. string.format("%q", val) elseif type(val) == "boolean" then tmp = tmp .. (val and "true" or "false") else tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\"" end return tmp end Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 10, 2016 Share Posted February 10, 2016 Just taking a simple approach that seems to work okay for setting a table as one property in the config file then reading back in that property and setting to a table. --Set table values as one key's value function System:SetTableAsOneKey(t,name) for k,v in pairs(t) do t[k] = tostring(v) end local s = table.concat(t, "|") s = s.."|" System:SetProperty(name, s) end --Get one key's value and set as table function System:GetOnePropertyAsTable(t,name) local s = System:GetProperty(name) local k = 1 for v in string.gmatch(s, "%w+") do t[k] = v k = k + 1 end return t end --test code mytable = {} mytable[1] = "string1" mytable[2] = true mytable[3] = 545.0003 System:SetTableAsOneKey(mytable, "OneKey") OneKey = {} OneKey = System:GetOnePropertyAsTable(OneKey, "OneKey") if (OneKey[2]=="true") then OneKey[2] = true else OneKey[2] = false end enabled = OneKey[2] if enabled==true then System:Print("ENABLED!") end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rick Posted February 10, 2016 Author Share Posted February 10, 2016 Just curious, have you tried calling set in 1 run, and then only calling the get in a new run of the exe? The config file seems to be empty when I do that. If they are both in the same run it works, but that's not how we'd want it. I have the standard Main() setup when testing this and I do it after the window is created (other GetProperty()'s called). Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 10, 2016 Share Posted February 10, 2016 and this is how i would approach setting a table as multiple keys: --Set table as multiple properties function System:SetAllTableProperties(t) for k,v in pairs(t) do System:SetProperty(k, tostring(v)) end end --Get properties as a table function System:GetAllTableProperties(t) for k,v in pairs(t) do t[k] = System:GetProperty(k) end return t end --test code enabled = true mytable1 = {} mytable1.color = "1,0,1,1" mytable1.name = "testkey and value" mytable1.boolean = enabled System:SetAllTableProperties(mytable1) mytable2 = {} mytable2.name = 0 mytable2.boolean = 0 mytable2.color = 0 mytable2 = System:GetAllTableProperties(mytable2) if (mytable2.boolean=="true") then mytable2.boolean = true else mytable2.boolean = false end if mytable2.boolean==true then System:Print("ENABLED!") end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
macklebee Posted February 10, 2016 Share Posted February 10, 2016 Just curious, have you tried calling set in 1 run, and then only calling the get in a new run of the exe? The config file seems to be empty when I do that. If they are both in the same run it works, but that's not how we'd want it. When I run just this: --Set table values as one key's value function System:SetTableAsOneKey(t,name) for k,v in pairs(t) do t[k] = tostring(v) end local s = table.concat(t, "|") s = s.."|" System:SetProperty(name, s) end --test code mytable = {} mytable[1] = "string1" mytable[2] = true mytable[3] = 545.0003 System:SetTableAsOneKey(mytable, "OneKey") I get this in my cfg file: OneKey=string1|true|545.0003| Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rick Posted February 10, 2016 Author Share Posted February 10, 2016 Right, so you are setting them there. Now restart the exe and only do the getting part. For me the config is empty when I do that. Even if I don't do the reading part. It's like the config file gets cleared out each run. I would think the idea of a config file would be to maintain itself between runs. Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 10, 2016 Share Posted February 10, 2016 Right, so you are setting them there. Now restart the exe and only do the getting part. For me the config is empty when I do that. So I run just this code now: --Get one key's value and set as table function System:GetOnePropertyAsTable(t,name) local s = System:GetProperty(name) local k = 1 for v in string.gmatch(s, "%w+") do t[k] = v k = k + 1 end return t end OneKey = {} OneKey = System:GetOnePropertyAsTable(OneKey, "OneKey") System:Print(OneKey[1]) System:Print(OneKey[2]) System:Print(OneKey[3]) And I get this in the console: string1 true 545 And my cfg file still has this in it: OneKey=string1|true|545.0003| My key/value property doesn't get written over unless i tell it to... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rick Posted February 10, 2016 Author Share Posted February 10, 2016 Very strange. That's not what I'm experiencing. My config file is getting totally wiped out on each run. Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 10, 2016 Share Posted February 10, 2016 Very strange. That's not what I'm experiencing. Without seeing what you are doing I can't say what's different. Ive tried it sandboxed and not, and it makes no difference, the key doesn't get deleted or overwritten by just performing a GetProperty. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rick Posted February 10, 2016 Author Share Posted February 10, 2016 Wow, very strange stuff here. So I just did: System:SetProperty("test", "Rick") and it showed up and stayed up between runs when I commented it out after. Then I wrote my map table again which results in 451KB in size. I then closed the exe, commented out any set or get and reran. Once I closed again the file size went back down to 1KB and only had my test=Rick in it. Maybe it's a size thing of the file? Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 10, 2016 Share Posted February 10, 2016 could be - as you might be trying to use it in a way that wasn't expected or intended. dunno. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Josh Posted February 10, 2016 Share Posted February 10, 2016 There's nothing I programmed into it that would do that intentionally. It's pretty simple. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.