Confused by name space

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Confused by name space

Post by Simon Knight » Mon Jun 29, 2020 10:24 am

Hi,
I have some code that is working but that I think should fail :

The following snip is being run from stack "A", it creates a new card in a second stack and adds a field to it. Next it changes some of the field properties. What I don't understand is why I don't seem to have to enter the "of stack "SecondStack" to the references to the field.

Code: Select all

 /* Create a new card in the stack UT_Documentation to hold documentation */
         Create card tNameOfControl in stack "UT_Documentation"
         
         lock screen
         go to card tNameOfControl of stack "UT_Documentation"
         create field "ControlName" in card tNameOfControl
         set the width of field "ControlName" to 350
         set the loc of field "ControlName" to 200,30
         set the textsize of field "ControlName" to 15
         set the textstyle of field "ControlName" to "bold"
         put tNameOfControl into field "ControlName" of card tNameOfControl of stack "UT_Documentation"
I entered these lines forgetting to add the full card and stack references. I suspect the the go to card call has something to do with it but I wonder how robust the code is given that it is run from a second stack. Any thoughts?
best wishes
Skids

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

Re: Confused by name space

Post by Klaus » Mon Jun 29, 2020 10:31 am

Hi Simon,

you "go to cd xyz OF STACK zyx", this way that stack becomes the DEFAULTSTACK and thus no more reference neccessary.


Best

Klaus

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Confused by name space

Post by Simon Knight » Mon Jun 29, 2020 10:41 am

Thanks Klaus,

I thought that might be the case. Its a pity the command does not extend "down" to controls to give us a "with" construct e.g.

Code: Select all

WithControl field "Tom" of card "Dick" of stack "Harry"
	set the textsize to 12
	set the textstyle to "bold"
	etc etc
end WithControl
or perhaps even dot notation.... (now rushes away to wash mouth out)

best wishes

Simon
best wishes
Skids

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

Re: Confused by name space

Post by Klaus » Mon Jun 29, 2020 11:01 am

:D

Yes, like -> the defaultstack, we need something like -> the defaultcard

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Confused by name space

Post by dunbarx » Mon Jun 29, 2020 2:16 pm

I see you both understand that Simon, having navigated to a card on another stack, need not make explicit reference to a stack where he already is on.

Unless it was sort of a joke, what value would "the defaultCard" have? The defaultStack already does it all; it does not matter which card one is on.

Craig

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

Re: Confused by name space

Post by Klaus » Mon Jun 29, 2020 2:23 pm

Hi Craig,

unless we GO to a special card in a stack, like SImon did, we still need to add references to that card!
So setting -> the defaultcard would do nothing but save us from typing:

Code: Select all

...
set the defaultstack to "another one..."
put "sdfasdfasdf" into fld xyz OF CD X
set the thumbpos of sb "a scoller" OF CD X
...
So being able to:

Code: Select all

...
set the defaultcard to card X of stack "another one..."
put "sdfasdfasdf" into fld xyz
set the thumbpos of sb "a scoller"
...
I, personally, would find this a welcome addition, you mileage may vary! :-)
So no, this is no joke, Sir!

Best

Klaus

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

Re: Confused by name space

Post by jacque » Mon Jun 29, 2020 5:05 pm

I've wished for the same thing sometimes. There is the currentCard property, which comes close, but it navigates to the card in the background which isn't always what I want.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Confused by name space

Post by dunbarx » Mon Jun 29, 2020 8:35 pm

@Klaus.

I see, the issue is to create a "global" card reference, similar to the "defaultStack". The benefit is to be able to eliminate explicit references.

I wonder if this would confuse me, having to keep track of the defaultCard when navigating in a running handler. Explicit references at least keep me honest, and that is no mean feat.

@Jacque.

Yes, the currentCard only returns the short name of the, er, current card. To use it, you would have to still explicitly reference the name of the card, and you gain nothing.

Craig

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

Re: Confused by name space

Post by Klaus » Tue Jun 30, 2020 10:30 am

Hi Craig,
dunbarx wrote:
Mon Jun 29, 2020 8:35 pm
@Klaus.

I see, the issue is to create a "global" card reference, similar to the "defaultStack".
The benefit is to be able to eliminate explicit references.
Exactly.
dunbarx wrote:
Mon Jun 29, 2020 8:35 pm
I wonder if this would confuse me, ...
I BET! :D
But don't worry, I doubt LC will ever implement this...


Best

Klaus

Post Reply

Return to “Talking LiveCode”