Page 1 of 2
custom properties
Posted: Fri Feb 15, 2013 3:36 pm
by KennyR
Now, on to the next issue I am having.... lol
I have been expanding my brain and delving into the world of custom properties. I have to say I like it....I have been reading the docs on how to set them up and save content and edit content that will remain between sessions. For the most part, I understand how they work, but I have been having issues with using custom properties to log and save the state of my buttons. What I mean is this... lets say that I have a button that the foregroundColor of the text changes when the button is clicked. I have been trying to save the foregroundColor of that button in the cards custom property set and retrieve and set that button back to the color it was when the stack was closed. So essentially, I want all the buttons that have been clicked and had their colors changed to remain between sessions. this is what I have been trying...
Code: Select all
on closeCard
local vColor
put the foregroundColor of btn id 1100 into vColor
set the cChange[cColor] of this card to vColor
end closeCard
on preOpenCard
set the foregroundColor of btn id 1100 to cChange[cColor]
end preOpenCard
It seems like when I do this, I can see the property contents record the color as "#FF0000" or something else, but setting the button back to its previous state does not seem to take effect when the card is opened. Sometimes I even get some gibberish like 255,255,255,0 that populates the property contents. Is there a better way to accomplish what I am trying to do here?
Re: custom properties
Posted: Fri Feb 15, 2013 4:00 pm
by Klaus
Hi Kenny,
you are mixing a local var and a custom property here!
Local var:
Code: Select all
## Local vars need to be declraed OUSIDE of any handler!
local vColor
on closeCard
put the foregroundColor of btn id 1100 into vColor
end closeCard
on preOpenCard
set the foregroundColor of btn id 1100 to cCvColor
end preOpenCard
Or a custom property set:
Code: Select all
on closeCard
put the foregroundColor of btn id 1100 into vColor
## NAMES of keys should go in QUOTES!
set the cChange["cColor"] of this card to vColor
end closeCard
on preOpenCard
## Dont forget the identifier "of this card"
set the foregroundColor of btn id 1100 to THE cChange["cColor"] OF THIS CD
## ... to cChange["cColor"] -> results in an empty variable = 0 = BLACK = 0,0,0 :-)
end preOpenCard
Best
Klaus
Re: custom properties
Posted: Fri Feb 15, 2013 4:02 pm
by KennyR
Thank you Klaus!! Your the best...
you know, in the example down at the bottom of the page where they detail how to save the custom property, there is no mention of putting quotes around the property set... maybe I just misunderstood the lesson...
http://lessons.runrev.com/s/lessons/m/4 ... is-changed
Re: custom properties
Posted: Fri Feb 15, 2013 4:22 pm
by Klaus
Hi Kenny,
glad I could help
In the example they use a variable for the key name:
...
put "cColor" into TheVarWithTheKeyName
set the cChange[TheVarWithTheKeyName] of this card to vColor
## this will work without quotes, they would be completely wrong here

...
Best
Klaus
Re: custom properties
Posted: Fri Feb 15, 2013 5:18 pm
by KennyR
Klaus,
I have noticed that the code works perfectly in the IDE but when I attempt to run this in the simulator the button that is being restored to the saved custom prop turns the text black, but not in the IDE...what the heck!?
Re: custom properties
Posted: Fri Feb 15, 2013 5:52 pm
by Klaus
Hi Kenny,
sorry, I do not develop for mobile, so I cannot test this.
But it SHOULD work, so it may be a bug.
EDIT & Idea

Since the "foregroundcolor" might not yet have been set for this button, maybe it inherits this from the card or stack,
so you should use:
...
put the EFFECTIVE foregroundcolor of btn X into Y
...
Check "effective" in the docs for more info.
Best
Klaus
Re: custom properties
Posted: Fri Feb 15, 2013 6:13 pm
by KennyR
thanks for the brainstorming....I am reading as we speak....
Re: custom properties
Posted: Fri Feb 15, 2013 7:21 pm
by KennyR
I tried to use the "Effective" qualifier but that does not work....For some reason, the custom properties are not being retained when I close the simulator and start it back up. What does work though is when I use a button to save the custom prop to the card, navigate away to another card ,go back to the card and use another button to load the custom prop. "WHEW"! I just wonder if the simulator removes the custom properties after you close it....that's the only thing I can come up with....
*UPDATE* Well I took the exact lesson and recreated it. I ran it on the simulator and found that the custom properties that are saved when the simulator runs are NOT retained when you close the simulator and open it agin....this might be common knowledge to most, but not for me.....hope this helps someone...
Re: custom properties
Posted: Fri Feb 15, 2013 10:55 pm
by Simon
Hi Kenny,
You cannot save to a standalone.
You will have to write the status out to a file and read it back in at start up. Don't worry it's easy, just a little text file.
As for how people do save to a standalone look up Splash stacks. It a stack that opens a LC file that you can save to.
Simon
Re: custom properties
Posted: Sat Feb 16, 2013 12:33 pm
by Klaus
Hi Kenny,
sorry, looks like I missed the "between sessions..." part.
Yes, Simon is correct, standalones cannot save themselvers!
You need to save all neccessary info to the users disk when the stack closes and read it in again
when the app starts the next time.
Check this thread to get the basic idea:
http://forums.runrev.com/phpBB2/viewtop ... references
Best
Klaus
Re: custom properties
Posted: Sat Feb 16, 2013 10:12 pm
by KennyR
hey guys...thanks for the input...
I read the posts from the link you provided and have a couple of questions....(btw, I'll be reading some more in the meantime to further my knowledge)
1) I am using buttons from mobGUI so the buttons are grouped. If I want to store the foregroundColor of each field of each group, I have to refer to them by their id number and the group the field is married to.So if I am reading the foregroundColor that is stored in each line of the saved text, and then setting each buttons grouped field to that color, how can I write a "repeat" statement that reads each line and sets each fields color without referring to each of the fields by id or name? (WOW)
2) is this close to how I need structure my code as far as retrieving it?
Code: Select all
local tCurrentData
on preOpenCard
repeat with x=1 to the number of buttons on this card---This is not right either...
end repeat
set the default foler to specialFolderPath("documents")
put url "file:myData.txt" into tCurrentData
repeat for each line tLine in tCurrentData
set the foregroundColor of btn id 1006, btn id 1010, btn id 1014 to tLine --This is not right, but I cannot seem to think of a way to do this....
end repeat
end preOpenCard
Re: custom properties
Posted: Sat Feb 16, 2013 10:38 pm
by KennyR
after thinking about this for a minute or two, I think my last post is confusing and probably idiotic to some....but I will leave it in the case that it could be done. But I think maybe the answer for me is to write something like this....
Code: Select all
local vColor
on preOpenCard
set the defaultFolder to specialFolerPath("documents")
put URL ("file:myFile.txt") into vColor
set the foregroundColor of fld id 1006 group id 1003 to line 1 of vColor
set the foregroundColor of fld id 1010 group id 1007 to line 2 of vColor
set the foregroundColor of fld id 1014 group id 1011 to line 3 of vColor
end preOpenCard
on CloseCard
set the defaultFolder to specialFolerPath("documents")
put the foregroundColor of fld id 1006 group id 1003 into line 1 of URL ("file:myFile.txt")
put the foregroundColor of fld id 1010 group id 1007 into line 2 of URL ("file:myFile.txt")
put the foregroundColor of fld id 1014 group id 1011 into line 3 of URL ("file:myFile.txt")
end CloseCar
am I getting closer??
Re: custom properties
Posted: Sat Feb 16, 2013 11:21 pm
by KennyR
okay I think I have it...this seems to work well for me....The only thing is I had to put the "if/else" statement in there because if the file was empty on the preOpenCard handler, it changed all my buttons foregroundColor to the inherited color of the card.....this is what I finally came up with if anyone is interested.
Code: Select all
on preOpenCard
set the defaultFolder to specialFolderPath("documents")
#If statement to check if the myFile.txt file is empty first
if URL ("file:myFile.txt") is empty
then
else
set the foregroundColor of fld id 1006 group id 1003 to line 1 of URL ("file:myFile.txt")
set the foregroundColor of fld id 1010 group id 1007 to line 2 of URL ("file:myFile.txt")
set the foregroundColor of fld id 1014 group id 1011 to line 3 of URL ("file:myFile.txt")
end if
end preOpenCard
on CloseCard
set the defaultFolder to specialFolderPath("documents")
put the foregroundColor of fld id 1006 group id 1003 into line 1 of URL ("file:myFile.txt")
put the foregroundColor of fld id 1010 group id 1007 into line 2 of URL ("file:myFile.txt")
put the foregroundColor of fld id 1014 group id 1011 into line 3 of URL ("file:myFile.txt")
end CloseCard
Re: custom properties
Posted: Sun Feb 17, 2013 12:38 am
by Simon
How about:
Code: Select all
on openCard
put 0 into tNum
set the defaultFolder to specialFolderPath("documents")
put url("file:myFile.txt") into tFile
if tFile = "" then exit openCard
repeat for each line tLine in tFile
add 1 to tNum
set the foregroundColor of fld tNum to tLine
end repeat
end openCard
on closeCard
set the defaultFolder to specialFolderPath("documents")
repeat N = 1 to the number of fields of this cd
put the foregroundColor of fld N into line N of tFile
end repeat
put tFile into url ("file:myFile.txt")
end closeCard
This way you don't have to define fld and grp ID's which would be handy if you have lots of fields.
One crazy thing here is that you don't really care about what myFile.txt looks like so the order that the information is stored doesn't matter, only how it is read back in.
Simon
Re: custom properties
Posted: Sun Feb 17, 2013 1:23 am
by KennyR
Thanks Simon but I have a question about this...
Code: Select all
on closeCard
set the defaultFolder to specialFolderPath("documents")
repeat N = 1 to the number of fields of this cd
put the foregroundColor of fld N into line N of tFile
end repeat
put tFile into url ("file:myFile.txt")
end closeCard
what exactly does the "N" represent? I apologize in advance, but when it comes to this I am still much of a rookie...When I implement the code in my handler of the card, It says no such object referring to "N". I assume this needs to be something, but I am not sure what....sorry again for being ignorant.