Variable math method needed

Problem: I’m having difficulty understanding how to use the variable math action to perform a simple math action on two variables and load it into the third:
Example: a = b/c

I’m only seeing a place to do an action such as b/c but no way to get the result into a.

Is this a Javascript-only type of action? Since I’m not a Javascript person could you give me a simple example of the code in Javascript to perform this? I’ve tried
var a = b/c;
and
prez a=b/c;
but clearly I’m not understanding something because neither is working. (I’m assuming you have to establish the variables in AP first, which I did).

ActivePresenter version: 8.5.8

OS: Win 11

Notes:
Sorry but I’ve spent hours trying to find similar questions or examples first, but couldn’t turn any up.

Hi Roger,

For your request, you don’t need to use JavaScript to solve the case.
Please set the action for your variables as in the image below to make the math action work:
variables

Kindly let us know if you have any other questions.

Regards,
Quynh Anh

I have exactly the same problem. I want to perform calculations with the help of Javascript (for example, the Pythagorean theorem a2 + b2 = c2). The calculation itself is not the problem but:
How can I enter the values “a” and “b” in ActivePresenter and output the result for “c”.
I know it’s a beginner’s question but I’m stuck otherwise. Thanks a lot in advance.
Regards, Holger

Hi Holger,

You can use the following script:

// read AP variables and assign their values for JS variables
var a = prez.variable('a');
var b = prez.variable('b');
// calculate c
var c = Math.sqrt(a * a + b * b);
// store JS variable in AP variable
prez.variable('c', c);

Regards

1 Like