Skip to main content
Participant
March 25, 2024
Question

Variables not keeping decimal places when relaunching course

  • March 25, 2024
  • 1 reply
  • 452 views

Hello,

When the user clicks on a button, it simply assigns a variable that I've created with 2.5.
It works fine. But when the user exits the course and then reenters (on moodle), the variable just shows 2. I'm using Captivate 11 (2019).
Any idea why this is happening?
Thank you

    This topic has been closed for replies.

    1 reply

    Lilybiri
    Legend
    March 25, 2024

    To format a number correctly, you'll need to use JS.

    Have a look at this blog post, at the end you'll see the JS function which I used to have the correct number of decimals. Captivate has no way to achieve this directly:

    https://blog.lilybiri.com/percentage-progress-indicator-non-linear-course-solution-1

     

    Participant
    March 25, 2024

    Hello Lilybiri,
    Thank you for your response.
    I tried your solution. However, it still doesn't work - when reentering the course, the variable only shows 2.
    Any thoughts?

    The javascript I put:

    var v01js = window.cpAPIInterface.getVariableValue(“v01”); window.cpAPIInterface.setVariableValue(“v01”,v01js.toFixed(2));

    Lilybiri
    Legend
    March 25, 2024

    Since I'm testing this issue, I have just one slide with one button and a shape to display the variable value (as shown in the image I've sent). I'm adding the advanced action to the button. The default value for the variable is zero.
    When the user clicks on the button it shows the correct value - 2.55. But when he exits and reenters the course, the value is now 2.
    I'm using Captivate 11 (2019) - 11.5.5.553


    You are using the most stable version of Captivate ever.

    It is the first time you show now that the value is negative, which is another issue for Captivate, due to the lack of variable types.

    Those types exist in the new version, but it causes also issues.

    If I understand correctly this is about a user variable.  Such a variable is reset when you start a new version, its value is not retrieved from the previous version. It starts to be confusing.