Code Organization
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 64
- Joined: Thu Jan 16, 2020 10:28 pm
- Location: Max Meadows, VA USA
Code Organization
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.
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Code Organization
Hi,
This link should be useful
http://lessons.livecode.com/m/4603/l/56 ... ssage-path
Best regards
Jean-Marc
You may put scripts on stack script too.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?
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
Re: Code Organization
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).
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).
-
- VIP Livecode Opensource Backer
- Posts: 9823
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Code Organization
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Code Organization
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
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
-
- Posts: 64
- Joined: Thu Jan 16, 2020 10:28 pm
- Location: Max Meadows, VA USA
Re: Code Organization
Thanks for your responses everyone. I'll take a look at the suggestions.
Re: Code Organization
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
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
-
- Posts: 64
- Joined: Thu Jan 16, 2020 10:28 pm
- Location: Max Meadows, VA USA
Re: Code Organization
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
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
Re: Code Organization
Hi Jack,
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
Best
Klaus
yes, it surely is!JackieBlue1970 wrote: ↑Fri Jan 17, 2020 7:36 pmOk. I think I understand the concept now. The terminology is very strange for someone that has programmed for years.
Yes to all. And we can only display ONE card of a stack at a time.JackieBlue1970 wrote: ↑Fri Jan 17, 2020 7:36 pmStack 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.
NO!JackieBlue1970 wrote: ↑Fri Jan 17, 2020 7:36 pmYou can put functions & handlers(I think of them of subroutines) in the top card and can be referenced within in the stack.
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
Not neccessarily, see above.JackieBlue1970 wrote: ↑Fri Jan 17, 2020 7:36 pmIf 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.
Get used to it!JackieBlue1970 wrote: ↑Fri Jan 17, 2020 7:36 pmI'm pretty fuzzy on scope and the lack of typed variables.
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Code Organization
Getting there...
See this:
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
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.You can put functions & handlers(I think of them of subroutines) in the top card and can be referenced within in the stack.
See this:
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
Re: Code Organization
Hmm, maybe Jean-Marc had it right, and I completely missed the target 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.
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Code Organization
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
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
-
- Posts: 64
- Joined: Thu Jan 16, 2020 10:28 pm
- Location: Max Meadows, VA USA
Re: Code Organization
Thanks everyone. Will be doing some more tomorrow now that I'm back in town. Jack