How to run code on start up

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

Post Reply
UtahCode197
Posts: 21
Joined: Sat Jun 22, 2013 9:36 pm

How to run code on start up

Post by UtahCode197 » Sun Nov 15, 2015 7:34 pm

I want to run some code (a clock) as soon as the program starts (ie not have to have a button pressed for the code to start). Is there a way to do this?
Thanks

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: How to run code on start up

Post by quailcreek » Sun Nov 15, 2015 7:48 pm

You could put the code in an openStack or preOpenStack script in a stack script.
Tom
MacBook Pro OS Mojave 10.14

UtahCode197
Posts: 21
Joined: Sat Jun 22, 2013 9:36 pm

Re: How to run code on start up

Post by UtahCode197 » Sun Nov 15, 2015 8:10 pm

Thanks for your reply!
I now have this code and it keeps flashing between internet date and item 5 of internet date (the time)

Code: Select all

on preOpenStack
   set the flag of me to not the flag of me
   if the flag of me then startTimer
end preOpenStack
on startTimer
   set itemDelimiter to " "
   put item 5 of internet date into me
   if the flag of me then send startTimer to me in 0.5 second
end startTimer
I'm not sure how to fix this. Is there a way?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How to run code on start up

Post by Simon » Sun Nov 15, 2015 8:54 pm

Hi Rory,
I just put all of this into a stack script;

Code: Select all

on preOpenStack
   set the flag of me to not the flag of me
   if the flag of me then startTimer
end preOpenStack

on startTimer
   set itemDelimiter to " "
   put item 5 of internet date
   if the flag of me then send startTimer to me in 0.5 second
end startTimer

on mouseUp
      preOpenStack
end mouseUp
It worked fine for me, LiveCode 7.1 Win 7

I will say that there was a recent post in which the coder stated that running a script like this all day would end up I think 2 minutes off at the end of the day. It took stopping the timer and restarting it to sync up.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply