On startup not working

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

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

On startup not working

Post by CAsba » Mon Oct 31, 2022 11:14 am

Hi all,
I have put the code attempts 1, 2 and 3 below into the master stack but without success:-

1.
on startup
go to card "template1"
end startup

2.
on startup pMode
global gRunningFromU3Drive
switch pMode
case "u3launch"
put true into gRunningFromU3Drive
break
case empty
put false into gRunningFromU3Drive
break
end switch
end startup
on startup
go to card "homepage"
go to card "template1"
end startup
3.
on startup pMode
global gRunningFromU3Drive
switch pMode
case "u3launch"
put true into gRunningFromU3Drive
break
case empty
put false into gRunningFromU3Drive
break
end switch
go to card "homepage"
go to card "template1"
end startup

Now, I'm fresh out of ideas ! Can anyone help ?

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: On startup not working

Post by stam » Mon Oct 31, 2022 11:53 am

Don’t use this handler. Instead use on preOpenStack and put the handler in the card script of your first card.

In 2 you seem to using “on startup” twice, consecutively. Only the first will run.
3 might run, you probably need to specify the stack that contains the desired cards.

But almost always you’re better off using on preOpenStack

PS: PLEASE use the “code” button when you insert code (the 4th one along from the “bold” button, above where you type forum message). Just select your code and click the button and it will surround it with code tags so it’s readable - thank you

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: On startup not working

Post by CAsba » Mon Oct 31, 2022 12:00 pm

Many thanks, Stam, that worked fine.

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: On startup not working

Post by Klaus » Mon Oct 31, 2022 12:09 pm

"on startup" is sent when the engine/runtime gets loaded into memory.
This will only have effect in a standalone because the IDE (Livecode) will catch this message and does not pass it.

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: On startup not working

Post by stam » Mon Oct 31, 2022 12:19 pm

Thanks Klaus - i knew it was something like that but couldn't quite remember and couldn't check as am at work... ;)

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: On startup not working

Post by CAsba » Thu Nov 10, 2022 2:36 pm

Hi,
I seem to have got myself into a real mess ! I have been trying to get an ask box to show on start up. I've tried on startup and on preopenstack on the stack and on the first page. No success, but worse, on start up, now, I get 5 instances of the first page launching, and this is with all the code I have tried commented out!
I would just love to launch and get just the one instance of the first page launched - any ideas ?

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: On startup not working

Post by Klaus » Thu Nov 10, 2022 2:45 pm

Hi CAsba,
CAsba wrote:
Thu Nov 10, 2022 2:36 pm
Hi,
I seem to have got myself into a real mess ! I have been trying to get an ask box to show on start up. I've tried on startup and on preopenstack on the stack and on the first page. No success, but worse, on start up, now, I get 5 instances of the first page launching, and this is with all the code I have tried commented out!
I would just love to launch and get just the one instance of the first page launched - any ideas ?
sound like you are using Windows, right?
If yes, you can prevent your EXE from starting several times, which is not possible on a Mac, add this to your STACK script:

Code: Select all

on relaunch
  ## Nada, just a dummy handler, but does what you need!
end relaunch
What exactly did you script so far for the ask/answer dialog? Please post your script(s)!

Best

Klaus

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: On startup not working

Post by Klaus » Thu Nov 10, 2022 2:51 pm

Some hints:

Code: Select all

on XXX
  go to card "template1"
end XXX
if "template1" is the FIRST card in your stack, then this is not neccessary, LC will always go to the first card in a stack.

Code: Select all

on XXX
  go to card "homepage"
  go to card "template1"
end XXX
This will happen so fast, that the user might see it flashing, not good.
Please decide to what card you actually want to go first!

Code: Select all

global gRunningFromU3Drive
on startup
   switch pMode
      case "u3launch"
         put true into gRunningFromU3Drive
         break
      case empty
         put false into gRunningFromU3Drive
         break
         ...
   end switch
end startup
Where on earth did you find this "ancient" code snippet? :-D
Do you plan to actually use this info -> gRunningFromU3Drive?
If not, just leave it out.

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: On startup not working

Post by CAsba » Thu Nov 10, 2022 3:44 pm

Hi Klaus, in the meantime I accidentally deleted the home page and its copy, so I've now had to revert to a project copy - lost a couple of weeks of progress there...Well, nobody said it would be easy !
Anyway, thanks for interest and help.

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: On startup not working

Post by Klaus » Thu Nov 10, 2022 3:55 pm

OUCH! :?
Good luck!

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: On startup not working

Post by CAsba » Thu Nov 10, 2022 4:22 pm

Good news ! I managed to copy from the backup to the current by temporarily changing the stack name to copy from - and it worked. The first card in the stack is now changed however; is there a way to nominate the "first card" ?

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: On startup not working

Post by Klaus » Thu Nov 10, 2022 4:28 pm

Sure, just set the number of your card:

Code: Select all

...
set the number of cd "the one that is not the first card" to 1
...
Et voila, card "the one that is not the first card" is now the first card in the stack.

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: On startup not working

Post by CAsba » Thu Nov 10, 2022 5:28 pm

Thanks a lot, worked OK.
I tried the following code - commented out parts are what I've tried - to get an input from the user the first time she runs the app:

Code: Select all

on relaunch
   ## Nada, just a dummy handler, but does what you need!
end relaunch
--on startup 
--   go to card "template1" of stack "casba accounts"
--end startup
on preopenstack 
   go to card "template1" of stack "casba accounts"
   send "mouseup" to btn "Get business name" of card "template1" of stack "casba accounts"
   end preopenstack 
--on startup 
--   send "mouseup" to btn "Get business name" of card "template1" of stack "casba accounts"
--end startup
Without the line "send mouseup..." card template1 shows. That's OK.
With the line, the btn "get business name" activates before the card template1 shows.
Any ideas ?

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: On startup not working

Post by Klaus » Thu Nov 10, 2022 5:43 pm

So "casba accounts" is not the runtime stack itself but a substack of the runtime stack?
Try to add a little delay like:

Code: Select all

on preopenstack 
  go to card "template1" of stack "casba accounts"

  ## Give LC a bit time to show that card:
  wait 300 millisecs with messages
  send "mouseup" to btn "Get business name" of card "template1" of stack "casba accounts"
end preopenstack 
If that does not work, try -> on openstack, then without the wait.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: On startup not working

Post by FourthWorld » Thu Nov 10, 2022 6:36 pm

CAsba wrote:
Thu Nov 10, 2022 3:44 pm
Hi Klaus, in the meantime I accidentally deleted the home page and its copy, so I've now had to revert to a project copy - lost a couple of weeks of progress there...Well, nobody said it would be easy !
I don't know anyone who has really good backup until after they suffer a loss, including yours truly

But my loss was significant, so I got thorough: in addition to nightly redundant rotating backups (portable drives are cheaper than time), I've also added Nextcloud to my workflow.

Nextcloud is a free and open collaboration toolkit that I also use to manage all my work with clients. But for myself it lets me keep my local machines in synch, with an off-site backup.

The synch alone would be great enough, having my work files and Plugins folder updated across all machines as I go. But the backup makes it even better: everything is timestamped, backed up with each save, so I can roll back to something I was working on without losing more than a few minutes work.

I pass this along so no one has to suffer at I one suffered. :)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply