All eventhandled code in a single view?

Is there a way to edit all the code inside the eevent hanler windows in one only view?

I mean, i have several buttons, each of them have a peculiar code inside each button’s event handler window.
When i have to edit, for example, in 50 different button presshandler event, i find very boring to edit
50 times the same thing for 50 buttons

Indeed, it would be very nice to have a separate ‘code page’ where you could create functions and reference code from anywhere else in your project.

1 Like

There is a way to come close to that: put your code in the touch event of a 1x1px hotspot which you “hide” somewhere in a corner and give a name, for example “func”. Use a global system variable, for example “sys0” to hand a parameter over.
In all buttons, only two lines of code:
sys0=1 // or any other value, depending on the button
click func,1

That’s it. Your hotspot function will then be executed with the parameter (which varies from button to button).

You might even store a second function in the release event of the hotspot and call it with click func,0.

I think another way is do not put any button on the page. You can use system variables tch2 and tch3 to judge which area is click. And write the function in the page event.

That’s also a good idea, but it risks to not work correctly on capacitive screens with multi touch…

Actually the buttons are “fake” buttons, touch insensitive, hidden.
I use them to avoid a cyclopic function with a lot of conditional jumps(if).
To be clearer, button’s name are func1, func2 etc.
I only simulate the click (click func1,1).

I have to respect a certain trigger coming from arduino serial port
i can afford a certain delay(async), between trigger from arduino and reaction in nextion (the startin of the function, that is, the code in the event) but not too out of synch.
I’s impossible to obtain a PERFECT synch, but what i want is
something not so “delayed” from trigger.
I decided to write in nextion 96 functions, too much for my arduino sRam, wrapped as 96 touch events.
This way all the weight of coding is in nextion, that have much more disponible sRam.

Your suggestion is good, but, if i ain’t misunderstood, at the end, i have to use 96 “if” blocks, that is
something delaying too much the response.

Originally i made it all in ONE code window(96 if blocks), but the delay qas too much.
So i “hacked”, using 96 separated functions, disguised as 96buttons event handlers.

So, async is bearable, but now i have the problem that, for minimal change that affects all “conditional buttons”, i have to write the change 96 times in 96 different code windows.

Ooh, it’s terrible, used to programming in C++, to adapt your coding to a lot of strange limits.
No cretable function, no panoramic vision of the code, no arrays (real arrays, i mean), no custom variables.
That’s a pity to have a remarkable amount of sRam for code and at the same time to have to use it
without these features.

I can undestrand return character instead of “;”, Basic do this way.
It’s good to have a visual ide, almost like VS philosophy, but, what a terrible
“poverty” of features!

I just do some research work on Dacai HMI system today. Their product support LUA language. So you can write a lot of deal in a script file. Maybe it is better for you. But a lot of set still in seperaterly.

Naturally, 96 ifs are too much. But I wonder (not knowing your project in detail) why you don’t rather switch over to a more powerful (and often less costly) MCU instead of delegating work to a HMI which is neither intended nor optimized for taking over classical MCU tasks?

Customer cost/Our gain ratio business.
I could use for example raspberry (40 U$) + reliable tcouch screen
(PI Official Tft, 70 U$).
Our product cost MUST be 100 U$ around.

So, I and my business partner MUST use arduino Nano and an Itead tft
big enogh to use comfortably.

That is, we have to reduce microcontroller costs, pointing up to a very reliable
tft, that Nextion is.
Plus, we strictly need a certain drwaing speed.
For all of that we have to use the poor memory of an arduino.
When i found Nextio i charghed as much as possible the code on it.

It’s, apparently, at the moment the only way to reduce the costs.

woow thanks a lot.
Very curious, i run searchin something about. Lua, i kne, i don’t remember, were it something used in producing graphical results or i don’t remember well?

Infact I haven’t us any products from DACAI before. But I check the document on their website and found that some of their products support LUA. They define some LUA api for their product. I copy a sample code from their document to here. I think it is more like a common code.

function on_control_notify(screen,control,value) \Here define the call back functions when control event happen.
if screen == 0 and control == 1 and value == 1 then \ This is a button (control id 1) on screen 0, is cliked.
set_text(0,2,“HELLO LUA”) \Set a text (control id 2) on screen 0

So all the deal could right in a same script file.

!!! Good! Thanks a lot

You are welcom. If any one have interesting to know any more information about related products in Chinese market, please let me know. I will try my best to help.

It sounds great! Thanks a lot