Btn can't find fields, etc on same card/stack

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Btn can't find fields, etc on same card/stack

Post by gyroscope » Mon Oct 12, 2009 3:34 pm

Hi, I've a bit of a frustrating prob which has occurred, and I can't work out why.

I've a main stack with an onOpencard script including:

Code: Select all

lock screen
open stack "PROCESSES A" 
hide stack "PROCESSES A"
unlock screen
send "mouseUp" to btn "startupmain" on stack "PROCESSES A"
All well and good, it reaches and activates the button, as always.

Script in button "startupmain" including:

Code: Select all

repeat with gClap=1 to 48
      put empty into field ("w"&gClap)
      set the backgroundColor of field ("w"&gClap) to white      
   end repeat
There's an error thrown here: it can't find field "w1" etc., all of a sudden (there wasn't a problem before).

The only way around this, of course, is to append "on card 2 of stack "PROCESSES A" to each command. This is a pain as there's a fair bit of code in the button; and I'm a bit miffed that, apart from making the script a bit denser and more difficult to read, I shouldn't have to do this.

I hasten to add that if btn "startupmain" is clicked directly, everything is executed fine.

So does anyone know please, why that when the mouseUp is sent to the button from the main stack, and the button executes, it can't find the fields/buttons, etc on it's shared card/stack? (suddenly...) Any help appreciated here as this has been driving me a bit bonkers to solve...

:(

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

Post by Klaus » Mon Oct 12, 2009 4:02 pm

Hi gyroscope,

if Rev loses "connection" this can most of the time be "cured" by setting the "defaultstack" first before the handler begins:

Code: Select all

on mouseup
  set the defaultstack to "PROCESSES A" 
  ## or whereever the "missing" fields are located...
   repeat with ...
   ...
end mouseup
Best

Klaus

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Mon Oct 12, 2009 6:10 pm

Hi Klaus

Thank you for your help. Unfortunately it doesn't work in my situation (although reading "defaultStack" in the Dictionary I see that it should).

I've tried a few more things to no avail. I guess I've really tangled it up somehow. I'm going to start from scratch, copying all relevant stuff across to a fresh set of stacks; it'll take a while but I think it's worth it, especially as I'll be using a lot of send mouseUps throughout.

:)

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post by chris9610 » Mon Oct 12, 2009 9:08 pm

gyroscope:

Code: Select all

repeat with gClap=1 to 48
      put empty into field ("w"&gClap)
      set the backgroundColor of field ("w"&gClap) to white     
   end repeat
You are sending to mouseup so the script should be:

Code: Select all

on mouseup
repeat with gClap=1 to 48
      put empty into field ("w"&gClap)
      set the backgroundColor of field ("w"&gClap) to white     
   end repeat
end mouseup
Best guess here .
Developing with Windows XP & Revolution 4.5

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Oct 12, 2009 9:25 pm

Dear gyroscope,

My guess is that the current card of stack PROCESSES A is card 1 rather than card 2. Running scripts expect objects to be on the current card, if the card or stack isn't made explicit. Setting the defaultstack won't solve this. You have to go invisible to card 2 of stack PROCESSES A to solve the problem.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Mon Oct 12, 2009 9:44 pm

Hi Chris,

the code is in a mouseUp handler, I took it as read that that was the case, but thanks for the info!

Hi Mark

Spot on, that's the one, thank you very much. That has solved hours of head-scratching and experiments!

:) :)

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post by chris9610 » Mon Oct 12, 2009 10:46 pm

I guess I misunderstood the issue.

But here are my thoughts.

Cards and fields, buttons and other objects can be copied and names can be identical on different cards so it is up to you to address the proper object with which you want to work with at any instance.

With mighty powers comes mighty responsibility. I think the advantages out weight the dis-advantages. Based on my experience which is minor compared with others.

Can you imagine always having unique names for every field or button in a large application?

I hope this helps.
Developing with Windows XP & Revolution 4.5

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Tue Oct 13, 2009 2:03 pm

Hi Chris
Cards and fields, buttons and other objects can be copied and names can be identical on different cards so it is up to you to address the proper object with which you want to work with at any instance.
I'm aware of the good principal to name things differently, thanks for reminding me.

My prob concerned sending mouseUps to buttons on other stacks, which Mark gave the solution to. It was "half-a-d'oh" moment for me!

Best regards

:)

Post Reply