Can a Field Variable be GLOBAL

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
user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Can a Field Variable be GLOBAL

Post by user#606 » Mon May 05, 2008 2:44 pm

I have found it impossible to make a Field "Variablethingy" Global. It will not compile. To get around it I have put the contents into another VariableThingy that is Global in the different cards, then tranferred it back at the destination. This is far from desireable in my application.

I might use the following:-
==========================================
--Card in a stack
On mouseup
Global field "Variablethingy"

--Calculate or evaluate and put the answer into field "Variablethingy"

end Mouseup
==============================================

Another and different card, same stack

On mouseup
Global field "Variablethingy"

--The result carried over into this card which has the actual displayed
Field "Variablethingy"

end Mouseup
++++++++++++++++++++++++++++++++++++++++++


So why does it fail to compile because it is a field?

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

Post by Klaus » Mon May 05, 2008 3:10 pm

Hi user#666,

sorry, no way, only variables can be local or global!
You will have to put your field(s) manually into a global or local variable.


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Mon May 05, 2008 3:57 pm

FileMaker user? I know of no other system that uses fields for globals.

Welcome aboard. Here in Rev, there are four main types of containers:

- local variables
- global variables
- custom properties
- fields

As discrete objects physically represented on screen, fields are best for displaying information. But because of the overhead needed for display, they aren't the most efficient choice for storing or programmatically manipulating information.

For information that doesn't need to be displayed for the user, you can use a global variable.

See the "global" keyword in the Rev Dictionary for details on using global variables.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Mon May 05, 2008 4:19 pm

Thank you Klaus and Fourthworld,

It does not say you cannot have Global fields in the Rev Docs. so what is a chap to think.
A field is still a variable.
Anyway, Thank you for the confirmation I can move on now to the next secret.

You know, so much time is wasted trying to make this sort of thing work before you give up.

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Mon May 05, 2008 7:54 pm

user#606 wrote:Thank you Klaus and Fourthworld,

It does not say you cannot have Global fields in the Rev Docs. so what is a chap to think.
A field is still a variable.
Anyway, Thank you for the confirmation I can move on now to the next secret.

You know, so much time is wasted trying to make this sort of thing work before you give up.
It is global in the sence that you can get/put it from any handler, you just need to specify where the field is if it is in a different stack or card.

Its just not a variable, so you don't declare it anything. its a field.

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Tue May 06, 2008 8:50 am

Thank you Keyless, I am clear on that now.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Tue May 06, 2008 3:25 pm

user#606 wrote:A field is still a variable.
That's an interesting idea, one I've not seen before. May I ask what other programming languages you've learned which may have contributed to this notion?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Tue May 06, 2008 3:45 pm

More to the point, why doesnt Rev make it clear in its documentation. A field IS a variable, it is not a constant or just text holder like a lable.
Well, isnt it?
Anyway, I am satisfied I am wrong, my mistake! I am used to Basic and a case tool called Layout. I know neither had the term Field, but they both had the same "box to put input into" and they were variables.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Tue May 06, 2008 4:09 pm

There's a few ways to work with data in rev, and they're roughly put into these categories (I hope I don't forget any):

variables & constants
stuff that only exists within scripts

fields (note that labels are just fields with lockText set to true)
text entry areas on cards

custom properties
part of any object but not visible anywhere on a card

outside
stuff like text files, databases, ftp, posting to urls etc.

there's of course other places where you can store text, like the name or label of buttons and stacks, but these are not really intended for data handling (although sometimes it's advantageous to be "misuse" them as such).

Every Language of course is different, but in Rev terms, calling a field a variable (or saying that a label is something else then a field) makes no sense whatsoever. Knowing all this is just one of the many steps to fully understand a new programming language.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Tue May 06, 2008 7:38 pm

user#606 wrote:More to the point, why doesnt Rev make it clear in its documentation. A field IS a variable, it is not a constant or just text holder like a lable.
Well, isnt it?
Interesting idea. I'd never thought about it that way, that anything that wasn't fixed was a "variable".

To be variable and to be *a* variable are different things, in any language. It's been a few decades since I worked with BASIC, but as I recall any form of BASIC that supports GUI objects maintains a distinction between objects and variables.
I am used to Basic and a case tool called Layout. I know neither had the term Field, but they both had the same "box to put input into" and they were variables.
I'm not familiar with CASE tools for BASIC, but the concept of variables is so fundamental to all languages that I would be surprised if any BASIC dialect or CASE tool dared to confuse matters by suggesting that any container object that may have editable text was synonymous with a variable per se.

That's not to suggest such a thing may not exist, but simply that it would be so very unusual in the programming world that the language designers would have quite a challenge justifying such a departure in language design.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Nonsanity
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 86
Joined: Thu May 17, 2007 9:15 pm
Contact:

Post by Nonsanity » Tue May 06, 2008 11:55 pm

To hit the subject over the head with an analogy... :)

Because fields have many properties over and above the displayed value, and can have unlimited additional custom properties, a field is more like a forest... And a variable in a script is like a tree.

When the language syntax expects a tree, it probably can't handle a whole forest.

But you can point out a particular tree in a forest for some operations, like "put myVar into the text of fld 1" for example. You can say the same thing with "put myVar into fld 1" in which case the syntax guesses you mean "the text of". (One particular tree out of many in the field... Ooh, really mixing metaphors now!)

The global keyword lets you access a variable from multiple scripts, but you already can access the contents of a field from multiple scripts. The following snippet:

Code: Select all

the text of fld "myField" of card "myCard" of stack "myStack"
...Will let you access the field's contents from ANYWHERE in Revolution. Global indeed. :)
~ Nonsanity
~ Chris Innanen

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10050
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Wed May 07, 2008 4:47 am

Mr. Innanen, that was quite good. When you write a book on Rev I'll buy a copy. Well done.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Wed May 07, 2008 7:11 am

But certainly one would be haunted by a 1000 CSE professors if they were to use a variable as wide as a forest. That would be very poor scope and memory allocation indeed. :)

Post Reply