Script Help For Running And Stopped Mobile Image Buttons


Hey guys.

I need a little script help with the mobile interface "Image buttons". I have two custom images I have made for one button... put simply, I have a green image for “script running”, and a red image for “script stopped”. I have the following script where if I press the image button once, the script runs. Pressing the same button again, the script stops.

What I have been trying to do is when the button is pressed once to start the script, I would like to have the green "running" image continuously on show while the script is running.

Then to press the same button again to stop the script, then have the red "stopped" image continuously show until button is pressed again. At the moment, only the "Stopped" image is displayed whether the script is running or stopped. Here's the script with #notes included...


#If button is pressed, this section runs.

#This is the running script where the green RUNNING image should come on and stay on...
if (!$pressed)
ControlCommand("Sound Sensors", ScriptStart)
$pressed = 1

#If the same button is pressed again, this section runs.

#This is the stopped script where the red STOPPED image should come on and stay on...
ControlCommand("Sound Sensors", ScriptStop)
$pressed = 0


I can guess that something like a "WaitForChange() " is needed, but have not had much luck so far. So any help you guys can offer would be appreciated.



A script that is an image button for mobile has two states:
- running
- stopped

There can be an image for each state. The interface allows you to select an image or choose an existing image for each state.

If a script is lengthy, the running image will be displayed. To stop the script, press the button while it’s runnjng and the script will stop. A stopped script will display the stopped image.

Have fun!

User-inserted image


Thanks for the reply DJ. I’m always having fun and glad I’m back working with robots again. Anyway...


If a script is length (I guess you meant “long”), the running image will be displayed.

That’s cool and I get that as I’ve used this a few times before on other bots. I guess what I should have mentioned is that when the script is running, $pressed = 1, this ControlCommand() is running looped script... ControlCommand("Sound Sensors", ScriptStart)

The second part of the same script, $pressed = 0, runs a ControlCommand("Sound Sensors", ScriptStop).

But because I’m running two State’s in one script, that’s why I can’t get a “running” image showing, (hope that makes sense, lol).


You won't be able to have the image show the running status of another script control. Put the script that you're attempting to show the status of in the mobile interface image button Smile. That's what it is, an image button that manages its own script.

What you're looking for is the image button to show the status of another script - that can't be done because it IS a script itself, and shows the status of itself.

The purpose of the Image Button is to manage the START and STOP of its script, not another script.

Another option is to have a LABEL beside or under the button that displays the status. And have the image button named "Toggle Blah Blah". And it sets a variable and starts the script, or sets a variable which stops the script. The variable can be displayed in the LABEL.


Look at this... longrunningmobiletoggle.ezb

*Note: ensure you run the Init first so the variable is initialized.


a video to help



What you said makes perfect sense to me now... like you say, even though my script does one of two things, it is still one script control and that is reading another script control somewhere else. I did try to add the original running script (and not the ControlCommand()) to it, but still had no luck.

I will have a look at the label idea though, that could be useful, and I’ll check out the project you linked to. Many thanks for the advice. Smile

And thanks Patrick for the video. I’ll have a look when I get home.


So I came back to this after a good nights sleep, re-read DJ's post #4, and realised where I was going wrong. I removed the ControlCommands() and copy/pasted the actual script. My script now looks like this, and image button now works exactly as I wanted it to...


if (!$pressed)
$left= GetADC(0)
$right= GetADC(1)
if($left >1)

elseif($right >1)
$pressed = 1

$pressed = 0


So thanks to DJ for helping out and pointing me in the right direction. I think I've been away too long and have become a bit rusty on a few things, lol. And thanks for the project example you posted. I may have a use for that example in another small project. Smile