[SOLVED]Previous card?

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

Post Reply
anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

[SOLVED]Previous card?

Post by anmldr » Thu Jun 04, 2020 12:34 am

What determines which card is the "previous card" in script? Is it the order of creation of cards that determines the sequence?

I assumed that if I have a button on a card (this card is called "theFirstCard") and it's code is:

Code: Select all

go to card "theSecondCard"
There is a button on "theSecondCard" named "Back". It's script is:

Code: Select all

go to previous card
But, in creating this stack, what if I created the cards in this order:
theFirstCard
theFourthCard
theThirdCard
theSecondCard

My "Back" button on "theSecondCard" is going to "theThirdCard" and not "theFirstCard". So, is it the order of creation (and so the Card ID number) that determines which is the previous and next cards followed in the code?

I was assuming that the previous card was the one that was in the history of the previous card seen by the user and so "previous" changes if two or more cards have buttons that direct it to a given card. Meaning, if I go to "theSecondCard" from "theFirstCard", the "previous" card would be "theFirstCard". And, if I was on "theThirdCard" later in using the app, and a button sends the user to "theSecondCard", then in this instance, the "Back" button on "theSecondCard" would use the app's history and that it would go to the "previous" card that was "theThirdCard".

If it is the order of creation of cards that determines the sequence, then I will need to keep track of the history myself, correct?

Linda
Last edited by anmldr on Sat Jun 20, 2020 4:12 am, edited 1 time in total.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Previous card?

Post by SparkOut » Thu Jun 04, 2020 7:57 am

In the Property Inspector you will see various "identification references" for all objects.
Every object has an ID which is unique in the stack.
There is also a name, which you can set to anything, as you already know.
You may notice altId which is an alternate Id number that is not very much used, I believe it is something to help with legacy and metacard compatibility and avoid colliding IDs. (Not sure, it's not really relevant here anyway.)

Each object also has a number. This goes up increasing as you create new objects of that type. It has a correlation with "layer" in that respect, so the order that you create objects will set the default number and layer. The lowest layered it of that type will have the lowest number. So on a card, you place a field, which will be in layer 1 and field number 1 (id say 1010). Then you place a button which will be in layer two, and become button number 1 (id 1011). Then you place another field, which is layer 3 (above the button) and field number 2 (id 1012).
The layer is a setable property (and correspondingly, the number) so you can set the layer of field id 1012 to bottom. This means it is now the lowest layered field in layer 1, so it is field number 1. Field id 1010 has now become field 2, in layer 2 because the other field has been shoved in underneath into layer one and pushed it up to layer 2. If you then set the layer of button id 1010 to top, then it is now in layer 3, but is still field number 2, because it is the field second closest to the bottom layer.

You may have guessed that although a card does not have a "layer" in terms of rendering the objects, each card has a number order within the stack. You can change the order by setting the property or you should be able to drag the cards about within the project browser.

anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

Re: Previous card?

Post by anmldr » Thu Jun 04, 2020 8:31 am

Thank you. I will then always be specific about the card name rather than using Previous, Next, etc. That way, I will be less apt to make mistakes in "directing" what is happening.

Linda

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Previous card?

Post by SparkOut » Thu Jun 04, 2020 5:50 pm

If you set the order of the cards and don't change them, there's no reason to avoid using next and previous. Especially as the actual cards are often a bit less volatile than other objects on the cards. It is a question of style and technique and sometimes it suits some people and their application to have a lot of dynamically generated objects and cards. Other times the application structure suits a more static style.
So, while this is to agree that giving an explicit object reference is a "good thing" you need not be afraid of the "simple" references where appropriate. Your application's cards won't jump about by themselves - only if you create on the fly or have a particular user interface that allows it. So use whatever you are comfortable with.

anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

Re: Previous card?

Post by anmldr » Thu Jun 04, 2020 6:53 pm

I guess time and practice will allow me to better choose my preferences then.
Thanks,
Linda

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Previous card?

Post by raugert » Thu Jun 04, 2020 8:36 pm

I’m not absolutely sure but I believe you can just re-order the cards in the Project Manager and they will follow suit.
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Previous card?

Post by dunbarx » Thu Jun 04, 2020 8:46 pm

I believe you can just re-order the cards in the Project Manager and they will follow suit.
Yep, just drag from one position in the list and drop at another.

Craig

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Previous card?

Post by Klaus » Thu Jun 04, 2020 9:00 pm

anmldr wrote:
Thu Jun 04, 2020 12:34 am
What determines which card is the "previous card" in script? Is it the order of creation of cards that determines the sequence?
No, as you already experienced. You can really take "previous card" literally, since it means the card
that you have been on previously before you came to the current (this) card. :D

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Previous card?

Post by SparkOut » Sat Jun 06, 2020 6:00 pm

There's a difference between "go back" and "go previous card"

"Go back" will take you to the card that you were last on before the one you are currently viewing (and back from there will be the one you were on before that, and so on).

"Go previous card" will go back through the cards in "layer" order (as created, or moved in the hierarchy through Project Browser or script)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Previous card?

Post by Klaus » Sat Jun 06, 2020 6:10 pm

You are definitively right!

Sorry, I must have mixed this. :oops:

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Previous card?

Post by mrcoollion » Sun Jun 07, 2020 10:28 am

SparkOut wrote:
Sat Jun 06, 2020 6:00 pm
There's a difference between "go back" and "go previous card"

"Go back" will take you to the card that you were last on before the one you are currently viewing (and back from there will be the one you were on before that, and so on).

"Go previous card" will go back through the cards in "layer" order (as created, or moved in the hierarchy through Project Browser or script)
I learned something here. Thanks SparkOut :D

anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

Re: Previous card?[SOLVED]

Post by anmldr » Sun Jun 07, 2020 5:02 pm

SparkOut wrote:
Sat Jun 06, 2020 6:00 pm
There's a difference between "go back" and "go previous card"

"Go back" will take you to the card that you were last on before the one you are currently viewing (and back from there will be the one you were on before that, and so on).

"Go previous card" will go back through the cards in "layer" order (as created, or moved in the hierarchy through Project Browser or script)
Now THAT is a great tip. Thank you.
Linda

anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

Re: Previous card?

Post by anmldr » Sat Jun 20, 2020 4:11 am

For reference, see related:
recent
recentCards
push
pop
go back

Linda

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”