Page 1 of 1
Writing custom property set to file
Posted: Sat Sep 14, 2013 10:39 pm
by donbrae
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) ...
Code: Select all
put the cHighScores of this stack into URL ("file:highscores.txt")
... and this ...
Code: Select all
put the customProperties["cHighScores"] of this stack into URL ("file:highscores.txt")
Is writing a set to file possible?
Many thanks in advance,
Jamie
Re: Writing custom property set to file
Posted: Sat Sep 14, 2013 11:44 pm
by dunbarx
Hi.
The "customProperties" is an array, and if you try to send it anywhere, it likely will be interpreted as empty. Try(pseudocode)
get yourCustomProperties
combine it with return
put it into URL....
Craig Newman
Re: Writing custom property set to file
Posted: Sun Sep 15, 2013 12:50 am
by donbrae
Many thanks, Craig. That did the trick.
Just in case anyone else finds it useful, this is the code I used:
Code: Select all
// 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:
Code: Select all
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
Re: Writing custom property set to file
Posted: Sun Sep 15, 2013 1:04 am
by FourthWorld
If you use a separate stack file for your custom props you can just save it.
Re: Writing custom property set to file
Posted: Sun Sep 15, 2013 1:09 am
by donbrae
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.
Re: Writing custom property set to file
Posted: Sun Sep 15, 2013 7:15 pm
by jacque
The "combine" command is part of LiveCode, and you could avoid a repeat loop by using it this way:
combine tHighScores by cr and colon
Re: Writing custom property set to file
Posted: Mon Sep 16, 2013 12:03 am
by FourthWorld
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.
Re: Writing custom property set to file
Posted: Tue Sep 17, 2013 9:39 am
by donbrae
Thanks a lot, guys - appreciate the advice.
Re: Writing custom property set to file
Posted: Mon Oct 14, 2013 11:48 am
by JenniferKatie51
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.