Unofficial Nextion/TJC User Forum

Bizarre behavior in code

Hello,
I just spent two hours troubleshooting the following code:

// Add panel average voltage to waveform
for(ktrend=60;ktrend>=1;ktrend–)
{
for(kreg=1;kreg<7;kreg++)
{
add 149,0,b[ktrend].val/10
}
}
// Add battery average voltage to waveform
for(ktrend=120;ktrend>=61;ktrend–)
{
for(kreg=1;kreg<7;kreg++)
{
add 149,1,b[ktrend].val/10
}
}

This is not complicated code. But the code refused to enter the inner loop of each nested FOR. After dozens of attempts at adjusting the indentation and using various debugging tools, I decided to just retype it. I retyped it exactly as is, and it worked.

I cut and pasted the original code into a button, so see if I could force it to run. It did not.

So there is something about the way it was typed that affected the way it ran. If someone could explain this to me, I would appreciate it.

Question, when I type a variable name, and Nextion shows a pop up box with the name of the variable, can I keep typing, or do I have to hit enter in order to make sure Nextion knows this is a variable?

AKG

Normally, this code should not work. If it runs occasionally, that’s probably a bug.

is not valid Nextion code, operations in parameters are not allowed. The correct implementation would be like
sys0=b[ktrend].val/10
add 149,0,sys0

Thank you for pointing this out. I will double check it. I wish the compliler would draw attention to these.

AKG

I just want to follow up with this. The code does run. Perhaps it’s not supposed to, but it does run.

But the code refused to enter the inner loop of each nested FOR. After dozens of attempts at adjusting the indentation and using various debugging tools, I decided to just retype it. I retyped it exactly as is, and it worked.

The short answer is: what you experienced is not supposed to happen and from your description I cannot see a plausible explanation. Hence it would be helpful to have an example file that demonstrates each case such that other people can have a look at it and investigate the problem on their own.

I cut and pasted the original code into a button, so see if I could force it to run. It did not.

The not working code…? From where? Anyways. Example files are the way to go.

So there is something about the way it was typed that affected the way it ran. If someone could explain this to me, I would appreciate it.

Question, when I type a variable name, and Nextion shows a pop up box with the name of the variable, can I keep typing, or do I have to hit enter in order to make sure Nextion knows this is a variable?

No, this does not make a difference. Nextion is not indentation sensitive, nor is sensitive to copy/pase. Also, Nextion does nothing smart during autocomplete (or at any other moment). Autocomplete just types the letters for you.
The HMI file - which is compiled into the TFT file that will be uploaded to the device or run in the debugger - doesn’t contain anything complex/smart/… The device properties (model, orientation, encoding, etc), a list of all your pages, each one with a list of components, each one with its attributes just as you see them in the editor (yes, when you open it in an editor you’ll see id[value]type[value]objname[value]...). No other information. The code events are also stored line by line as you typed and see them in the editor. No hidden variables/links/… Your text and int32 values. That’s all there is.

Btw. you can let Nextion do the indentation automatically by switching the code view to another event (f.ex. switch from touch press to touch release event and back). You’ll see that the editor has adjusted the indentation. Just to repeat, no, it does not make a difference. It’s only cosmetics.

Kind regards,
Max

We have perhaps to accept that the Nextion compiler is simple compared to, for example, the GNU C compiler which has grown over 30 years with worldwide contributions and a much wider user base. We shouldn’t maybe expect the same degree and deepness of plausibility checks and qualified error messages but deal with little things which appear sometimes to be incoherent.

The compiled tft is only one side of the medal. Most commands have also to be interpreted in the same way at runtime when they are issued over serial. And that with very restricted firmware memory, especially in the T series.

Thank you very much for your help on this. I know it’s not perfect, but it’s a pretty nice screen for the cost.

I have also found that retyping (what appears to be 100% correct code) has fixed compiler errors.

This often comes about when you are renaming variables, and use cursor left arrow to “backspace” and start retyping and then use the delete key to delete characters forward of where the cursor is parked.
(hard to describe, but you might understand?)

Have been caught many times with this.
Best to cursor to the end of the variable name, and use the real (destructive) backspace and then retype.

I believe the autocomplete gets itself knotted up or confused unless you backspace properly.
(My projects are typically 20+ pages and lots of components and code on each page, so quite involved)

The same can happen around use of if/else, the Editor seems intolerant of line feeds, spaces, and not accommodating various typing habits.

Don’t dare suggest the Editor has problems, or the wrath of Patrick will follow. :wink:

$0.02

Thank you. This is what i suspected, that while editing variable names, but not retyping them, it seems the compiler needs to be reminded that the name has changed.

Who is Patrick?

Patrick is one of the Nextion Forum‘s admins and Nextion‘s sales representative in Canada.
For reasons which I ignore, people blamed him for several presumed hardware and software problems around Nextion in the past, although he doesn‘t seem to have any direct influence or impact on the Editor development.

For example, in past times when the Nextions could only display fonts with fixed letter width, he developed a complex workaround in Nextion logic. This solution was then sold to interested customers through enhanced support tickets. Years later only, the developers in China integrated a similar functionality into the Editor and variable font spacing became available for free to everybody.

As a forum admin, he fights vehemently against everything which smells like violation of Nextion‘s intellectual property (reverse engineering etc.) which is the official Nextion code of conduct, not forcibly his own, I presume.

I did not want to suggest that simple means bad. If “simple” is enough to fulfill your needs, then anything more complex would probably be a waste of time.

While the resources certainly are limited, the TFT file shows that Nextion/TJC don’t go for the most efficient way by any means. F.ex. I can’t figure out how having dedicated instructions for a=a+1, a+=1 and a++ helps with keeping the memory footprint low.
So yes, their product/ecosystem certainly has a couple advantages and depending on your use case it makes your life very easy. And yes, sometimes they do provide support and help as one would expect. I reported a bug and it got fixed with the latest release. Great, except that they blocked me in their forum.
But the truth is, their product and their support is far from being perfect either. And I don’t mean that it is limited. Of course it has limits and that’s fine. What I mean is that each TFT file contains 65kB(!) of 0xff that are simply dead weight (131kB for intelligent series files - that’s ), that there are 3 (!) dedicated instructions for a=a+1, that there are equally 3 (!) dedicated instructions for a=a-1, that they edit your posts to make you look bad/stupid/criminal/… if they don’t like what you said.
tl;dr they are not perfect in the sense that there’s no valid/logical reason for some things to be the way they are and that some of their actions are the opposite of customer friendly.

Years later only, the developers in China integrated a similar functionality into the Editor and variable font spacing became available for free to everybody.

This is only half the story. The full story is that Nextion/Patrick asked 125$ for a single size of a single font plus a (quote!) “motivate me fee”. And when the devs at TJC indeed published a new version that allowed anyone to make their own proportional font, Nextion was holding back updates for well over a year and continued to make money with their expensive fonts. They didn’t let you download version 0.54, 0.55, 0.56 and 0.57 (full support for those fonts was introduced in 0.55). By doing so they denied access to all other new features, improvements and bugfixes that were included with those updates. This behavior is what pissed off so many users. Not only were they forced to pay hundreds of dollars for a feature after it had been available for free (in the chinese version), no, in addition to this “premium” they were stuck with an inferior and older version that didn’t even support if/else (introduced in 0.54). Can’t blame anyone for feeling ripped off by that. It’s one of the reasons why people started hacking the chinese editor to english.


To come back to the topic: I honestly didn’t know about that bug; never faced it. I guess the issue is only in RAM then? Meaning that saving, closing and reopening the file solves the issue? If not, I’d still be interested in demo files.

Regards,
Max

It’s just that nobody was forced into paying for variable width fonts. After it had been shown that it was possible within Nextion logic, everybody could have done it by themselves.

And I’m not sure that holding back Editor versions from 0.54 to 0.56 was motivated by that. These versions were issued by TJC with support for the then new X5 displays. I’d rather guess that it made no sense for Nextion to translate and publish these as long as their version of the X5, the so-called intelligent series was not ready and certified for the markets outside mainland China.

We’ll most probably never know or understand what happens behind the Chinese wall and how the exact relationship between TJC and Nextion is defined.

But I’m almost certain that “externals” like Patrick are not always to blame for decisions which are obviously taken in Shenzhen, China.

Edit after going through my own HMI collection: if/else was introduced in 2016 with v.0.33. Not sure why you see it in 0.54…

You’re right, I misread the TJC release notes. It was actually the option to use || and && with if/else and while, not the control statements themselves. Still a very useful feature. Just as proportional fonts, upload protocol v1.2 and support for baudrates up to 912600 - all things introduced within those “blocked” versions.

Even if you were right and it was not because of money that they denied the users access to updates for over a year I have a hard time believing this resulted in any benefit for the customers. Thus I still think my main point remains valid, customers paid (a lot) more and got less.

Kind regards,
Max

Please don’t take me wrong Max, I’m not intending to be right, here, that’s absolutely not important to me, but I perceive some comments and reactions in this forum as rather speculative and emotional, based on guesses and assumptions. Being myself a rather unemotional and analytic personality type, I feel sometimes just the need to point out that other explications for the same phenomenons can exist and have a similar probability - independent from my personal opinion.

Since we are far away from Shenzhen, none of us will ever know the absolute truth, and at the end, it’s not important. In their eyes, they have probably valid reasons even if these remain intransparent or questionable to us.

I for myself will continue to take things just as they come and as they are, and make the best of it. It’s like standing out in the wild with car problems. Blaming Lada for not putting a spare ignition cable into the onboard toolbox won’t get me back on the road - I’ll have to be creative and find a workaround by myself. Thus, I never will, neither in the TJC/Nextion context nor in any other one in my life, waste lifetime and energy in trying to change things which I simply can’t change.

Sorry for this excursion in the philosophic domain…

1 Like

Hi,
Some stupid remark eventually, I see only a single minus sign behind the variable (ktrend-).
Shouldn’t that be two minus? (ktrend - -)

Saw that, too, but that seems to be the forum software; after all you had to separate them by a space, too. I’m pretty sure if he formatted it as code (using ``` at the beginning and end of the code) it would have remained 2 individual characters.

Kind regards,
Max

Yes, it is written as - -. It is easier to read in the IDE. The code was written correctly. It just didn’t run. The code was in a timer event. I cut and pasted the code into a button event. It still didn’t run. Then I retyped it and it ran. It was like the compiler didn’t even see the loop.


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).