Just teaching myself variables - name changes From@ to _


#1

1) Give a description of the problem
I’m trying out some simple uses of variables to learn how to use them. I created some and tried to make them global by adding the @ in front. When it creates them it changes them (in the piston view) to variablename. Ok, no problem, they still seem to do something. But I had them do a household temperature average, and then wanted it to send a text with that variable result in it. But instead of showing me the result in the text (number) I am just getting the word variablename. I tried putting {}. I tried putting the @ back in. I’m sure its something simple, but I can’t tell what.

2) What is the expected behavior?
It will send me a text with the variable calculation result.

3) What is happening/not happening?
It is sending me a text with the name of the variable.

4) Post a Green Snapshot of the pistonimage

Thanks so much!!


#2

To create a global variable, it is not placed in the ‘define’ section of any piston. You have to use the right margin (when editing any piston) to create a global.

By default, variables are blank, so you’d have to write to it first, and then send it. The issue lies using global variables because they are not written to until the piston has finished execution. If you used local variables, it would work immediately.

Basically, I literally have thousands of local variables, and less than 30 globals.

Using locals (whenever possible) should be your general “go-to” practice.

The only time I use global variables is when I need to pass data from one piston to another.


#3

Local variables are created in the piston in the spot you created them. Global variables will be in a section to the right of the piston edit window.

In sending your SMS, you will want to change the notification from a value to an expression in the drop down. Then keep your variable name outside of the quote marks, like this:

The expression text will auto-fill with the evaluation of your expression.


#4

Here is an example using locals, since that should be 99% of the time.


For variables that change often, I always define it up top like this:

temp

This lets me see what numbers were gathered at last run.

If you define up top, you will not have access to that data


#5

Thanks, I knew it would be something easy-ish.

But I am having the following problem. I go to enter it and it shows up in the drop down menu, all good like this. I just used the name it changed it to shown in the top left corner (which I assume is Local).

But when I select it I get this error.

Any thoughts?


#6

Yes, once the piston has been saved (and run once) it will populate the data, and the “cheat sheet” will be helpful for all future edits.


#7

Thanks. I tried it this way and it worked!


#8

Notice how when looking at the piston now, up top in the define section will have:

decimal avgTemp; /* X */

The /* and */ surround the data as last seen by the piston.
You loose that info if you enter in anything up there.


#9

Thanks, I didn’t get that I had to run it once with the error active. Now it works with both methods!
Thanks so much @ WCmore and Brian_D. That really helped me learn!