United Kingdom
Asked — Edited

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.

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

endif

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.

Thanks.


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

PRO
Synthiam
#1  

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

United Kingdom
#2  

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

Quote:

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).

PRO
Synthiam
#3  

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:). 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.

United Kingdom
#6  

@Dj.

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 control command) 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.:)

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

United Kingdom
#7  

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)
:loop
$left= GetADC(0)
$right= GetADC(1)
sleep(500)
servospeed(d6,1)
servo(d6,90)
:loop 
if($left >1)
servo(d6,140)
sleep(3000)
servo(d6,90)
sleep(2000)

elseif($right >1)
servo(d6,40)
sleep(3000)
servo(d6,90)
sleep(2000)
endif
sleep(500)
goto(loop)
$pressed = 1

ELSE
sleep(1000)
pause()
$pressed = 0

endif

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.:)