on openCard, is there a bug?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Joop Sleijster
Posts: 46
Joined: Mon Aug 26, 2013 6:49 pm

on openCard, is there a bug?

Post by Joop Sleijster » Thu Nov 04, 2021 4:27 pm

Hello,

I have a Stack with 3 Cards.
Card 1 with a Button “Go Next” + script
Card 2 with a Button “Go First” + script
Card 3 with a Button “Go First” + script

Card 2 with Card script:
On openCard
go next
End openCard

This Card 2 script is always executed when the card is opened, both in Run mode and Edit mode.
It should not in Edit mode, isn’t it?

The only way to open card 2 is to double click on Script lines in the Project Browser so the code window of card 2 opens and then comment out the script.

I use LC 9.6.4 Indy

Is this a bug?

thanks
Joop

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

Re: on openCard, is there a bug?

Post by Klaus » Thu Nov 04, 2021 4:44 pm

Dag Joop,

I don't think this is a bug, but a feature! I recently had to learn this for "mouseenter"
which is also sent with the pointer tool!

The message "opencard" is being triggered and sent and that is desired behavior.

I once created a small palette for e.g. to navigate through my stack(s).
I used this script for the "Next" button:

Code: Select all

on mouseup
  if the ALTkey = "down" then
    lock messages
  end if
  go next cd
end mouseup
So you could just use the message box:

Code: Select all

lock messages;go cd 2
Groetjes

Klaus

xAction
Posts: 86
Joined: Sun Oct 03, 2021 4:14 am

Re: on openCard, is there a bug?

Post by xAction » Thu Nov 04, 2021 10:07 pm

Trap the currentCard like so

You fill in the actual name between <>

Code: Select all

on openCard
if the currentCard of this stack is not <"the short name of the target card"> then exit openCard
end openCard
Using the number of the currentCard instead of short name of 'currentCard'

Code: Select all

on openCard
if the number of the currentCard of this stack is not 2 then exit openCard
end openCard
OpenStack, openCard, resizeStack...get sent to everything all at once. I've had so many nightmares with that. But exiting at the top of the handler if the message is not intended for that object seems to be the workable solution.

I'm not sure if using 'private' will control who gets the message and who doesn't
Let's test
uh, I don't know what 'private' is doing.

Code: Select all

 private on openCard
put the number of the currentCard of this stack into  fld 1
end openCard
doesn't do anything at all card after card
sending openCard through the message box does what is intended.

stam
Posts: 2683
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: on openCard, is there a bug?

Post by stam » Fri Nov 05, 2021 9:51 am

Joop Sleijster wrote:
Thu Nov 04, 2021 4:27 pm
It should not in Edit mode, isn’t it?
I think that is intended as it not a bug.
If you want to be able to navigate in edit mode without triggering the 'go next' statement, then you can add a conditional:

Code: Select all

on openCard
  if the tool is "browse tool" then go next
end openCard
This will then only run when you're running the app.
S.

--- edited to correct the typo of the forgotten 'if' ;) (thanks Jacque!)
Last edited by stam on Fri Nov 05, 2021 8:10 pm, edited 1 time in total.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: on openCard, is there a bug?

Post by jacque » Fri Nov 05, 2021 6:26 pm

Stam's solution is what I do, though the second line is missing the "if". It's a typo.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Joop Sleijster
Posts: 46
Joined: Mon Aug 26, 2013 6:49 pm

Re: on openCard, is there a bug?

Post by Joop Sleijster » Sat Nov 06, 2021 9:33 pm

Hi,
Thank you all for your responses.
It's completely clear to me.
However, I still don't understand the purpose of the “open card” message in Edit mode.
If you go to the card to edit the card in edit mode, that's not very handy in my opinion.
But your responses helped me a lot.
thanks,
joop

p.s.
Dag Klaus
The salutation and conclusion of your response was perfectly Dutch.
Groetjes,
j.

stam
Posts: 2683
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: on openCard, is there a bug?

Post by stam » Sat Nov 06, 2021 11:01 pm

Joop Sleijster wrote:
Sat Nov 06, 2021 9:33 pm
However, I still don't understand the purpose of the “open card” message in Edit mode.
openCard and preOpenCard are often used for initialisation of layout and data when entering a card. In these cases, it's good that it works in edit mode, otherwise you'd have to enter browse mode, navigate to the card (or run pre/openCard from the msg box) and then enter edit mode - tedious.

For example i have a stack where a styled field top left informs the user which section (card) they're on. I've named the cards to reflect this name and have a background group containing this field, so it exists on all new cards i create. I just set the text of the field to be the short name of the card when navigating to said card and it's all automatic even in edit mode, which is useful...

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

Re: on openCard, is there a bug?

Post by Klaus » Sun Nov 07, 2021 4:11 pm

Dag Joop.
Joop Sleijster wrote:
Sat Nov 06, 2021 9:33 pm
...
p.s.
Dag Klaus
The salutation and conclusion of your response was perfectly Dutch.
Groetjes,
j.
Dat weet ik heel goed, ik spreek een beetje nederlands. :-)
Tot ziens!

Post Reply

Return to “Talking LiveCode”