Re-calling the same card?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re-calling the same card?

Post by paulsr » Sat Sep 15, 2012 10:28 am

Sorry Folks, I think this might be a long explanation for something which probably has a simple solution...

I have a card called "news" which displays a news article. The specific article is selected from an sqlite database depending on the content of a global variable.

I want to be able to scroll thru the articles in the database by swiping left and right for next and previous.

What I thought I could do was increment/decrement the value in the global variable, and then re-call the same "news" card, with the appropriate push effect.

But nothing happens. I'm guessing the "news" card's openCard handler is not being called because the card is already open.

I have a couple of workarounds but they are not elegant.

I have a "dummy" card which I call with no visual effect, and this then re-calls the "news" card with the left/right push effect. This works, except there is brief flash as the dummy card is displayed, so it doesn't quite look like the correct push effect.

Or, I guess I could have two almost-identical news cards, where news1 calls news2, and news2 calls news1.

But I bet I'm missing something, and there is an elegant way to re-call an open card.

TIA

--paul

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

Re: Re-calling the same card?

Post by jacque » Sat Sep 15, 2012 8:33 pm

try:

lock screen
<load new content here>
unlock screen with visual effect push left <or right>
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Re-calling the same card?

Post by paulsr » Sun Sep 16, 2012 2:57 am

jacque wrote:try:

lock screen
<load new content here>
unlock screen with visual effect push left <or right>
Nope, that didn't help Jacqueline. Absolutely nothing happens when I swipe ... with or without lock screen.

Any other thoughts?

--paul

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

Re: Re-calling the same card?

Post by jacque » Sun Sep 16, 2012 3:27 am

If your content loads only on opencard then you'd need to move that process to its own handler. On opencard, call the handler. Then call the handler again in between lock screen messages when you need to load new content.

Alternately you can just call "opencard" from another handler.

It would be informative to see your scripts.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Re-calling the same card?

Post by paulsr » Sun Sep 16, 2012 4:02 am

jacque wrote:If your content loads only on opencard then you'd need to move that process to its own handler. On opencard, call the handler. Then call the handler again in between lock screen messages when you need to load new content.

Alternately you can just call "opencard" from another handler.

It would be informative to see your scripts.
Thanks Jacqueline. Yes, the content loads on openCard. I thought about moving the code into another handler, but can I get then the visual effect?

There's not much to see in the code. I've tried...

Code: Select all

command goNextArt
   put g_sel_btnnbr + 1 into g_sel_btnnbr
   if g_sel_btnnbr < g_tot_disp then
      go card "dummy_page_n"
        else
      put g_sel_btnnbr - 1 into g_sel_btnnbr
   end if
end goNextArt
...where dummy_page_n re-calls article_page with the push left effect. That works, except, as I mentioned, there is white flash as dummy_page_n loads, so that's not ideal.

If I do...

Code: Select all

command goNextArt
   put g_sel_btnnbr + 1 into g_sel_btnnbr
   if g_sel_btnnbr < g_tot_disp then
      lock screen
      go "article_page"  -- this card is "article_page"
      unlock screen with visual effect push left
   else
      put g_sel_btnnbr - 1 into g_sel_btnnbr
   end if
end goNextArt


... then the swipe gesture does nothing.

But if I try...

Code: Select all

command goNextArt
   put g_sel_btnnbr + 1 into g_sel_btnnbr
   if g_sel_btnnbr < g_tot_disp then
      lock screen
      openCard
      unlock screen with visual effect push left
   else
      put g_sel_btnnbr - 1 into g_sel_btnnbr
   end if
end goNextArt
... I correctly display the next article, but I do not see the visual effect.

So, I'm getting closer, but still not there. Learning more every day...

--paul

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Re-calling the same card?

Post by sturgis » Sun Sep 16, 2012 1:53 pm

Forgive the inline answers:

Code: Select all

command goNextArt
   put g_sel_btnnbr + 1 into g_sel_btnnbr
   if g_sel_btnnbr < g_tot_disp then
      go card "dummy_page_n"
        else
      put g_sel_btnnbr - 1 into g_sel_btnnbr
   end if
end goNextArt
To use the "dummy" method change your code to something like this.

Code: Select all

command goNextArt
   put g_sel_btnnbr + 1 into g_sel_btnnbr
   if g_sel_btnnbr < g_tot_disp then
      lock screen for visual effect -- must specify the for visual effect. In this case its the whole screen so I just use lock screen
      go card "dummy_page_n" -- change to dummy.
      go card "theMainCard" -- change back to your main card and opencard will fire. No code is necessary in dummy. 
      unlock screen with visual effect push left -- do the visual effect
        else
      put g_sel_btnnbr - 1 into g_sel_btnnbr
   end if
end goNextArt



...where dummy_page_n re-calls article_page with the push left effect. That works, except, as I mentioned, there is white flash as dummy_page_n loads, so that's not ideal.
The white flash is because you go to the dummy page which I assume is blank, and do the lock screen from there. (i think)
If you had used the "lock screen for visual effect" form of lock screen from the dummy card with unlock screen with visual effect push left, you would see an empty screen pushing left and ending up showing the other card. Since the visual effect was not working you just see the flash of white then the other card.
If I do...

Code: Select all

command goNextArt
   put g_sel_btnnbr + 1 into g_sel_btnnbr
   if g_sel_btnnbr < g_tot_disp then
      lock screen
      go "article_page"  -- this card is "article_page"
      unlock screen with visual effect push left
   else
      put g_sel_btnnbr - 1 into g_sel_btnnbr
   end if
end goNextArt


... then the swipe gesture does nothing.
As mentioned, the above code doesn't change a) because you don't lock screen for visual effect. And b) because opencard doesn't fire. Changing the lock line to:
lock screen for visual effect

and adding a line:
opencard

should solve that issue.

But if I try...

Code: Select all

command goNextArt
   put g_sel_btnnbr + 1 into g_sel_btnnbr
   if g_sel_btnnbr < g_tot_disp then
      lock screen
      openCard
      unlock screen with visual effect push left
   else
      put g_sel_btnnbr - 1 into g_sel_btnnbr
   end if
end goNextArt
... I correctly display the next article, but I do not see the visual effect.

So, I'm getting closer, but still not there. Learning more every day...

--paul
For this one, see the answer just above. (lock screen for visual effect)

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Re-calling the same card?

Post by paulsr » Mon Sep 17, 2012 4:21 am

most of quote snipped...
sturgis wrote: For this one, see the answer just above. (lock screen for visual effect)
Many thanks ... I learned a lot from your comprehensive answer. The solution I picked is the "lock screen for visual effect" which works just fine.

--paul

Post Reply