-->
Page 1 of 3

Flow control

PostPosted: Mon Apr 04, 2016 1:25 pm
by Electroguard
I'm having trouble trying to understand ESP Basic flow control in the "A NICE TOGGLE BUTTON" example below.
[Toggle] will always branch to either goto [On] or goto [Off}, but neither of them are called using gosub and return, so why doesn't [On] drop on through into [Off] or [Off] drop out to end the program, and what decides where the program flow goes to from the bottom of such branches?

cls
let OutputPin = D4
button "Toggle" [Toggle]
wait

[Toggle]
if PinStatus == 1 then goto [On] else goto [Off]

[On]
PinStatus = 0
po OutputPin 1
wait

[Off]
PinStatus = 1
po OutputPin 0
wait

Re: Flow control

PostPosted: Mon Apr 04, 2016 3:38 pm
by Mmiscool
The wait command tells the esp to hang out and not do any thing untill there is a gui interaction, interupt or timer action.

Re: Flow control

PostPosted: Mon Apr 04, 2016 6:01 pm
by Electroguard
Yes, thanks, that helps, cos now I can see how it staggers from one actioned wait event to the next. I'm still confused how the program can keep repeating though, rather than staggerring once down past each wait event then stopping.

Sorry, as you can guess I don't know much about doing web pages, and I think the button repeating of its own accord must be some sort of webby thing.

I had assumed that the button "Toggle" [Toggle] command simply painted an appropriate button on the page then waited for a click event before becoming lost in history, and therefore program flow would need to be specifically steered back up to the button command for it to become active again... but that's evidently not the case though.


So does it mean that a web button is created which has a continued existence of its own, and will just keep on looking itself for subsequent button-click events to action?

Re: Flow control

PostPosted: Mon Apr 04, 2016 6:05 pm
by Mmiscool
The gui objects get placed on the screen and are persistant untill the cls (clear the screen) command is called. When ever you click the button and the program is in a wait stait. It will exicute the associated branch.