swipe left, swipe right

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

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

swipe left, swipe right

Post by marksmithhfx » Thu Nov 05, 2020 5:00 pm

I have a 3 card stack with some screen shots on them. I added the swipe code from one of the livecode lessons. Basically there is some start and end code to capture how far you've swiped and in what direction. That all works fine and calls one of two commands "moveForward" or "moveBackward" depending on the direction of the swipe. I named my cards "the first card", "the second card" and "the last card" and modified the move commands to read as follows:

Code: Select all

on moveForward
   if the name of the current card <> "the last card" then
      visual effect push left        
      go next card
   end if
end moveForward

on moveBack
   if the name of the current card <> "the first card" then
      visual effect push right        
      go prev card
   end if
end moveBack
What I was looking for was the following: if you are on the 2nd card you can move forward or backward. If you are on the first card you can only move forward, and if you are on the last card you can only move backward.

But it doesn't work that way. In essence, you can move forward or backward on any card, including the first and last cards which just cycle around. I added some code to show me the name of the card, just to make sure that it was being identified properly, and it was. So how come this swiping action does not "stop" on the first and last cards like I think it should? I am sure there is a simple answer for this. I've just been staring at it too long.

Thanks

ps changing the code to read "if the name of the current card is not "xxxx" then..." had no effect. It continued to behave as before.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: swipe left, swipe right

Post by Klaus » Thu Nov 05, 2020 5:11 pm

Hi Mark,

this is a feature! :D

From the dicitonary for next:
If you are already on the last card, the next card is the first card in the stack.
and previous:
If you are already on the first card, the previous card is the last card in the stack.

Best

Klaus

P.S.
I would probably use the NUMBER instead of the name:

Code: Select all

...
if the num of this cd < the num of cds then
  ## go forward
end if
...
if the num of this cd > 1 then
  ## go back
end if
...

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: swipe left, swipe right

Post by Thierry » Thu Nov 05, 2020 6:46 pm

marksmithhfx wrote:
Thu Nov 05, 2020 5:00 pm
So how come this swiping action does not "stop" on the first and last cards like I think it should?
I am sure there is a simple answer for this. I've just been staring at it too long.
Hi Mark,

I vote for you staring at it too long :wink:


replace

Code: Select all

if the name of the current card ....
with

Code: Select all

if the short name of the current card 
not tested, but you will tell me :)

Kind regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: swipe left, swipe right

Post by marksmithhfx » Thu Nov 05, 2020 8:52 pm

Thierry wrote:
Thu Nov 05, 2020 6:46 pm
marksmithhfx wrote:
Thu Nov 05, 2020 5:00 pm
So how come this swiping action does not "stop" on the first and last cards like I think it should?
I am sure there is a simple answer for this. I've just been staring at it too long.
replace

Code: Select all

if the name of the current card ....
with

Code: Select all

if the short name of the current card 
not tested, but you will tell me :)
Thierry, you win the prize. To be announced later. But riddle me this.

If I say "put the short name of the current card" it responds "the first card". If I say "put the name of the current card" it responds "the first card". If I say "put the short name of the current card = the name of the current card" it responds false.

????

Ok, I'll go have some more sugar pie now. Maybe that will cheer me up :)
But thank you!

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: swipe left, swipe right

Post by Thierry » Fri Nov 06, 2020 8:01 am

marksmithhfx wrote:
Thu Nov 05, 2020 8:52 pm
If I say "put the short name of the current card" it responds "the first card".
If I say "put the name of the current card" it responds "the first card".
????

Good morning Sir,

Here is what I would expect:

Code: Select all

put the short name of the current card  --> "the first card"
put the  name of the current card       --> card "the first card"
or what did I miss?

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

jiml
Posts: 339
Joined: Sat Dec 09, 2006 1:27 am

Re: swipe left, swipe right

Post by jiml » Fri Nov 06, 2020 4:58 pm

Hi Mark,

Code: Select all

go to the first card

Code: Select all

go to the last card
are both acceptable LC commands.

You have named cards "the first card" and "the last card".
And you properly quote the names in your handlers, so it works OK.
But you might consider a different naming scheme to avoid inevitable confusion if you happen to forget the quotes some day.

Jim Lambert

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: swipe left, swipe right

Post by Klaus » Fri Nov 06, 2020 5:12 pm

Why not just use NUMBERs as I wrote above?
No need to mess with (short) card names.

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: swipe left, swipe right

Post by marksmithhfx » Fri Nov 06, 2020 10:08 pm

Klaus wrote:
Fri Nov 06, 2020 5:12 pm
Why not just use NUMBERs as I wrote above?
No need to mess with (short) card names.
Hi Klaus,

It's a very scripted journey. It's just 4 cards (of many) that form a user guide. So it's fine to say "go next" or "go prev" when you are in the set. But when you get to the end there is no logical next card. Likewise when you get back to the beginning, the prev card should be whatever the card was you came from in the first place. The longer card names were just for illustrative purposes. The actual card names are ug1 - ug4 (User Guide 1-4). And as Thierry has helpfully pointed out, "card "ug1"" is not the same as "ug1" and my eyes are just not trained to pickup such subtle differences. ie.

card "ug1" and "ug1" (meaning card "ug1") look the same to me because they have the same meaning. Of course they may serve a subtle and important difference in programming LC that I've just not come across yet. It is a pretty big programming environment.

Finally, last point about this, unless the numbers form a meaningful sequence, I am not going to use numbers any more than I would use numbers to name variables. They have no intrinsic meaning so are very hard to recall. The strategy of calling these cards ug1 - ug4 works for me because I adopted the abbreviation ug to mean User Guide, and then within the UG cards the sequence 1-4 also makes sense (ie. it follows some logical progression that maps back to the program).

But I do appreciate your input Klaus. It's just not always the way I might approach a problem.

Cheers, and thanks all. I see now what my problem was.
Best,
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: swipe left, swipe right

Post by Thierry » Sat Nov 07, 2020 9:05 am

marksmithhfx wrote:
Fri Nov 06, 2020 10:08 pm
Finally, last point about this, unless the numbers form a meaningful sequence, I am not going to use numbers any more than I would use numbers to name variables. They have no intrinsic meaning so are very hard to recall.
Hi Mark,

I'm sharing your thoughts on this too, and avoid numbers as much as I can.

You might like this more generic way testing for first and last cards,
avoiding typos or other kind of mistakes:

Code: Select all

   if (id of current card) is not (id of last card) then ...

   if (id of current card) is not (id of first card) then ...
 

Kind regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: swipe left, swipe right

Post by Klaus » Sat Nov 07, 2020 10:14 am

marksmithhfx wrote:
Fri Nov 06, 2020 10:08 pm
...
Finally, last point about this, unless the numbers form a meaningful sequence, I am not going to use numbers any more than I would use numbers to name variables. They have no intrinsic meaning so are very hard to recall...
Maybe I am not understanding your problem completely, but my example would fit your needs here exactly, not?
No need to know any number:

Code: Select all

...
## the number of the last card = the number of cards in the current stack
if the num of this cd < the num of cds then
  ## go forward
end if
...
## We are NOT on the first card yet:
if the num of this cd > 1 then
  ## go back
end if
...
If not, sorry. :D

EDIT:
Added a little explanation.

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

Re: swipe left, swipe right

Post by SparkOut » Sat Nov 07, 2020 10:18 am

Just to be clear, cards (and other objects) will always have a number, regardless of what they are named. It's very bad practice to use a "number" for an object's name, because this might bear no relation to its position in the stack or card. The project browser will show the cards in their order, and they can be rearranged. If you are not dynamically creating, destroying and moving cards in the usage of the application, then there's no reason not to navigate by number, although like you and Thierry, I mistrust keeping track of number/name/id relationships. Here though, there's nothing to remember, if you have set the cards in order ug1,ug2,ug3,ug4 then the number based navigation will just happen without thinking about it. It's not even number-based navigation, just checking when to wrap from front to back or vice versa.

[edit: Klsusimausi answered while I was phone-typing this. Outklaused again]

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: swipe left, swipe right

Post by jacque » Sat Nov 07, 2020 6:52 pm

Maybe I am not understanding your problem completely, but my example would fit your needs here exactly, not?
He wants to navigate among 4 particular cards only, not through the whole stack. Thierry identified the problem in the original handler.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: swipe left, swipe right

Post by Klaus » Sat Nov 07, 2020 11:02 pm

Ouch, yes, sorry... :oops:

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: swipe left, swipe right

Post by jacque » Sat Nov 07, 2020 11:18 pm

Klaus wrote:
Sat Nov 07, 2020 11:02 pm
Ouch, yes, sorry... :oops:
It's okay, we still love you.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: swipe left, swipe right

Post by marksmithhfx » Sun Nov 08, 2020 11:09 am

jacque wrote:
Sat Nov 07, 2020 11:18 pm
Klaus wrote:
Sat Nov 07, 2020 11:02 pm
Ouch, yes, sorry... :oops:
It's okay, we still love you.
I'll second that 😊
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Post Reply