Behavior stack script not run first time card is visited

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Behavior stack script not run first time card is visited

Post by jim1001 » Tue Oct 03, 2017 7:47 pm

I have some buttons on a card. The behavior of all the buttons is set to the same script-only stack and works as expected in the IDE.

For my Android standalone however, the first time I visit the card and click on any of the buttons nothing happens. If I go to another card then back to the card with buttons, all the buttons then trigger the event handler in my script-only stack as I would have expected the first time.

Before the first visit I've checked (by answer dialogs when running):
- the behavior stack is included in the stackFiles of the UI stack
- the behavior of the buttons is set to the stack
- the behavior stack exists and is loaded in memory

Just to make sure there was nothing wrong in the way I was pressing the buttons, for one of them I over-ruled the shared behavior with the script file directly attached to the button in the IDE. This confirmed the button press was being correctly registered.

For information, the card containing the buttons also gets its behavior from a script-only stack but I’m using this kind of setup on another card where the buttons respond as expected on first visit. Also I’m using Levure though I can’t think why that would make any difference.

It may be difficult to try & reproduce in a simplified app.

Anyone any ideas what could be going wrong & / or how to diagnose?

Thanks for reading,
Jim

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Behavior stack script not run first time card is visited

Post by jim1001 » Tue Oct 03, 2017 9:34 pm

OK - I've been looking at the commands that run when the second card is opened before I go to the problem card for a second time & then see it working. I have an idea what's happening. I'll test it & try & summarize when I'm sure what's going on.

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Behavior stack script not run first time card is visited

Post by jim1001 » Tue Oct 03, 2017 11:26 pm

To cut to the chase I found that by inserting this one line in the card’s preOpenCard handler for just one button made all the buttons use the intended behavior stack script:

Code: Select all

set the behavior of button "myButton1" to the long id of stack "myButton Behavior"
I had done this when creating the button in code in the IDE but it seems it needs to be repeated when the standalone is running. I guess this is because the long id of the stack contains a path and the paths are different in the IDE and in the standalone. However the LiveCode dictionary says
...the form stored in the behavior includes only the stack name, allowing the reference to continue to work after the stack file has been moved to another computer.
I didn’t find that to be true.

Something else I don’t fully understand is why setting the behavior script for only one button as above directed all the other buttons to the script. I can only guess that the line above links the stack name "myButton Behavior" with the correct path for that & all subsequent occurrences of the stack name.

Post Reply

Return to “Android Deployment”