Page 1 of 1
Detecting an open card
Posted: Tue Feb 19, 2013 12:14 am
by KennyR
How might one go about detecting if a card has been visited/opened for the first time?
Re: Detecting an open card
Posted: Tue Feb 19, 2013 12:25 am
by Simon
Hi Kenny,
This does not included between sessions right?
Here is where you use and set a custom property.
Just make sure that you have a method of clearing all the setting before you save the stack.
or...
on preOpenStack
repeat with tNum = 1 to the number of cds of this stack
put 0 into cVisit of cd tNum
....
Simon
Re: Detecting an open card
Posted: Tue Feb 19, 2013 12:27 am
by dunbarx
Hi.
Several messages are sent when a card is opened, but nothing special when it is opened the first time. This means that you have to remember this explicitly. The best way, I think, is to set a custom property. Do you know about these?
Try this in an openCard handler in the stack script:
Code: Select all
on opencard
set the firstVisit of this card to "true"
end openCard
"firstVisit" is a custom property that you make up on your own. Just like built-in properties (like the name or the textFont), they are remembered when they are set, and can be read at any time.
So how do you know if a certain card, likely one of many, has been visited? You can check by hand:
Code: Select all
answer the firstVisit of card "yourCard"
Or, you might want to check on that status every time you navigate from card to card. Or perhaps you might suggest a way to query all the cards in your stack and report those that have been opened? Write back if you need more...
Craig Newman
Re: Detecting an open card
Posted: Tue Feb 19, 2013 12:53 am
by KennyR
AAHHH! The lightbulb just went on!! So something like this?
on mouseUp
set the cCustomStack["cVisited"] of this stack to "false"
end mouseUp
on openStack
if the cCustomStack["cVisited"] of this stack if "true" then
do something
else
do something else
end if
end openStack
Re: Detecting an open card
Posted: Tue Feb 19, 2013 1:19 am
by dunbarx
Do you want to set the property of the stack, or of certain cards within that stack? The former would only be useful if the stack contained only one card.
Well, it might, I guess, and then well and good.
Using your mouseUp handler, the user must either click on the card window area, or click on an object on that card, in which case make sure the "mouseUp" message is explicitly passed along the hierarchy. This works, but is constricted, do you see? There ought to be a more fundamental way to set the property, and that belongs in an "openCard" handler in the stack script. Now certainly there may be a reason within the workings of your stack that the issue need only be addressed when the user clicks on something on a card. In that case, well and good. I just wanted to make the distinction. As long as you see how this works, you will rightly choose what works best for you.
But if there is more than one card in the stack, it will not serve to set a stack custom property, since the status of the several cards might well be different, some already visited and some not. Again, your call, as long as you see the difference.
Is this clear? Practice will make it so. And if you do have a one card stack, do you see why it does not matter if you set a card or stack custom property? But in any case please play a little with a multi-card stack, setting and reading individual card properties, as this will be a valuable lesson.
Write back...
Craig Newman
Re: Detecting an open card
Posted: Tue Feb 19, 2013 1:26 am
by Simon
Well mostly...
You want it on the card level
Not sure about this:
cCustomStack["cVisited"]
isn't it "set the cVisited of this stack to false"
and
if the cVisited of this stack = true
Well you are close.
Simon
Re: Detecting an open card
Posted: Tue Feb 19, 2013 1:30 am
by Simon
Oh...
and I still want an answer on your nested if/then if you figured out how to use switch.
Re: Detecting an open card
Posted: Tue Feb 19, 2013 3:32 am
by dunbarx
Hmmm.
First, please tell us if you have a single or multi-card stack. Or both. Too much conceptual wiggle room here.
Second, you cannot use an array variable, or any other kind, when you set a property. This is what Simon alluded to. You PUT values into variables, be they normal or array types, but you SET properties. For example, the script of an object is a property, not a container (variables, like fields, are containers). You will get an error if you try to put something into the script of an object, but will have no problem setting that script to a value. Do you see this? A property contains information, as does a variable, but they act, and are addressed, in entirely different ways. This is a good thing.
Third, if you have only two choices, I would stick to a simple if/then. Not that there is anything wrong with a short switch construction, and I urge you to do it both ways, but keep it simple in the beginning. Switch comes in real handy with larger constructions, however.
Keep at it. Try different stuff. You will get all this soon. Do not hesitate to write back.
Craig Newman
Re: Detecting an open card
Posted: Tue Feb 19, 2013 3:42 am
by sturgis
Code: Select all
set the cCustomStack["cVisited"] of this stack to "false"
This is just setting the value of cVisited in the custom property set cCustomStack right? So it should work if my limited understanding of custom property sets is correct.
At least according to
http://lessons.runrev.com/s/lessons/m/4 ... ropertyset
Re: Detecting an open card
Posted: Tue Feb 19, 2013 4:01 am
by KennyR
hey guys! Just got home from work, so sorry for the delay in writing back...Overall, my stack has a total of 4 cards....What I am trying to do is this....I have 4 cards with scrolling button fields on each card that contain items to be checked off for the state of Illinois DOT ambulance checklist. With the help of Dixie, Simon you and others I have been able to keep track of the states of each button, save them at closeCard, and reload those states at runtime. My problem now is, I want the user to skip the first card in the stack and go straight to the scrollers if the cards that contain the scrollers has been visited previously. This keeps the user from having to enter in information on the first card again since I already stored that information in a variable for later. I have a "reset" button on the scroller cards to reset the variables and states of the buttons so the user can essentially "start over". But lets say the user is doing the checklist and the program unexpectedly gets closed. I wanted them to be able to fire the program back up and continue where they left off...(just like any other program I have ever used on my phone). Getting this accomplished is another thing...I am close and I think it can be accomplished by writing a simple if/else statement since I use a variable to store the states of the buttons that have and have not been clicked. So in summation, I think my problem can be solved like below instead of using a custom property....although, I think that would work too....my brain is a little fried after 14 hours at work and that many coding.....lol. Let me take in what you guys have written and I will get back to you all....
*Simon....I haven't forgotten about you...I am going to take a look at what I did with the nested if/else statement and shoot you a message....
if vAirway,vALS,vWhite,vMisc = 0 then
go to the first card
else go to card "ALS" or some other card.
end if