With your last post, I now understand your question on curly braces. In scripting environment (script, expression, control UI, extras), curly braces is not needed at all. But in any other fields in non scripting environment, curly braces is needed to access the variable's content. You can see the element's field explanation, if it has "variables supported", you can put variable there by using curly braces. You can somewhat imagine that all those "variables supported" field has imaginary double quotes, which will translate the curly braces into their value. You can see the difference as you put curly braces, the color will change to cyan-blue, denoting it is a variable. For the ones which doesn't turn cyan-blue after putting braces, most likely that field doesn't support variable.
Let's walk thru the script for the strange part.
this is one of the problem, when there is curly braces, it terminate the value there. Anything afterward + {b} is calculated but not assigned to the d. This cause logic error. So even if you put
d still take the {a} portion only, which is 2. However if you put another assignment in b and c braces, it will assign for each.
d = 2, d2 = 3, d3 = 5. This is useful for multiple script assignment in one line, but I won't encourage this style. I better split them to multiple statement in single line and terminate with semi colon.
There are exception though, when I need to use function, or I want to save additional curly braces in if(), for(), while() block.
e suffer from the same problem, except now it is assigned to string "a", instead of variable a.
Code: Select all
f = "{a}" + "{b}"; // 5
g = "{a}"*"{b}"; // 6
f and g are OK. If you still need the green coloring to identify the variable, use this way. I still don't encourage it, better use c method.
j and l are OK, as both still evaluate to the value of h. But k will evaluate to string "h", hence when you split it, nothing happen, and the result is the "h" alone as the first element.
vertigo wrote: ↑09 May 2020 07:02
And between the two, and thinking about it some more, here's my thoughts:
- Part of my problem is that sometimes I put the quotes inside the braces and sometimes I put them outside, so when things don't work right, sometimes it's because of quoting when I shouldn't be and sometimes it's because I'm quoting wrong.
Don't put curly braces unnecessarily in scripting, as it might cause logic error as shown above (more fatal than syntax error). I sometimes think that the coloring is actually a hindrance, it makes us lazy. I occassionally type a long script in notepad (without any coloring), and then pasting it to script later.
vertigo wrote: ↑09 May 2020 07:02
- Quoting numeric variables works fine when adding, but not with multiplying (and, I assume, it also works with subtraction but not division), which adds to the confusion. And technically, it does work with multiplying, but only when done just right, as in my example vs yours. So it's clear now that, even though it *can* work with numeric variables quoted, it's best not to quote them. It's just confusing because the fact it does often work has led me to think that was the correct way to do it.
Automagic has some of the problem from javascript, such as force variable type. When "1" can be converted to number, it will be converted to number if the next operand is number too. Best way is to avoid this force conversion, as it is very prone to logic error. Especially when dealing with +, as it can be use to add number and concatente string.
vertigo wrote: ↑09 May 2020 07:02
- I prefer quoting variables, since it makes them turn green, which is nice for making them stand out, making the code more readable. I'm used to this in other languages and editors, and not only does it make me prefer to quote them, but it makes it look like the syntax isn't right when I don't, since they're not colored and therefore look like they're not recognized as variables.
- If they're not quotes and/or braced, they look like a letter or word, not a variable. For example, c = a + b above looks like it should either result in ab or an error, like you're trying to add letters, not variables. It just feels like it should be c = {a} + {b} or c = !a + !b or c = %a + %b or something like that, to identify them as variables. It seems everything is a variable unless it's quoted, though. Just seems strange to me.
I recommend to get used to Automagic scripting style. White color should be quite stand out. And if you got undefined variable, you get red underline to notify you. Javascript, python and several other languages also use this method. (c = a + b) I don't think Automagic will change this scripting style.
This works fine here in script action, without braces