Start a new topic

either GOTO / or / RETURN / or / SWITCH(){ case 1: default: }

 the language of Nextion is good.  It would be good to be able to use a "return" statement to avoid executing code below a taken "if", or a "goto" to allow bypassing code, or a switch() statement (similar to C) which would pretty much do everything needed.

Nextion is not a language, but a few commands.

To avoid executing code below a specific point:

  - create a variable(s)

  - conditionally (based on variables) skip over said code.

Nextion remains interpreted sequential commands

<smile>  A rose by any other name is still a rose.  You have enough elements to classically be called a language.  However....


  No problem, your interpreter is good, and fast.  The fact that timers are truly asynchronous is an interesting phenomenon which can be useful.

  Yes, your option works.  I didn't think of that, but in my case there would be so many variables it would have been very unwieldy.

   I got around the issue by writing my if statements in reverse order, high to low.  Interestingly, "else if" did not appear to work properly.  I must not understand else if properly. <laughing at myself>

Another possibility is to use the click command as a jump out to elsewhere, I have to try a few tests, but I am not certain that click can return to next point after click completion.  But a few 5x5 pixel pictures or hotspots as code holders, the click command can create some interesting control structures.

Hmm.  Would have to test.  Interesting.  Basically you are saying it is the equivalent to a "goto the other control"

In that case, labeling the control "return" would be an interesting statement:  click return,1

Okay, so click commands that do not call page command will return to next statement

two buttons, two numbers

b1 pressed event

  click b2,1



b2 pressed event


So conditions would still need to be created to bypass


  if b2 pressed toggles variable "handled"

  then maybe

if(condition.val==1) {

  //code for case 1

  click b2,1 // set handled


if(handled.val!=1) {

  code to skip


// code all will return to

The implication is that if a "page" command is executed, the click will not return.


b1 pressed event

  page myself

if (contidion.val==1){

  // execute code 

 click b1,1


 would not return to the executing code.

  So, if you named your button "return"....

The issue if changing page with page myself is

this will restart the myself page from the beginning

- page preinitialize event

- page reset as per the HMI design

- page positinitialize event

If that is sufficient - but most often is like restarting

 less of a "goto"

(How many bytes needed - other thread)

Yes, just ran into that in the debugger.  can easily be an infinite loop....not a good solution....

perhaps a "stop"  to stop execution of the command processor?  That would be the equivalent of a "return", but would fall within the paradigm of a command execution processor.

some Nextion coding tricks ...

assume that

    - jump to another page will always break a running script
    - scripts dont run parallell
Lets think which construct match or come close a construct of another language ...

    - click object,state - triggers a script on same page without parameters  - SUB/FUNCTION/GOSUB comes most close
    - click object,state with set parameter variables - triggers a script on same page  - SUB/FUNCTION/GOSUB comes most close
    - page pagex - reset all non globals and call new scripts - SUB/FUNCTION, global declared can be used
    - timer - can run automaticaly or on command and repeat itself - SUB/FUNCTION/GOTO/GOSUB

and so on ...

To break a running script on a given condition, you must order your code into logic blocks ... Furthermore just add a runnextblock variable ... like

// SCriptStart
// Block1

// Block2

// Block3

// Block4

// Block5


To make that a called page will execute conditional scripts, just use one global variable, which is set to an execution level value ... so it is also possible to call different command alike structures on different pages.

With sys0-sys2 you even have globals for shifting parameters and results between pages without additional declarations ...

It is not exactly what other real languages offer, but with a bit of rearanging your logic, nearly all can be accomplished ...

In my case, I had a choice of a variable being 1-5,2-28,30-35,40-48,....

I had to make a decision on being greater than something.  I simply had to arrange my if statements backwards (from a counting point of view) and modify the variable dramatically so as not to trigger any other if statement.

A "switch" construct, or a "stop", or a "goto" all would have made my job easier.  I am lazy.  I was just asking. :)

As I said before, I was able to accomplish by re-arranging.  I have use timers as repeating subroutines by enabling/disabling them in code.  I had not thought of using touch events as a subroutine, but it makes obvious sense.

Just saying that a "stop interpreting here and go away" construct (at a minimum) would be very useful for extremely lazy programmers such as myself.

That being said, your display is extremely useful, your command processor works well and runs without memory leaks that we can tell, and it hit a very good spot for our products.  We expect to be purchasing hundreds over the lifetime of the products we are designing now.

Final word: you don't have to change anything, it is definitely good as it is.  Is just a feature request. :)

the Nextion is an ongoing project. We daily work on to bring it to its limits and enhance it where possible.

but every change must be thought twice, one change and maybe a rats tail of endless issues will come out ... especially with the limited ressources we do use ...

but nevertheless, every Feture Request is taken seriousely to our big list ... :-)

  I fully understand.

   rats are hard to kill......

   BTW, rats with seniority are called features.....

Bad news, your application didn't sound like it could afford lazy.

Picture / Hotspot components make good touch code holders.

Press click obj,1   Release click obj,0 ...

if you embed printh 65 03 02 01 FF FF FF

  [03 page, 02 component, 01  touch (01/00)]

  you can effectively simulate send component id and MCU is notified

yep.  had to type a few more characters into the ide.  :(

understood.  Nextion in concept is brilliantly simple.

Login or Signup to post a comment