Open a LC document using a standalone

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Open a LC document using a standalone

Post by maxs » Fri Mar 30, 2018 4:57 am

Hi

How can I open a LC document using a standalone? The LC document changes to a Unix document when I put it with a Standalone onto my laptop, and it will not open.

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

Re: Open a LC document using a standalone

Post by bogs » Fri Mar 30, 2018 5:09 am

Um...what is an "LC document"? Are you asking about a standalone launching another Lc stack?
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: Open a LC document using a standalone

Post by FourthWorld » Fri Mar 30, 2018 5:30 am

On Mac and Windows that should be happening. On Linux, the installer does not currently set up the MIME association to treat LiveCode stack files as documents that way.

If you're using Linux and running Gnome, you can set that association in the "Open With" tab of the file's Properties window.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Fri Mar 30, 2018 6:13 am

I am asking about a standalone launching another Livecode stack

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

Re: Open a LC document using a standalone

Post by bogs » Fri Mar 30, 2018 6:35 am

This is the lesson you want to read then. In its most basic form, in the standalone stacks openStack handler, you would write code like this-

Code: Select all

on openStack
	open stack "myStack"
	close stack "thisStack"
/* if you don't want the standalone to close, 
you could put 'iconify stack "thisStack" or
hide stack "thisStack" instead */
end openStack
And there are other variations on this theme, for instance 'go to stack "myStack"', etc.
Image

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Mon Apr 09, 2018 2:18 am

I have a stack in the same folder as my standalone. I want the standalone to open the other stack. (open stack "myStack") does not work,

DO I need to get the entire pathname? Do I need to set a new filetype to open this stack?

If the livecode app is not on the laptop, the stack is displayed as a UNIX file, and my standalone does not recognize it. How do I open a stack using a standalone without Livecode being on the computer?

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

Re: Open a LC document using a standalone

Post by bogs » Mon Apr 09, 2018 5:15 am

I think you were taking me a bit too literally, open stack "myStack" was an example, you need to substitute the name of the stack you want to open in place of 'myStack'.

Did you read the lesson I linked to? It goes into far more depth.
Image

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

Re: Open a LC document using a standalone

Post by jacque » Mon Apr 09, 2018 9:16 pm

Is the standalone for desktop or mobile? Are you including the LC stack in the Copy Files pane of the standalone settings or do you add it later? Or does the user choose a file to open?

A full file path will always work but getting that path will vary depending on how you've set up the standalone and how you include the file. If the user chooses a file from disk, use "answer file" to get the path. If the file is included in the Copy Files pane then use specialFolderPath("resources") and add the rest of the path by script: specialFolderPath("resources") & "/mystack.livecode". That will also work if you add the file manually later, but only on desktop and only if the file is in the same folder as the app.

If the file is elsewhere or you are building for mobile then you may need a different path.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Sun Apr 29, 2018 6:57 am

I am trying to make a launcher app so I can store information in the second stack . The app and the stack are in the same folder. Im beyond frustration. I can't even add an attachment to this forums window to show an example. I read the documentation which didn't help

I tried using
on mouseup
open stack "CCC.tmg"
close stack "Classroom Control Center"
end mouseup
Nothing happened.

I also tried sending a pathname to the second stack. again another happened.
on openstack
OpenWorkshop
end openstack

on OpenWorkshop

put AppPath()&"CCC.tmg" into tWorkshopStack
if there is a stack tWorkshopStack
then
toplevel stack tWorkshopStack
else
answer "Can't find file 'CCC.tmg'."
end if
close stack "Classroom Control Center"
end OpenWorkshop

function AppPath pAppStack
-- put AppStack(pAppStack) into tStack
--put AppStack("Classroom Control Center") into tStack
put the effective filename of stack tStack into tPath
--
if (the platform is "MacOS") AND ("dev" is not in the environment)
then
if IsOSX()
then
set the itemdel to "/"
get offset(".app/Contents/MacOS/", tPath)
if it > 0
then -- account for bundle:
delete char it to len(tPath) of tPath
end if
end if
end if
--
set the itemdel to "/"
put empty into last item of tPath
return tPath
end AppPath

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

Re: Open a LC document using a standalone

Post by bogs » Sun Apr 29, 2018 2:53 pm

IF I'm reading your problem correctly, you developing this on Mac OSX. If that is the case, and I followed your code correctly, you can't put the stack in the app folder, I think. Instead, try this.

Create a folder in your home folder, and put the stack you are trying to launch in there.
specialFolderPath/home/folderYouCreated
// Whatever folder you'd like your stack saved in...
The side benefit is that this path will work no matter where you deploy to with the exception of Android I believe, where you would have to use 'documents'. In the dictionary, look up 'specialFolderPath'.

When you deploy your project, you will have to copy the stack file to that folder path as well.
Image

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Sun Apr 29, 2018 4:31 pm

Thank you bogs, for taking the time and effort to assist me. Unfortunately, because it is difficult for me to explain things clearly in written form, I am still having difficulty.

Let me try again:

I wrote a launcher stack and saved it as a standalone using LC 8.1.6 for Mac OS 10.

I wrote a second stack , which allows users to input information which will not be erased when the user quits the application.

I put the app and the second stack in a folder which I can copy to another Mac computer which does not have the Livecode application. (I do not know what a home folder is. ) And I keep the stack in the same folder as the app so I can send a pathname to open that app.

Because the second computer does not have Livecode, the standalone app cannot recognize the second stack. Because Livecode is not installed, the other computers recognize the second stack as a Unix file. When I double click on the second stack nothing happens. When I open the app stack it cannot find or open the second stack.

I tried to replicate the code in the documentation using 2 empty stacks. But the same thing happens. The second stack will only open if Livecode is installed on the computer.

(I have always been able to open documents which are in the same folder as the App. Is this not the case in Livecode? Or did I misunderstand?

Perhaps, if someone has a sample stack and app which does work on a computer which does not have Livecode installed, I can reuse that code.

It seems like a simple problem and important. I don’t know why the documentation is so short on this subject. This is my final step in a project that has taken 6 months to complete. I have never needed help on this. Now, at the final stage, I have 60 teachers waiting weeks while I’m tearing my hair out trying to make a standalone that works.

Here is what I tried on my computer:

Creating the launcher
The launcher stack will be built into a standalone and all we need it to do is to open our main application, it can then close itself. Add the following script to the stack script of the launcher stack.
on openStack open stack "Main Application" close stack "Launcher" end openStack
Thats all we need to do. The launcher will then open the Main Application stack, which can be modified and saved as it is not a standalone.

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

Re: Open a LC document using a standalone

Post by jacque » Sun Apr 29, 2018 4:42 pm

Using a Home folder is a Unix thing, it isn't a good choice for Mac or Windows. There are some errors in your handlers that are causing the problem, but I'm not at my Mac right now and writing code on a mobile device is tricky. I'll be back in a couple of hours, stay tuned.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Open a LC document using a standalone

Post by Klaus » Sun Apr 29, 2018 4:58 pm

Hi Max,

you cannot save anything in the application bundle of a standalone!
and since we have several specialfolderpath() names for years, no need to
mess around with the FILENAME of the standalone stack!

Do like this to have an "editable" stack in your app:
1. Add that "editable" stack via the "Copy files" tab in the "standalone builder settings"!
2. When your app starts, copy that stack over to the users documents folder,
this is where we definitivley have WRITE (save a stack) permission!
3. use the copied folder from now on.

Script of standalone stack:

Code: Select all

on openstack
  ## Create path to RESOURCES folder!!!!! and target stack in the users docs folder
  put specialfolderpath("resources") & "/my_editable_stack.livecode" into tSourceStack  
  put specialfolderpath("documents") & "/my_editable_stack.livecode" into tTargetStack

  ## check if stack already exists:
  if there is not a file tTargetPath then
    put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)
 end if

  ## Now open that stack that we can modify and SAVE!
  go stack tTargetStack
end openstack
Best

Klaus

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 421
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Sun Apr 29, 2018 8:07 pm

Thanks Klaus,

THis seems simplier

I tried. When I open the app, it did create a new file in the document folder. But the file did not open, and showed a file size of 0. Also when I double click on the document file, I got the error: "This is not a stack"

on openstack
## Create path to RESOURCES folder!!!!! and target stack in the users docs folder
put specialfolderpath("resources") & "/testa.livecode" into tSourceStack
put specialfolderpath("documents") & "/testb.livecode" into tTargetStack

## check if stack already exists:
if there is not a file tTargetPath then
put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)
end if

## Now open that stack that we can modify and SAVE!
go stack tTargetStack
end openstack

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

Re: Open a LC document using a standalone

Post by Klaus » Sun Apr 29, 2018 8:31 pm

Ops, sorry, a typo, my fault:
....
## check if stack already exists:
## if there is not a file tTargetPath then
if there is not a file tTargetStack then
...

Post Reply

Return to “Talking LiveCode”