formula with set_variable
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
- IIIO_METAL
- Posts: 202
- Joined: January 18th, 2017, 5:03 pm
- Location: japan
formula with set_variable
It may be a stupid question, but I'm in trouble because I don't know the answer.
I want to addition using formula with set_variable, but it don't work.
I want answer = 3, but the actual value is empty.
Also, if the number part is replaced with a variable, the character strings will be concatenated.
The value is 12.
I don't know what's wrong. Please tell me how to addition.
I want to addition using formula with set_variable, but it don't work.
Code: Select all
[set_variable]
name = answer
formula = $(1 + 2)
[/set_variable]
Also, if the number part is replaced with a variable, the character strings will be concatenated.
Code: Select all
a = 1
b = 2
[set_variable]
name = answer
formula = $($a| + $b|)
[/set_variable]
I don't know what's wrong. Please tell me how to addition.
Creator of "Mountain Witch" & "Castle of evil spirit"
- Pentarctagon
- Project Manager
- Posts: 5565
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: formula with set_variable
Always put quotes around formulas.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
- IIIO_METAL
- Posts: 202
- Joined: January 18th, 2017, 5:03 pm
- Location: japan
Re: formula with set_variable
Thank you, Pentarctagon!
I arrived at the correct way of writing.
I got answer 3.
I arrived at the correct way of writing.
Code: Select all
[set_variable]
name = answer
formula = "$(1+2)"
[/set_variable]
Creator of "Mountain Witch" & "Castle of evil spirit"
- Celtic_Minstrel
- Developer
- Posts: 2222
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: formula with set_variable
If you're using
The difference between
Obviously there's no reason to use a formula for that specific example (just write
[set_variable]formula=
then the correct way to write it is formula="1+2"
- you don't need the $ at all. Your example is no different from writing value="$(1+2)"
.The difference between
value="$(...)"
and formula="..."
is that in the latter you can easily reference the current value of the variable using self
, whereas in the former you would need to write out the variable's full name preceded by $ in order to reference it. The following two tags are equivalent, for example:Code: Select all
[set_variable]
name=some_container[$i].sub_container[$j].some_value
value="$($some_container[$i].sub_container[$j].some_value + 1)"
[/set_variable]
[set_variable]
name=some_container[$i].sub_container[$j].some_value
formula="self + 1"
[/set_variable]
add=1
), but if you have a very complicated formula you want to calculate, and/or if the variable's name is very long, then using formula=""
may be more convenient than value="$()"
.- IIIO_METAL
- Posts: 202
- Joined: January 18th, 2017, 5:03 pm
- Location: japan
Re: formula with set_variable
Thank you Celtic_Minstrel.
Your commentary was very easy to understand and was helpful.
Sure, 1 + 2 isn't as difficult as using mathematical formulas, but I thought I should practice with simple ones before trying complex math.
And I made a big mistake in the syntax.
But I'm not so shocked.
Well .. I think it's a lot less damaging than finding this mistake after writing thousands of lines of code.
Your commentary was very easy to understand and was helpful.
Sure, 1 + 2 isn't as difficult as using mathematical formulas, but I thought I should practice with simple ones before trying complex math.
And I made a big mistake in the syntax.
But I'm not so shocked.
Well .. I think it's a lot less damaging than finding this mistake after writing thousands of lines of code.
Creator of "Mountain Witch" & "Castle of evil spirit"