Help with summing two variables(Solved)

hi,

I have run into a problem with adding two values, and i’m stumped as despite copying literal examples here it refuses to work.

the relevant portion of the table is:


 <tr>
     <td>Saves</td>


 <!-- <td><$let a=<<modif 000Might>> b=<<modpot 011Martial>> sum={{{[<a>add<b>]}}}> <<sum>> </$let></td> -->


<!--     <td><$let a=2 b=-1 sum={{{[<a>add<b>]}}}> <<sum>> </$let></td> -->


     <td><$let a=<<modif 000Might>> b=-1 sum={{{[<a>add<b>]}}}> <<a>> <<sum>> </$let></td>

as you can see, i have tried 3 versions.

top one was first attempt. it displays zero when not commented.

second one displays 1 and appears to work.

third one displays 2 and -1.

thus a= 2 b= -1 and the sum of a + b = -1 instead of 1.

as it does work with simple numbers (second version), why doesn’t work it when those numbers are assigned by variables?

a does display as 2 but it seems to be zero when summing it?

Any help would be greatly appreciated!

This works for me:

<$let a="2" b="-1" c="{{{[<a>add<b>]}}}">

a = <<a>> b = <<b>> c = <<c>>

{{{[<a>add<b>]}}}
</$let>

well, as long as they are literals, it works for me too.

The problem only arises when I try to sum variables.

the second example works fine, when I change b to 3 there the result is 5, so it appears to be working.

but when a value of 2 is assigned to a it seems to make it a 0 when summing it up.

This works too and the values for a and b are not hardcoded anymore

\procedure return_a()
2
\end

\procedure return_b()
-1
\end

<$let a=<<return_a>> b=<<return_b>> c="{{{[<a>add<b>]}}}">
 
a = <<a>> b = <<b>> c = <<c>>

{{{[<a>add<b>]}}}
</$let>

What happens if you quote the c variable like I do?

The key rule to remember is: macros/procedures are NOT evaluated… they simply return their content. It is left to the calling context to determine how they are handled. If they are rendered as wikitext, then they will display their resultant values. But if they are used as widget parameters, they are simply passed along to the widget for further handling.

Thus, if the modif macro contains some complex wikitext code, that code is what will be used as the value assigned to a. To “capture” the computed value in a variable, you can use the $wikify widget to explicitly convert the returned macro code into values:

<$wikify name="a" text="<<modif 000Might>>">
<$wikify name="b" text="<<modpot 011Martial>>">
<$let sum={{{ [<a>add<b>] }}}>
...

-e

3 Likes

same behavior.


<td><$let a=<<modif 000Might>> b=<<modpot 011Martial>> c="{{{[<a>add<b>]}}}"> a = <<a>> b = <<b>> c = <<c>>

{{{[<a>add<b>]}}} </$let></td>

it has 2 -1 0 0 as output.

this worked,

with

 <td>
<$wikify name="a" text=<<modif 000Might>>>
<$wikify name="b" text=<<modpot 011Martial>>>
<$let sum={{{ [<a>add<b>] }}}>
   <<sum>>
</$let>
</$wikify>
</$wikify>
</td>

it finally did the addition.

First use of $wikify for me =)