Sending a handler problems

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
Mistfall
Posts: 23
Joined: Tue Dec 30, 2008 1:26 pm
Contact:

Sending a handler problems

Post by Mistfall » Mon Dec 07, 2009 3:51 am

Hi everybody!

On a card in my mainstack I put a button that sends a handler to another stack. There are (currently) two cards in the substack. If the first card is the one open when the user clicks the button, I want to hide some graphics and a field. I'll be adding more code to deal with any further cards.

I was puzzled because the "if" structure was not being evaluated as "true" even though the correct card was open. The handler was correctly executing the lines following the "end if". My theory is that clicking on the button on the mainstack brings that stack to the front, and therefore the card that receives the handler in the substack is not the "current card" because its stack is not the active stack.

Is there a way to refer to the open card of the stack that receives the handler, when that stack is not the current stack?

Is there a way to keep a substack displayed in front of the mainstack when the user clicks on the mainstack, besides opening the substack as a palette?

If I do set the substack to be a palette, will its top card then be the "current card", or will the top card of the mainstack remain the "current card" when the button on it is clicked?


on quitApp

if the name of the current card is "Mock-up" then
hide field "Welcome"

repeat with x= 11020 to 11040
hide image ID x of group "Opening Animation"
end repeat
end if

show image "Springboard.png"
enable button ID 1053
hide image ID 1060
end quitApp

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

Re: Sending a handler problems

Post by sturgis » Mon Dec 07, 2009 4:59 am

The problem is that current card returns in this format

card "testCard"

So your test fails to match.

instead you need something like this. There are lots of ways to skin this cat but this one works adequately.

Code: Select all

on doStuff
   put the last word of the name of this card into theCard
   replace quote with empty in theCard
   if theCard = "testCard" then
      put theCard && "It worked!"
   end if
end doStuff

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sending a handler problems

Post by bn » Mon Dec 07, 2009 11:38 am

if you use the short name instead of the name of the current card it returns just the name, not card "nameOfCard"

Code: Select all

on doStuff
   put the short name of this card into theCard
   if theCard = "testCard" then
      put theCard && "It worked!"
   end if
end doStuff
the problem with last word is that you can have card names that consist of more than one word.
regards
Bernd

Mistfall
Posts: 23
Joined: Tue Dec 30, 2008 1:26 pm
Contact:

Re: Sending a handler problems

Post by Mistfall » Tue Dec 08, 2009 5:37 am

Thanks for the suggestions! :oops: I realized that my handler needed to say "if the short name of the current card..." rather than " if the name of the current card.." After I changed that, the if evaluated without a problem.

I do need to figure out how to keep the substack on top, though, when the user is clicking on the mainstack. Is making it a palette or the only way to do this?

Post Reply