Simple example of start using stack

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Simple example of start using stack

Post by dntknwjck » Mon May 27, 2019 9:13 pm

New to live code and trying to create a library stack for use with Sqlite.
Have found some information by searching for:livecode library script stack example on the internet.

so if I have:
start using "myLib.livecode"
How do I find if the stack loaded?
What is the proper syntax to call a function in "myLib.livecode" from another stack?
Thanks in advance for your help.

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

Re: Simple example of start using stack

Post by bogs » Mon May 27, 2019 9:54 pm

dntknwjck wrote:
Mon May 27, 2019 9:13 pm
How do I find if the stack loaded?
You could look in the openStacks. Put a button on your main stack, and in mouseUp put -

Code: Select all

on mouseUp
   answer the openStacks
end mouseUp
obviously, you would want to not use an answer dialog in a real application, this is just an example. If you are running in the IDE, you will see something like this -
Selection_001.png
myLib is the #3 stack!
Selection_001.png (10.21 KiB) Viewed 6892 times
Here is a pretty good explanation of how library stacks work -
http://livecode.byu.edu/messages/libraries.php
What is the proper syntax to call a function in "myLib.livecode" from another stack?
Your question is pretty literally the answer. Look up call in the dictionary.
Image

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

Re: Simple example of start using stack

Post by jmburnod » Mon May 27, 2019 9:57 pm

Hi dntknwjck,
If I believe LC dictionary (no tested)
The start using command places a stack's script into the message path after the current stack and before any objects in the backScripts.
You may call your function by its name

Code: Select all

put myFunction(something) into tVar
Best regards
Jean-Marc
https://alternatic.ch

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Simple example of start using stack

Post by SparkOut » Mon May 27, 2019 10:50 pm

A slight correction
start using "myLib.livecode"
should be

Code: Select all

start using stack "myLib.livecode"

dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Re: Simple example of start using stack

Post by dntknwjck » Mon May 27, 2019 11:53 pm

Thanks to all. I now have a working script file.

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 818
Joined: Fri Feb 06, 2015 4:03 pm

Re: Simple example of start using stack

Post by LiveCode_Panos » Tue May 28, 2019 9:33 am

Hello all,

See also the "libraryStack" message in the Dictionary.

Kind regards,
Panos
--

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

Re: Simple example of start using stack

Post by bogs » Tue May 28, 2019 11:00 am

Thanks Panos, I had forgot to mention that with the BYU link :oops:
Image

dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Re: Simple example of start using stack

Post by dntknwjck » Tue May 28, 2019 6:50 pm

Here is a simple example of script stack
in the resource folder put this as file testing.livecodescript
script "testing"

command doSomething
answer "The command doSomething in test.livecodescript has executed"
end doSomething

put his in a button's mouseup event:
on mouseUp
--resources is /home/user on Linux
start using stack (SpecialFolderPath("resources") & "/testing.livecodescript")
doSomething
end mouseup

Tested this on Linux Mint 18.3 and it was successful

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

Re: Simple example of start using stack

Post by Klaus » Tue May 28, 2019 6:57 pm

dntknwjck wrote:
Tue May 28, 2019 6:50 pm
...
on mouseUp
--resources is /home/user on Linux
start using stack (SpecialFolderPath("resources") & "/testing.livecodescript")
doSomething
end mouseup
To be precise in the IDE -> SpecialFolderPath("resources")
points to the folder in which the current stack resides, the one that executes the script.
In a standalone to the folder where you added all of your resources via the "Copy files" tab in then "Standalone Application Settings".

This way we can use this SpecialFolderPath as well in the IDE as in a standalone, works on ANY platform!

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

Re: Simple example of start using stack

Post by bogs » Tue May 28, 2019 7:56 pm

Klaus wrote:
Tue May 28, 2019 6:57 pm
This way we can use this SpecialFolderPath as well in the IDE as in a standalone, works on ANY platform!
Unless the user has made changes (on linux, anyway, not sure about win and mac). There was a thread recently that highlighted just such an issue, where the user changed their 'Documents' folder (linux) to just plain "docs", which specialFolderPath failed to notice.

Note - I don't think this applies to, in this case, ("resources"), but I am still a big fan of building the path manually.

Ah yes, this was the thread I was thinking of: https://forums.livecode.com/viewtopic.p ... ilit=linux
Image

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

Re: Simple example of start using stack

Post by Klaus » Tue May 28, 2019 8:22 pm

Hi Bogs,

yes, I remember that thread, but not using Linux, I did not pay much attention to it.
bogs wrote:
Tue May 28, 2019 7:56 pm
Note - I don't think this applies to, in this case, ("resources")...
Exactly, this is a special case, I think.
bogs wrote:
Tue May 28, 2019 7:56 pm
... but I am still a big fan of building the path manually.
Yep, I bet you HAVE TO, as a Linux user! :D


Best

Klaus

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

Re: Simple example of start using stack

Post by bogs » Tue May 28, 2019 8:38 pm

Klaus wrote:
Tue May 28, 2019 8:22 pm
Hi Bogs,

yes, I remember that thread, but not using Linux, I did not pay much attention to it.
bogs wrote:
Tue May 28, 2019 7:56 pm
Note - I don't think this applies to, in this case, ("resources")...
Exactly, this is a special case, I think.
Agreed :wink:
bogs wrote:
Tue May 28, 2019 7:56 pm
... but I am still a big fan of building the path manually.
Yep, I bet you HAVE TO, as a Linux user! :D
Actually, that preference goes back to VS5 on Win, I've seen no reason to change it in all these years :)

The formula I go with is usually the appPath, which I make sure all sub folders are contained within, although if I ever start writing stuff for Mac again, I suppose I'll have to change that up a bit :|
Image

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

Re: Simple example of start using stack

Post by Klaus » Tue May 28, 2019 10:01 pm

Yes, sure. On a Mac these specialfolderpaths are extremely handy, especially regarding the "unusual" folder hierachy of a Mac standalone. And Mac users ususally do not mess (e.g. rename) with the system folders like "Documents". Ok, some do, but then they are usually erm... licked! :-D

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

Re: Simple example of start using stack

Post by bogs » Tue May 28, 2019 10:26 pm

LOL!
Klaus wrote:
Tue May 28, 2019 10:01 pm
some do, but then they are usually erm... licked! :-D
Wonder if that leaves a 'sour taste in the mouth' :P
Image

dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Re: Simple example of start using stack

Post by dntknwjck » Tue May 28, 2019 11:09 pm

To be precise in the IDE -> SpecialFolderPath("resources")
points to the folder in which the current stack resides, the one that executes the script.
In a standalone to the folder where you added all of your resources via the "Copy files" tab in then "Standalone Application Settings".

This way we can use this SpecialFolderPath as well in the IDE as in a standalone, works on ANY platform!
[/quote]

Went back and looked at this:
SpecialFolderPath("resources") points to the folder the current stack is
I had used SpecialFolderPath("/resources") which points to my home directory
Don't know is that is the same for Linux or just my configuration.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”