Code Organization

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
JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

Code Organization

Post by JackieBlue1970 » Thu Jan 16, 2020 10:31 pm

Hi. I'm new to LiveCode but have coded off and on for years in VB (classic and .net), C, Python, and various scripting languages. However, I'm very confused on how you organize your code in LiveCode. Are there no modules or classes? Any way to separate code from user interface? I'd prefer to have my code in separate modules as it makes it easier to share code (such as database access) between projects. The examples I've found so far seem to put everything into a card. Cards appear to me to be just for interface. I know you could put code in the card but often the same code will need to be referenced from other cards. How is this resolved? TIA.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Code Organization

Post by jmburnod » Thu Jan 16, 2020 10:59 pm

Hi,
I know you could put code in the card but often the same code will need to be referenced from other cards. How is this resolved?
You may put scripts on stack script too.
This link should be useful
http://lessons.livecode.com/m/4603/l/56 ... ssage-path
Best regards
Jean-Marc
Last edited by jmburnod on Fri Jan 17, 2020 7:21 am, edited 1 time in total.
https://alternatic.ch

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Code Organization

Post by bogs » Thu Jan 16, 2020 11:11 pm

I think what JackieBlue1970 is looking for would be more akin to a library, or script only stack. Either would work for separating code from the objects in the working stack for re-usability.

You might also want to look into behaviors, although from my understanding of your question, the first two suggestions would be more likely (i.e., the most like modules).
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Code Organization

Post by FourthWorld » Fri Jan 17, 2020 12:17 am

The LiveCode IDE itself is a good example of that sort of code style. Scripts are often factored from UI as behaviors, and nearly everything is plain text files so it can all be worked on via GitHub.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Code Organization

Post by dunbarx » Fri Jan 17, 2020 1:14 am

Hi.

Welcome to LiveCode.

The whole point is that everything is integrated. You work directly within the IDE, and manage controls, layout and code all at once. It takes a bit of getting used to, but is far easier and faster to learn than any of the other languages you mentioned.

Try a simple task, like a calculator or address book. Use this forum often. Once you get going, you will see how it all works, and then you can determine whether LC is for you.

Craig

JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

Re: Code Organization

Post by JackieBlue1970 » Fri Jan 17, 2020 5:01 pm

Thanks for your responses everyone. I'll take a look at the suggestions.

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

Re: Code Organization

Post by Klaus » Fri Jan 17, 2020 5:05 pm

Hi Jackie,

you can also put all of your ahndlers/functions into the stack script of your mainstack.
This way all objects on all cards of the stack and its substacks can access them, because they are in the "message path".

Here a very good read about "message hierarchy":
http://www.fourthworld.com/embassy/arti ... _path.html


Best

Klaus

JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

Re: Code Organization

Post by JackieBlue1970 » Fri Jan 17, 2020 7:36 pm

Ok. I think I understand the concept now. The terminology is very strange for someone that has programmed for years. Correct me if I am wrong:

Stack is a group of related cards. A stack can be an application or an application can consist of multiple stacks. Cards are windows within that application. You can put functions & handlers(I think of them of subroutines) in the top card and can be referenced within in the stack. If you want more than one stack in that application to reference the functions, it would be better to create a "script-only" stack that can be referenced from all the stacks in the application. I'm pretty fuzzy on scope and the lack of typed variables. TIA again for your comments. Jack

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

Re: Code Organization

Post by Klaus » Fri Jan 17, 2020 8:04 pm

Hi Jack,
JackieBlue1970 wrote:
Fri Jan 17, 2020 7:36 pm
Ok. I think I understand the concept now. The terminology is very strange for someone that has programmed for years.
yes, it surely is! :D
JackieBlue1970 wrote:
Fri Jan 17, 2020 7:36 pm
Stack is a group of related cards.
A stack can be an application or an application can consist of multiple stacks.
Cards are windows within that application.
Yes to all. And we can only display ONE card of a stack at a time.
JackieBlue1970 wrote:
Fri Jan 17, 2020 7:36 pm
You can put functions & handlers(I think of them of subroutines) in the top card and can be referenced within in the stack.
NO!
If you put your "subroutines" into the STACK cript of the Mainstack, then all object on all cards of the mainstack and its substacks can access them!

If you put them into the first card, then only objects on that card can access them -> Message hierarchy
JackieBlue1970 wrote:
Fri Jan 17, 2020 7:36 pm
If you want more than one stack in that application to reference the functions, it would be better to create a "script-only" stack that can be referenced from all the stacks in the application.
Not neccessarily, see above.
JackieBlue1970 wrote:
Fri Jan 17, 2020 7:36 pm
I'm pretty fuzzy on scope and the lack of typed variables.
Get used to it! :D


Best

Klaus

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

Re: Code Organization

Post by dunbarx » Fri Jan 17, 2020 9:18 pm

Getting there...
You can put functions & handlers(I think of them of subroutines) in the top card and can be referenced within in the stack.
Klaus is correct, in that the hierarchy strictly controls traffic from one level to another. But know that you can bypass the hierarchy with either the "send' or "dispatch" commands, allowing you to send a message from any level to any other level explicitly.

See this:
message Hierarchy.png
This is the built-in message path. You can subvert it as much as you want, but if you do not, it works rigidly and automatically.

Know also that LiveCode is ALL about messages. You have to understand that first and foremost. All else are details, really.

When you click on a button, several messages are generated, originating from that button. They are then open to be "trapped". They are trapped by you, when you write a handler with the name of one of those messages. "MouseUp" is a very common one, and it is pretty self-explanatory. You can trap it anywhere, though usually this is done in the target button.

Read about the message hierarchy in the User Guide. Start at page 100. There is a more detailed diagram there, and the next handful of pages get right to the heart.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Code Organization

Post by bogs » Fri Jan 17, 2020 9:32 pm

jmburnod wrote:
Thu Jan 16, 2020 10:59 pm
Hi,
I know you could put code in the card but often the same code will need to be referenced from other cards. How is this resolved?
You may put scripts on stack script too.
--------
Best regards
Jean-Marc
Klaus wrote:
Fri Jan 17, 2020 5:05 pm
you can also put all of your ahndlers/functions into the stack script of your mainstack.
This way all objects on all cards of the stack and its substacks can access them, because they are in the "message path".
Hmm, maybe Jean-Marc had it right, and I completely missed the target :D but I still say that the closest translation to .vb modules in Lc would be libraries, or script only stacks, especially if code re-use is the primary goal.
Image

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

Re: Code Organization

Post by dunbarx » Fri Jan 17, 2020 9:43 pm

Bogs.

The OP is a bit away from those ideas. He is not yet even a beginner.

But he sounds like he soon might be.

Craig

JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

Re: Code Organization

Post by JackieBlue1970 » Tue Jan 21, 2020 4:11 am

Thanks everyone. Will be doing some more tomorrow now that I'm back in town. Jack

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”