Screen shot 2013-10-16 at 17.08.36.png
Somewhat terribly confused here, while I fully understand both the concept and the scripts themselves I fail to see why he has two separate scripts in two separate tabs with two completely different names. What I mean is this, the tab labelled " 'card prevNextButtons' " is written at the Stack level - I checked. But I can not find where tab labelled 'card commands' is written (by the way this whole thing is a group); anyway, I don't understand why he could not have written the script for 'prev' and 'next' within the same tab, same page so to speak. When you open the two scripts by pressing on the "open script of first card" you get the tab - "prevnextButtons" tab; when you open the last card button you get the "cardCommands" tab. Why?Previous next buttons
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, asayd
Previous next buttons
Somewhat terribly confused here, while I fully understand both the concept and the scripts themselves I fail to see why he has two separate scripts in two separate tabs with two completely different names. What I mean is this, the tab labelled " 'card prevNextButtons' " is written at the Stack level - I checked. But I can not find where tab labelled 'card commands' is written (by the way this whole thing is a group); anyway, I don't understand why he could not have written the script for 'prev' and 'next' within the same tab, same page so to speak. When you open the two scripts by pressing on the "open script of first card" you get the tab - "prevnextButtons" tab; when you open the last card button you get the "cardCommands" tab. Why?
Re: Previous next buttons
Hi,
There are two cards in this stack. Both cards have a script. There is no relevant script at stack level, unless a script in one of the two cards calls a script at stack level, but I don't think this is a the case. Therefore, I don't think that your observation is correct. Something must have confused you
The first card handles the next button. The second card handles the Prev button. (Apparently, the first card is called "Commands" and the second card is called "PrvNextButtons" but they could have any name you like). Therefore, you need two different sets of scripts and it makes sense to write these scripts at card level rather than stack level.
The two navigation buttons, and possibly all other controls too, are in a group because you need them on both cards. It is obvious.
The script of cd 1:
The script of cd 2:
The first card enables and disables the "Next" button. The second card enables and disables the "Prev" button. This makes sense.
If you have mutliple cards, it doesn't make sense to write these scripts at card level, because you don't want to have a script in every card if you can avoid it. The following script, written at stack level, is a much better alternative:
This last example is better, because you don't need to make sure that the first card always stays the first card and the last card always stays the last card. You can shuffle the cards at will and the script will still work correctly.
Kind regards,
Mark
There are two cards in this stack. Both cards have a script. There is no relevant script at stack level, unless a script in one of the two cards calls a script at stack level, but I don't think this is a the case. Therefore, I don't think that your observation is correct. Something must have confused you
The first card handles the next button. The second card handles the Prev button. (Apparently, the first card is called "Commands" and the second card is called "PrvNextButtons" but they could have any name you like). Therefore, you need two different sets of scripts and it makes sense to write these scripts at card level rather than stack level.
The two navigation buttons, and possibly all other controls too, are in a group because you need them on both cards. It is obvious.
The script of cd 1:
Code: Select all
on openCard
enable btn "Next"
end openCard
on closeCard
disable btn "Next"
end closeCard
Code: Select all
on openCard
enable btn "Prev"
end openCard
on closeCard
disable btn "Prev"
end closeCard
The first card enables and disables the "Next" button. The second card enables and disables the "Prev" button. This makes sense.
If you have mutliple cards, it doesn't make sense to write these scripts at card level, because you don't want to have a script in every card if you can avoid it. The following script, written at stack level, is a much better alternative:
Code: Select all
on preOpenCard
if the number of this cd is 1 then
disable btn "Prev"
enable btn "Next"
else if the number of this cd is the number of cards then
enable btn "Prev"
disable btn "Next"
else
enable btn "Prev"
disable btn "Next"
end if
end preOpenCard
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Previous next buttons
Hi Mark, I have just come here out of curiosity and noticed with delight that you answered these questions. Actually that is great about writing one script at stack level. Thanks.
Re: Previous next buttons
You're welcome
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Previous next buttons
Hi guys,
what about this cool (but maybe a tad mentally challenging) solution using BOOLEan values?
Monsieur Boole can avoid a lot of unneccessary IF...THEN clauses!
OK, after you have digested this, you will see the benefits of using
BOOLEan values in situations like these.
I put the values into variables first, but we could skip this step and simply write:
Et voila, a clean 2 liner!
Have fun
Best
Klaus
what about this cool (but maybe a tad mentally challenging) solution using BOOLEan values?
Monsieur Boole can avoid a lot of unneccessary IF...THEN clauses!
Code: Select all
on preOpenCard
put (the num of this cd = 1) into isFirstCD
## TRUE if we are on the first card, otherwise FALSE!
put (the num of this cd = the num of cds) into isLastCD
## TRUE if we are on the last card, otherwise FALSE!
## Now simply use these values in a clever way. Hey, in programming its all about logics :-)
set the DISABLED of btn "Prev" isFirstCD
set the DISABLED of btn "Next" isLastCD
end preOpenCard
BOOLEan values in situations like these.
I put the values into variables first, but we could skip this step and simply write:
Code: Select all
...
set the DISABLED of btn "Prev" to (the num of this cd = 1)
set the DISABLED of btn "Next" to (the num of this cd = the num of cds)
...
Have fun
Best
Klaus