Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Hello. I'm trying to write a custom property set to file. I'm able to do it with individual properties without a problem, but I can't seem to save a set.
I've tried both this (where cHighScores is a set containing custom properties storing the high score for each individual level in the game) ...
put the customProperties["cHighScores"] of this stack into URL ("file:highscores.txt")
Is writing a set to file possible?
Many thanks in advance,
Jamie
Jamie Smith Composer, web dev, LiveCoder www.donbrae.co.uk - Donbrae Studios: Music for games, film, TV, web jamieonkeys.tumblr.com - My game development blog
// Get high scores custom property as an array
put the customProperties["cHighScores"] of the current stack into tHighScores
// Cycle through the array and format for saving to file
repeat for each line tKey in the keys of tHighScores
put tKey & ":" & tHighScores[tKey] & return after tArrayContents
end repeat
put tArrayContents into URL ("file:highscores.txt") // Save to file
Example of text file:
level1:5
level2:20
level3:40
level4:100
level5:20
And to read it from the file and put it into the custom property:
if there is a file "highscores.txt" then
put URL ("file:highscores.txt") into tHighScores // Get text file
split tHighScores by return and ":" // Split into array
set the customProperties["cHighScores"] of this stack to tHighScores // Set the array to value of cHighScores custom property
end if
Last edited by donbrae on Sun Sep 15, 2013 1:10 am, edited 1 time in total.
Jamie Smith Composer, web dev, LiveCoder www.donbrae.co.uk - Donbrae Studios: Music for games, film, TV, web jamieonkeys.tumblr.com - My game development blog
FourthWorld wrote:If you use a separate stack file for your custom props you can just save it.
Thanks, Richard. Sounds like an excellent approach - will read up on it.
Jamie Smith Composer, web dev, LiveCoder www.donbrae.co.uk - Donbrae Studios: Music for games, film, TV, web jamieonkeys.tumblr.com - My game development blog
If the values aren't specific to objects, another option is arrayEncode and arrayDecode, so you could use a global array variable rather than custom properties for those values.
Richard Gaskin LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Jamie Smith Composer, web dev, LiveCoder www.donbrae.co.uk - Donbrae Studios: Music for games, film, TV, web jamieonkeys.tumblr.com - My game development blog
You can use Writing Custom properties file to indicate what actions the project system should perform on the files. For example, you can set file properties to indicate whether a file should be compiled or embedded into the build output as a resource.