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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
donbrae
- VIP Livecode Opensource Backer

- Posts: 19
- Joined: Sun Feb 22, 2009 9:49 pm
-
Contact:
Post
by donbrae » Sat Sep 14, 2013 10:39 pm
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
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
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10305
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Sat Sep 14, 2013 11:44 pm
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
-
donbrae
- VIP Livecode Opensource Backer

- Posts: 19
- Joined: Sun Feb 22, 2009 9:49 pm
-
Contact:
Post
by donbrae » Sun Sep 15, 2013 12:50 am
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
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
- VIP Livecode Opensource Backer

- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Sun Sep 15, 2013 1:04 am
If you use a separate stack file for your custom props you can just save it.
-
donbrae
- VIP Livecode Opensource Backer

- Posts: 19
- Joined: Sun Feb 22, 2009 9:49 pm
-
Contact:
Post
by donbrae » Sun Sep 15, 2013 1:09 am
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
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7389
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Sun Sep 15, 2013 7:15 pm
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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Mon Sep 16, 2013 12:03 am
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.
-
donbrae
- VIP Livecode Opensource Backer

- Posts: 19
- Joined: Sun Feb 22, 2009 9:49 pm
-
Contact:
Post
by donbrae » Tue Sep 17, 2013 9:39 am
Thanks a lot, guys - appreciate the advice.
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
-
JenniferKatie51
- Posts: 1
- Joined: Mon Oct 14, 2013 11:20 am
Post
by JenniferKatie51 » Mon Oct 14, 2013 11:48 am
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.