Error getting input?

Hello,
I am trying to trigger the subroutine ‘fire’ when a switch is pressed down (and causes its target to equal 0)
The stack overflows nearly instantly resulting in an error, usually 0x0080 and sometimes 0x0040

I have tried using the example script for using inputs from the site but all of them spit out errors,

Here is the script i’ve tried throwing together, I am sort of new to coding this kinda of thing,

# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through a sequence
# of positions on servo 0.
sub button_push
if 0 servo equals 0 fire
#0 get_position 0
#if 0 fire
endif 0
return


sub fire
begin
5000 1 servo 
500 delay
5000 2 servo
500 delay
5000 3 servo
500 delay
7000 1 servo
500 delay 
7000 2 servo
500 delay
7000 3 servo
500 delay
repeat

Thanks alot, any help is appreciated :slight_smile:

Hello.

It looks like your button_push code is being written in an imperative way rather than a stack-based way. Try reading over the part of the Maestro user’s guide where you took that comment from. You can get there by searching for “Using a button or switch to control servos.”

Something like:

0 get_position 500 less_than  
if
  fire
endif

is probably what you want.

- Ryan

Ryan
Thanks