Running function when app starts?

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Running function when app starts?

Post by trenatos » Tue Dec 10, 2013 6:47 am

I'm new to mobile programming, and one of the small tasks I want to do is create an animating background for the menu.

I've got that done, a simple function that calls itself and moves the background back and forth.

But I can't get it to start when the app starts.

It works if I push a button, but not if I place the same call from on openstack or on opencard

Code: Select all

on aniBack
   if checkit contains "start" then
      if direction = "left" then
         set the left of image "background" to the left of image "background" -1
         if the left of image "background" < -200
         then
            put "right" into direction
         end if
      else if direction = "right" then
         set the left of image "background" to the left of image "background" +1
         if the left of image "background" > -5
         then
            put "left" into direction
         end if
      end if
      send aniBack to me in 20 milliseconds
   end if
end aniBack

on openstack
   mobileSetAllowedOrientations ("landscape left,landscape right")
   set the left of image "background" to 0
   set the top of image "background" to 0
   aniBack
end openstack
The button simply calls aniBack.

Any help or ideas would be greatly appreciated, I've been fighting with this for the past few hours.
Marcus

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

Re: Running function when app starts?

Post by Simon » Tue Dec 10, 2013 7:02 am

Hi trenatos,
if checkit contains "start" then
Have you proved this is true?

Code: Select all

on openstack
   mobileSetAllowedOrientations ("landscape left,landscape right")
   set the left of image "background" to 0
   set the top of image "background" to 0
answer checkit -- test before launching
answer direction --test does it contain right or left?
   aniBack
end openstack
This is just for debugging, but from the info you've given it's where I'd start.
Now the delay caused by "answer" will probably allow the function to run as it does from a button, you can use that info.

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

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Re: Running function when app starts?

Post by trenatos » Tue Dec 10, 2013 7:11 am

This worked!

Code: Select all

on openstack
   mobileSetAllowedOrientations ("landscape left,landscape right")
   set the left of image "background" to 0
   set the top of image "background" to 0
   put "left" into direction
   put "start" into checkit
   aniBack
end openstack
Apparently I had to set direction and checkit *within* the openstack for it to properly register and now it works, the animation plays when the app loads.

Thank you Simon, you made me look in the right place
Marcus

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

Re: Running function when app starts?

Post by Simon » Tue Dec 10, 2013 7:27 am

Hi trenatos,
You are welcome to ignore this but I implore you take up a naming convention;
http://fourthworld.com/embassy/articles ... #Variables
gDirection
tCheckIt
It will help you spot variables quickly and help us to easily follow your code. :)

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

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Re: Running function when app starts?

Post by trenatos » Tue Dec 10, 2013 8:39 am

Thanks Simon, I usually do use proper notation, just wasn't paying attention (This small app grew out of a tutorial-set I started adding to. lol)
Marcus

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

Re: Running function when app starts?

Post by Simon » Tue Dec 10, 2013 8:50 am

Thanks for writing back trenatos, sometimes it's scary asking someone to improve their "style".

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

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Re: Running function when app starts?

Post by trenatos » Tue Dec 10, 2013 9:19 am

No worries, I know the feeling.

I'm a web developer, and usually I use proper notation (Usually camel notation of some variation) and lots of comments, sometimes ridiculous amounts of comments when working on projects with other developers.
Marcus

Post Reply