save content of field [SOLVED]

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

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

Re: save content of field

Post by SparkOut » Wed Dec 01, 2021 10:03 pm

Stacks copied in the "copy files" section get built into the specialFolderPath ("resources") location.

On Windows, this is relative to the mainstack exe location. If that is running in a writable location then fine. If in "Program Files" maybe, maybe not, depending on user privileges.

On mobile, the resources folder is sandboxed. The originally built standalone can access this as "master app" but even the standalone cannot save there. Just "go stack" will try to open the target stack but that also needs to be in a writable location (else, as already seen it will fail). (Yes! Even just trying to open the stack without yet specifying any save actions.)

Hence, for mobile, you have to take the "template" stack you built with the "copy files" tab settings and save a copy of it from specialFolderPath("resources") to specialFolderPath('documents"). You will want to check whether that copy exists already when the app starts, or else you will overwrite any changes saved last time.

When you want to "go stack" to the stack you want to save, you need to refer to the "documents" location to which the target stack was copied the first time you ran the app.

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

Re: save content of field

Post by dunbarx » Wed Dec 01, 2021 10:43 pm

Sparkout is the sort of guy who knows the ins AND the outs of LC.

Craig

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

Re: save content of field

Post by SparkOut » Thu Dec 02, 2021 9:12 am

Well, just SOME of them maybe. I'm not in the same Klaus as class.

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: save content of field

Post by Samuele » Thu Dec 02, 2021 10:42 am

Klaus wrote:
Wed Dec 01, 2021 5:28 pm
You did not read SpakOut's posting, right?
Here the important parts:
I think it was mentioned before, but the app folder mapped to "resources" is not writeable.
So your script cannot work.
On first run, you need to check whether the stack that needs to be saved exists already in the app "documents" folder and if not, copy it there from "resources".
What does this tell you?
sorry but i'm not that good with english and often i don't understand... :?
i tried like this but i don't even know if it's on the right track for understanding this... is it like this?

Code: Select all

on mouseDown
   put the text of widget "fi" into _gUserName
   put _gUserName into field "la"
   if the environment is "mobile" then
      mobileVibrate 1
      --save this stack
      put specialfolderpath("documents") & "/Working.livecode" into tStackToSave
      if there is a file tStackToSave then
         save stack tStackToSave
      else
         put specialfolderpath("resources") & "/Working.livecode" into tStackFromResources
         put url("file:" & tStackFromResources) into url url("file:" & tStackToSave)
         save stack tStackFromResources
      end if
   end if
end mouseDown
thanks!
(i tried now and it doesn't work)
Samuele.

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

Re: save content of field

Post by Klaus » Thu Dec 02, 2021 12:18 pm

Buongiorno Samuele,

no, no, no! :D

At that point (on mousedown) it is already much too late, everything has to happen
before you open stack "WORKING".

The logical workflow is like this:
1. You create a standalone from the "SPLASH" stack.
All of your inclusions like the ASK and ANSWER dialogs and all externals you are using need to go into stack SPLASH!

2. On the cellphone you start the app (= stack "SPLASH").

3. The app (= stack "SPLASH") checks if there is already a stack named "WORKING" in the users DOCS folder.

4. If there isn't the app (= stack "SPLASH") copies that stack from RESOURCES to DOCS.

5. THEN the app (= stack "SPLASH") opens that stack from the DOCS folder.

6. NOW stack WORKING can be saved.

Capisce?

You need to create a little script in the SPLASH stack:
This goes into the stackscript of SPLASH!

Code: Select all

on openstack
   
   ## Neccessary so all opened stacks can access the inclusions of stack "SPLASH"!
   start using this stack
   
   ## Prepare filenames:
   ## Stack in RESOURCES
   put specialfolderpath("resources") & "/working.livecode" into tSourceStack
   
   ## Stack in DOCUMENTS folder
   put specialfolderpath("documents") & "/working.livecode" into tTargetStack
   
   ## check if we already opened the app = the WORKING stack is already in DOCS folder
   if NOT (there is a stack tTargetStack) then
      
      ## Now copy the stack to the DOCS folder
      put url("binfile:" & ttSourceStack) into url("binfile:" & tTargetStack)
   end if
   
   ## NOW we can open that "new" stack that NOW can be saved
   go stack tTargetStack
   hide stack "splash"
end openstack
Now you can do this in the WORKING stack:

Code: Select all

on mouseDown
   put the text of widget "fi" into _gUserName
   put _gUserName into field "la"
   if the environment is "mobile" then
      mobileVibrate 1
      ## This will work now:
      save this stack
...
Best

Klaus

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

Re: save content of field

Post by Klaus » Thu Dec 02, 2021 12:42 pm

If you need this for the DESKTOP, too, use these folders:

Code: Select all

...
if the environment = "mobile" then
  # Mobile:
  put specialfolderpath("documents") into tTargetStack
 else	
  ## Desktop:
  ## Windows
  if the platform contains "Win" then
    put specialfolderpath("support") into tTargetStack
  else
   ## Mac:   
   put specialfolderpath("preferences") into tTargetStack
  end if
end if
put "/working.livecode" after tTargetStack
...

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

Re: save content of field

Post by Klaus » Thu Dec 02, 2021 3:11 pm

However if you only have some text to save, this technique seem a little OVERKILL! :-)

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

Re: save content of field

Post by jacque » Thu Dec 02, 2021 5:40 pm

Klaus wrote:
Thu Dec 02, 2021 3:11 pm
However if you only have some text to save, this technique seem a little OVERKILL! :-)
I was thinking the same thing. It would be much easier to just write a text file to the documents folder. If the app is only for mobile it doesn't even need to be encrypted since users can't directly access it, though I probably would use encryption if the info is very sensitive.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: save content of field

Post by FourthWorld » Thu Dec 02, 2021 5:56 pm

jacque wrote:
Thu Dec 02, 2021 5:40 pm
Klaus wrote:
Thu Dec 02, 2021 3:11 pm
However if you only have some text to save, this technique seem a little OVERKILL! :-)
I was thinking the same thing. It would be much easier to just write a text file to the documents folder. If the app is only for mobile it doesn't even need to be encrypted since users can't directly access it, though I probably would use encryption if the info is very sensitive.
Even simpler: if the data is local why does the app need to add its own login in addition to the phone's login?

Also, without a server how would password reset be handled?

You could reset without a server, but that would mean anyone using the phone can reset the password, so why have a password?

If password reset isn't available, how do they recover data if they've forgotten their password?

I think we need to learn more about this unusual use case before advising how to support it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: save content of field

Post by Samuele » Mon Dec 06, 2021 12:14 pm

Klaus wrote:
Thu Dec 02, 2021 12:18 pm
Buongiorno Samuele,

no, no, no! :D

At that point (on mousedown) it is already much too late, everything has to happen
before you open stack "WORKING".

The logical workflow is like this:
1. You create a standalone from the "SPLASH" stack.
All of your inclusions like the ASK and ANSWER dialogs and all externals you are using need to go into stack SPLASH!

2. On the cellphone you start the app (= stack "SPLASH").

3. The app (= stack "SPLASH") checks if there is already a stack named "WORKING" in the users DOCS folder.

4. If there isn't the app (= stack "SPLASH") copies that stack from RESOURCES to DOCS.

5. THEN the app (= stack "SPLASH") opens that stack from the DOCS folder.

6. NOW stack WORKING can be saved.

Capisce?

You need to create a little script in the SPLASH stack:
This goes into the stackscript of SPLASH!

Code: Select all

on openstack
   
   ## Neccessary so all opened stacks can access the inclusions of stack "SPLASH"!
   start using this stack
   
   ## Prepare filenames:
   ## Stack in RESOURCES
   put specialfolderpath("resources") & "/working.livecode" into tSourceStack
   
   ## Stack in DOCUMENTS folder
   put specialfolderpath("documents") & "/working.livecode" into tTargetStack
   
   ## check if we already opened the app = the WORKING stack is already in DOCS folder
   if NOT (there is a stack tTargetStack) then
      
      ## Now copy the stack to the DOCS folder
      put url("binfile:" & ttSourceStack) into url("binfile:" & tTargetStack)
   end if
   
   ## NOW we can open that "new" stack that NOW can be saved
   go stack tTargetStack
   hide stack "splash"
end openstack
Now you can do this in the WORKING stack:

Code: Select all

on mouseDown
   put the text of widget "fi" into _gUserName
   put _gUserName into field "la"
   if the environment is "mobile" then
      mobileVibrate 1
      ## This will work now:
      save this stack
...
Best

Klaus
thanks! that works, but when i try to save the stack as standalone it gives me this Screen Shot 2021-12-06 at 12.13.54.png
and the problem is that if i click on save it will show the same thing again and again , is it a problem?
Attachments
Screen Shot 2021-12-06 at 12.13.54.png
Samuele.

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

Re: save content of field

Post by Klaus » Mon Dec 06, 2021 3:31 pm

Oh yes, this is an old LC problem!
Do this:
put this into the stack script of "Splash.livecode":

Code: Select all

function isBuildingStandalone
   return (the environment is "development" AND there is a stack "revStandaloneProgress" AND the mode of stack "revStandaloneProgress" > 0)
end isBuildingStandalone
Then add this to your "on openstack" Handler:

Code: Select all

on openstack  
   if isBuildingStandalone() then
      exit openstack
   end if
   
   ## Neccessary so all opened stacks can access the inclusions of stack "SPLASH"!
   start using this stack
...
Unfortunately LC will also execute these scripts (pre-/openstack, pre-/opencard etc...) when creating a standalone, this will prevent LC from this behavour.

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: save content of field

Post by Samuele » Mon Dec 06, 2021 7:30 pm

ok thanks, now i have another problem it shows only this
Screen Shot 2021-12-06 at 19.29.04.png
all the time when trying to save as standalone
Samuele.

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

Re: save content of field

Post by Klaus » Mon Dec 06, 2021 7:46 pm

Sorry, never saw this dialog, so I have no idea what's going wrong... :(

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: save content of field

Post by Samuele » Mon Dec 06, 2021 9:42 pm

anyone has any idea why it doesn't let me save as standalone the splash stack with the working in it?
Samuele.

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

Re: save content of field

Post by dunbarx » Mon Dec 06, 2021 11:27 pm

Samuele.

Try saving another "splash/working" pair of stacks and see if they go through. Just two brand new stacks, but where one stack file is attached to the other. I assume this is what you have now.

If that works, we can then know it is something in the other that is stopping the process.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”