Constants

Snurre

Well-known member
For a long time I've been wondering why there ain't the possibillity to use constants in MD, I think it's a very common thing ๐Ÿค”

It could be useful in different scenarios like calculating C to F, systemtime to d/h/m and so on. There a several places where it could be useful, I think

If you a fooling around (like me) with a lot of variables and macro's, it is easy by mistanke to change the value of a wrong var with some "funny" result in different macro's

So my suggestion is the option to make constants, or somehow make a var readonly (wich gives a constant s ๐Ÿ˜‰)
 

Dm114

Well-known member
Hi dear "old Viking" ๐Ÿ˜‰

I'm not sure I really understood your request. Do you mean you would like to have variables (containing constraints) with a kind of "read only" feature?

If you use local variables, you only can modify them with the macro they are assigned to. Unlike global ones that can be modified by any macro referring to. Maybe using local widely could be a part of the solution.

I also sometimes have this problem while modifying/improving a macro and when, because of a bug while testing, it destroys the content of an important variable! To avoid that, I generally make a copy of the macro before messing it up. ๐Ÿ™‚

When you speak about "calculating C to F" do you mean "converting temperatures from โฐC to โฐF"? It's not a single constraint but a formula which is needed to convert. If you are interested, you could download and use this system I wrote a couple of years ago and I use from time to time:

According to a kind of "read only" feature, I'm thinking about a very simple Block action that could simulate that... Tell me if it's what you are looking for and I will put my brain on the job! ๐Ÿ˜‰๐Ÿ™‚
 

Snurre

Well-known member
Hi dear "old Viking" ๐Ÿ˜‰

I'm not sure I really understood your request. Do you mean you would like to have variables (containing constraints) with a kind of "read only" feature?

If you use local variables, you only can modify them with the macro they are assigned to. Unlike global ones that can be modified by any macro referring to. Maybe using local widely could be a part of the solution.

I also sometimes have this problem while modifying/improving a macro and when, because of a bug while testing, it destroys the content of an important variable! To avoid that, I generally make a copy of the macro before messing it up. ๐Ÿ™‚

When you speak about "calculating C to F" do you mean "converting temperatures from โฐC to โฐF"? It's not a single constraint but a formula which is needed to convert. If you are interested, you could download and use this system I wrote a couple of years ago and I use from time to time:

According to a kind of "read only" feature, I'm thinking about a very simple Block action that could simulate that... Tell me if it's what you are looking for and I will put my brain on the job! ๐Ÿ˜‰๐Ÿ™‚
Hey my friend๐Ÿ˜‰
It's not exactly what I meant, I'm talking about constant not constraint
In every (I think) programming language you can use different data types, among that, variables (dynamic) and constant (static)
I know MD is not a programming language, but a little bit "programming lite" ๐Ÿ˜Š
Local var is ok, but I'm using quite a bit globals in some different macro's, so I think it would be much easyer to declare a const, instead of your suggested 'Action Block', which could work fine
And about conversion of C to F, it was maybe just a bad example, there could be many situations where a certain formula or value should be used over and over again, in different scenarios
But thx for your input
Take care ๐Ÿค—
 

Dm114

Well-known member
Hey my friend๐Ÿ˜‰
It's not exactly what I meant, I'm talking about constant not constraint
In every (I think) programming language you can use different data types, among that, variables (dynamic) and constant (static)
I know MD is not a programming language, but a little bit "programming lite" ๐Ÿ˜Š
Local var is ok, but I'm using quite a bit globals in some different macro's, so I think it would be much easyer to declare a const, instead of your suggested 'Action Block', which could work fine
And about conversion of C to F, it was maybe just a bad example, there could be many situations where a certain formula or value should be used over and over again, in different scenarios
But thx for your input
Take care ๐Ÿค—
Hi my "Viking biker" friend,

I made a mistake (due to the keyboard) and, somewhere it wrote "constraint" instead of "constant". But I was really speaking about constant.

As soon as Action blocks are "repaired" (a small bug since v5.25.5) I'll send you what my lazzy brain found... ๐Ÿ˜‰

Take care.
 

Dm114

Well-known member
For a long time I've been wondering why there ain't the possibillity to use constants in MD, I think it's a very common thing ๐Ÿค”

It could be useful in different scenarios like calculating C to F, systemtime to d/h/m and so on. There a several places where it could be useful, I think

If you a fooling around (like me) with a lot of variables and macro's, it is easy by mistanke to change the value of a wrong var with some "funny" result in different macro's

So my suggestion is the option to make constants, or somehow make a var readonly (wich gives a constant s ๐Ÿ˜‰)
Hi my friend, hi to all who could be interested,

I created these 2 tools the same day we spoke about and was ready to send them for you but I had to delay them a bit because of some technical problems: a small bug that will be fixed in the very next release and a feature that will come later and I had to deal without...

It's a way to have PROTECTED VARIABLES with fixed content/value you cannot modify by accident in any macro (such as constants). To get their content/value wherever you need in a macro just replace the common MD Set Variable action by the ๐Ÿ”GetVAR Action Block. To create, update or remove these PROTECTED VARIABLES, use the ๐Ÿ”UpdtVARs macro.

I hope it will suit your needs!

Take care.

๐Ÿ”GetVAR link: https://www.macrodroidlink.com/macrostore?id=13089

๐Ÿ”UpdtVARs link: https://www.macrodroidlink.com/macrostore?id=13090
 
Last edited:

Snurre

Well-known member
Omg, what a work for making a constant
Thx my friend, I will have a closer look at it tomorrow
 

Dm114

Well-known member
Omg, what a work for making a constant
Thx my friend, I will have a closer look at it tomorrow
I don't think it's so restrictive:
- just the standard MD action (Set variable) to be replaced by ๐Ÿ”GetVAR Action block every time you need to get a constant content or value with 2 parameters only (the name of the "protected variable" and the name of the variable you are using in your macro). No more than with the Set variable action.
- a special macro (๐Ÿ”UpdtVARs) to update these "constants" to avoid them from being altered by accident.

I'm eager to get your opinion...

Good night and see you tomorrow.
 

Dm114

Well-known member
I don't think it's so restrictive:
- just the standard MD action (Set variable) to be replaced by ๐Ÿ”GetVAR Action block every time you need to get a constant content or value with 2 parameters only (the name of the "protected variable" and the name of the variable you are using in your macro). No more than with the Set variable action.
- a special macro (๐Ÿ”UpdtVARs) to update these "constants" to avoid them from being altered by accident.

I'm eager to get your opinion...

Good night and see you tomorrow.
Not sleeping yet? ๐Ÿ˜‰๐Ÿ™‚
Here it's 1:20pm
 

Dm114

Well-known member
Omg, what a work for making a constant
Thx my friend, I will have a closer look at it tomorrow
Just made an update of ๐Ÿ”UpdtVARs macro to add a new feature.

It's now possible to enter a mathematical formula or functions when creating/updating a PROTECTED VARIABLE. The formula must begin by the equal sign "=" and the result will be stored as a decimal value.
 

Qarboz

Well-known member
Although I don't understand much, I'm sure your action blocks work. But I think the following macro is simpler

Constant.png

If you need to add a "constant" just add a trigger and an action
 

Dm114

Well-known member
Although I don't understand much, I'm sure your action blocks work. But I think the following macro is simpler

View attachment 3039

If you need to add a "constant" just add a trigger and an action
The goal is not exactly the same.

The initial goals are:
- to have values (constants) accessible from anywhere (any macro). It's the reason why they must be global (not local)
- as they can have any (convenient) name, they are gathered in a dictionary, not to be spread out anywhere
- to avoid to alter them by accident in a macro (accidental Set variable action mainly during tests), each macro works on its own variables (local or global) and never reaches the "protected" ones
- these "protected constants" are used to initialize relevant variables (from almost any type) inside the macros that need to use their content like a common Set variable action.

It's the reason why an Action block (๐Ÿ”GetVAR) does that rather than a simple Set variable action.

About ๐Ÿ”UpdtVARs macro, it is made to update more safely and conveniently these protected variables rather than initializing/modifying them by hand in the global dictionary. Besides, when you have a dictionary, you can manually rename a key (variable name) but it's not possible to remove one: you must delete the dictionary itself and then recreae it with the appropriate keys and values...

Of course these 2 modules are made for some advanced users' special needs.
 
Last edited:

Dm114

Well-known member
It also can be used to store some text used in menus of various macros. They can be modified outside these macros and their modification will impact all the macros without having to update each text in every macro... ๐Ÿ˜‰
 

Snurre

Well-known member
My friend, I've got a problem โ˜น๏ธ
I have tryed different things with your macro, and creating a var works pefectly
But when I try to get the value, I just can't get it to work
Maybe I just don't get it right, am I missing something?
Screenshot_20220713_132237.jpg Screenshot_20220713_132019_com.arlosoft.macrodroid.jpg Screenshot_20220713_132323.jpg
 

Dm114

Well-known member
Hi my friend,

As there were some MD bugs on dictionary manipulation, I would suggest you to download the last 5.26.1 MD version, as well as the freshest version of my 2 macro/Action block.

All you did seems to be correct but as the content of your protected variable called "Day" is a number (3600) you'll get the value as an output decimal or integer variable. You could retrieve it in your own local/global variable also called "Day" inside your macro instead of "nr".

Anyway there's something very strange I'm discovering: the global dictionary ๐Ÿ”ProtectedVARs contains some of my old test variables. Does it mean it came with the macros when you downloaded them?
 

Snurre

Well-known member
Hi my friend,

As there were some MD bugs on dictionary manipulation, I would suggest you to download the last 5.26.1 MD version, as well as the freshest version of my 2 macro/Action block.

All you did seems to be correct but as the content of your protected variable called "Day" is a number (3600) you'll get the value as an output decimal or integer variable. You could retrieve it in your own local/global variable also called "Day" inside your macro instead of "nr".

Anyway there's something very strange I'm discovering: the global dictionary ๐Ÿ”ProtectedVARs contains some of my old test variables. Does it mean it came with the macros when you downloaded them?
Yep, it made the variables itself, just read another post about it
And I have the newest MD
 

Dm114

Well-known member
I've got this just by downloading
View attachment 3043
Does it mean you also got the other mentioned macros? You only should have the macro ๐Ÿ”UpdtVARs and the Action block ๐Ÿ”GetVAR. Nothing else! The other ones were copies while testing the main ones (as you probably understood) and the BOOL boolean variable doesn't exist anymore.

I think there's a problem with exporting Action blocks...

Did you download the newest versions I uploaded yesterday. As I have a doubt, I wanted to upload them now but something goes wrong: both uploads fail today!

Anyway I just improved them a bit yesterday, adding a new functionality, but didn't change the logic that should work correctly. I remember that when I was making my tests, MD sometimes crashed or gave me odd results (as yours). Without changing anything, I sometimes restarted my device (not only MD) and then everything was clean...
 
Top