Hello team.
I'm in the process of creating a batch of additional new variables to accompany a number of previously-created associated variables.
I presently need to copy created variable names to save time manually entering the names of similar new variables, each created one-by-one with associated var type and default value fields. It would therefore be really useful to be able to duplicate variables in the drop-down, just as one can presently do with macros (i.e. duplicated with "...copy" at the end).
Many thanks,
Brendan
Duplicate variables, as with macros
-
Brendan
- Posts: 72
- http://meble-kuchenne.info.pl
- Joined: Tue Dec 08, 2020 2:12 pm
- Has thanked: 59 times
- Been thanked: 16 times
-
mnfisher
- Valued Contributor
- Posts: 1763
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 148 times
- Been thanked: 831 times
Re: Duplicate variables, as with macros
Hi Brendan,
Take a look at using local variables - in each macro. then they will be copied / created as required and the danger of unpleasant side effects (due to using the wrong variable!) is minimised...
Martin
Take a look at using local variables - in each macro. then they will be copied / created as required and the danger of unpleasant side effects (due to using the wrong variable!) is minimised...
Martin
-
Steve-Matrix
- Matrix Staff
- Posts: 1688
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 242 times
- Been thanked: 400 times
Re: Duplicate variables, as with macros
Martin makes a good point and I would second using local variables where possible.
Also, I have added a rudimentary copy/paste for variables which should be available in the next core update of Flowcode v11.
Also, I have added a rudimentary copy/paste for variables which should be available in the next core update of Flowcode v11.
Re: Duplicate variables, as with macros
Thanks Martin, Steve.
I mostly use local vars where possible (e.g. local loop counters and such), though others are global for system-wide control so that values are preserved when macros close, or may be updated by ISRs and cleared by the main program (e.g. UART string indexers, etc).
Often I have many globals used this in way, each similar in characteristics but repeated with different names for different controls (e.g. stepper counters and ramp controllers), and a latest project involving multiple displays and creation of multiple shapes, with separate arrays (each intuitively-named) controlling X, Y, Z, Size, etc., on each connected display. This is where it gets somewhat tedious repeating the process of duplicating global variables/arrays for many such peripherals and controls.
Thank you Steve for adding the variables copy/paste function for FC11, particularly as I acquired the complete professional FC11 suite a few days ago
Best regards,
Brendan
I mostly use local vars where possible (e.g. local loop counters and such), though others are global for system-wide control so that values are preserved when macros close, or may be updated by ISRs and cleared by the main program (e.g. UART string indexers, etc).
Often I have many globals used this in way, each similar in characteristics but repeated with different names for different controls (e.g. stepper counters and ramp controllers), and a latest project involving multiple displays and creation of multiple shapes, with separate arrays (each intuitively-named) controlling X, Y, Z, Size, etc., on each connected display. This is where it gets somewhat tedious repeating the process of duplicating global variables/arrays for many such peripherals and controls.
Thank you Steve for adding the variables copy/paste function for FC11, particularly as I acquired the complete professional FC11 suite a few days ago
Best regards,
Brendan
-
mnfisher
- Valued Contributor
- Posts: 1763
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 148 times
- Been thanked: 831 times
Re: Duplicate variables, as with macros
Hi Brendan,
Sorry - I'd just been looking at a (very) large program with NO locals and my head hurt.
Use of globals for 'state' storage is a necessary on MCUs for sure - although it's still somewhat contentious - Id recommend 'The Pragmatic Programmer' and 'Clean Code' - both of which are very readable. Issues can arise where values are changed in multiple places (or in multiple threads - esp32 for example). There are many suggestions out there - even going as far as using a database to hold the current context - obviously not on a MCU!
In my opinion it's a slight weakness in FC - for example 'structs' to keep related variables together and enumerations (for 'related' constants) would improve things. The display of variables especially if there are many could be enhanced too.
I'm sure Steve is looking at such things!
A way to create multiple variables without resorting to the mouse would also be good - note that you can do 'a,b,c[12],d,e' as the variable name and in this cae it will create a,b,d,e and c[12] - where the variables have the same underlying type (byte, int etc). It used to be that you could create one variable, then press enter and create a second - but then had to 'click add' for a third.
Also on the wish list - constants should be useable in other declarations - for example constant buf_size = 10 and then buffer[buf_size]...
Anything to help create more readable, reliable and maintanable code
Martin
Sorry - I'd just been looking at a (very) large program with NO locals and my head hurt.
Use of globals for 'state' storage is a necessary on MCUs for sure - although it's still somewhat contentious - Id recommend 'The Pragmatic Programmer' and 'Clean Code' - both of which are very readable. Issues can arise where values are changed in multiple places (or in multiple threads - esp32 for example). There are many suggestions out there - even going as far as using a database to hold the current context - obviously not on a MCU!
In my opinion it's a slight weakness in FC - for example 'structs' to keep related variables together and enumerations (for 'related' constants) would improve things. The display of variables especially if there are many could be enhanced too.
I'm sure Steve is looking at such things!
A way to create multiple variables without resorting to the mouse would also be good - note that you can do 'a,b,c[12],d,e' as the variable name and in this cae it will create a,b,d,e and c[12] - where the variables have the same underlying type (byte, int etc). It used to be that you could create one variable, then press enter and create a second - but then had to 'click add' for a third.
Also on the wish list - constants should be useable in other declarations - for example constant buf_size = 10 and then buffer[buf_size]...
Anything to help create more readable, reliable and maintanable code
Martin
Re: Duplicate variables, as with macros
Hi Martin.
Thank you again for your help and support - Appreciated entirely!
Best regards,
Brendan
This is certainly something that I wasn't immediately aware of, and will be most useful for immediate purposes!A way to create multiple variables without resorting to the mouse would also be good - note that you can do 'a,b,c[12],d,e' as the variable name and in this case it will create a,b,d,e and c[12] - where the variables have the same underlying type (byte, int etc)
Thank you again for your help and support - Appreciated entirely!
Best regards,
Brendan
-
chipfryer27
- Valued Contributor
- Posts: 1790
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 402 times
- Been thanked: 618 times
Re: Duplicate variables, as with macros
Hi
The ability to create multiple variables at once (x, y, z etc) was news to me until I read about it in Everyday / Practical Electronics.
Medelec35 wrote a few articles on Flowcode for the magazine. Well worth reading.
Regards
The ability to create multiple variables at once (x, y, z etc) was news to me until I read about it in Everyday / Practical Electronics.
Medelec35 wrote a few articles on Flowcode for the magazine. Well worth reading.
Regards