Page 1 of 1

Running function when app starts?

Posted: Tue Dec 10, 2013 6:47 am
by trenatos
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.

Re: Running function when app starts?

Posted: Tue Dec 10, 2013 7:02 am
by Simon
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

Re: Running function when app starts?

Posted: Tue Dec 10, 2013 7:11 am
by trenatos
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

Re: Running function when app starts?

Posted: Tue Dec 10, 2013 7:27 am
by Simon
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

Re: Running function when app starts?

Posted: Tue Dec 10, 2013 8:39 am
by trenatos
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)

Re: Running function when app starts?

Posted: Tue Dec 10, 2013 8:50 am
by Simon
Thanks for writing back trenatos, sometimes it's scary asking someone to improve their "style".

Simon

Re: Running function when app starts?

Posted: Tue Dec 10, 2013 9:19 am
by trenatos
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.