Jump to content

System:GetProperty() fails to read long strings


Rick
 Share

Recommended Posts

Attached is what my config file looks like after I write to it via System:SetProperty(). However, when I close my exe and open it up again to try and read it, it's empty. When the exe closes this time the file itself is empty too. It's like it's able to write a long string but it's not able to read a long string correctly.

 

Is there any way in your reading of properties that you can read in any length string? There must be a crash happening in that function that does the reading that causes it to just bail out and return an empty string.

RTS.txt

Link to comment
Share on other sites

Its not the length that is the issue - its the format of how you are saving the data into the file. The multiple equal signs are screwing it up.

Typically properties are saved as;

Property=Value

and you are doing this:

profile1=[data] = { [1] = { [1] = 0, [2] = 0, [3] = 0, [4] = 1, ...etc

for one property.

I just took your text file and removed the '[data]' and all the superfluous equal signs resulting in a 411kb file and GetProperty works just fine when I use this code:

---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, "profile1")

for k,v in pairs(OneKey) do

System:Print(k.." = "..v)

end

 

You just need to figure out a better way to write your multi-dimensional array with SetProperty. Might be easier to just set one property per array but name the property as the dimension.

  • Upvote 2

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

Ah, ok. I'll make a couple changes. I just figured each property is on it's own line and that Josh would be looking for the first equal sign only to determine the difference between key and value and everything after that is just considered part of the value string.

Link to comment
Share on other sites

If you have your heart set on one property key, there are cleaner and quicker ways to write what you are doing. Just write all the points as being separated by only a comma. The first 200 values are for dimension 1, the next 200 values are dimension 2, etc... You are setting the property to make it easier for you to read in the cfg file and it isn't really required for this. This will make the write smaller and then when you get the property value, you just have convert the blocks of 200 into dimensions of your multi-dimensional array.

  • Upvote 1

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

I'm writing it so it's less code on my side actually (code that I had to write anyway) smile.png The following works:

 

-- for saving (instead of = I use ~)
local mapSave = serializeTable(map, "map", true)
System:SetProperty("profile1", mapSave)

 

 

-- for loading
local r = System:GetProperty("profile1")
r = string.gsub(r, "~", "=")
loadstring(r)()

 

The 'map' table now has my data which is the variable used in my game.

 

 

I'll relook at this later. For now it's good enough to keep me moving with the game. Thanks a lot Mack for the investigation. Always an amazing help you are!

  • Upvote 2
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...