Can I add commas to large numbers in a %score% field?

Dec 17, 2012

I have a course with manual scoring using a variable.  The total possible score is 150,000 points.  I have placed the Reference %score%  on each page, but the numbers display without commas.  This means that a perfect score shows as 150000.  This makes it hard to read.

Does anyone know of a way to add the commas? 

Thanks!

Jill

16 Replies
Jill McNair

Hi Montse,

I followed your instructions and this worked beautifully on a regular slide.  I tried to copy and paste to the next slide and the triggers did not come along with the commas, so that means that I would have to manually create all 5 triggers (the score goes over 100,000) on every slide, which is too time consuming if I want to meet my deadline.  I tried to do the same thing on the master slide, but it does not work for some reason.  Any ideas why not?

Mel Ruth

Have you guys tried just right-justifying the score variable so that the commas should always stay in the same places once the score goes over 1,000 and 1,000,000?  I haven't tried this in practice but, in theory, it seems to me like that should work.  Then you can still use Montse's workaround (which is excellent, by the way!) but it shouldn't require so many triggers to make it work.  Of course, this is also presuming that right-justification works for your particular layout...

Rebecca Fleisch Cordeiro

Montse's solution is awesome and Mel, I gave your right-alignment suggestion a try and it's equally awesome. That way, there's no need to insert more than one comma, thus eliminating extra triggers.

Jill, I was able to get this to work in the Master, but of course I don't know what exactly is going on in your story that may be preventing it.

Johanna Stix

The following javascript code could do the job too:

Create a variable "value" of type number

create a value "stringvalue" of type text

create a trigger: when variable "value" changes -> execute javascript

add this javascript code:

var player = GetPlayer(); 

var res= player.GetVar("value"); 

res= res.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

player.SetVar("stringvalue", res); 

stringvalue is now formatted text with commas

Hope this helps

Mel Ruth

Johanna Stix said:

The following javascript code could do the job too:

Create a variable "value" of type number
create a value "stringvalue" of type text

 create a trigger: when variable "value" changes -> execute javascript

 add this javascript code:

 var player = GetPlayer(); 
var res= player.GetVar("value"); 
res= res.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
player.SetVar("stringvalue", res);  

stringvalue is now formatted text with commas 

That's really neat, Johanna!  I have a basic understanding of HTML and CSS but I'm not a programmer and I've never really used javascript before so I don't fully understand its capabilities or how to write it.  It does open up a whole new realm of what you can do, though!  I will have to look and see what resources are available, both on Articulate's website and elsewhere online, to see if there are simple pieces of code that we "non-programmers" can use to fix our dilemmas in Storyline!  Do you have any suggestions for that?

Bruce Graham

Mel Ruth said:

 It does open up a whole new realm of what you can do, though!  I will have to look and see what resources are available, both on Articulate's website and elsewhere online, to see if there are simple pieces of code that we "non-programmers" can use to fix our dilemmas in Storyline!  Do you have any suggestions for that?
In this vein, I would love to have a small (?) library of Javascript code available with explanations, demo, and code that us "non-programmers" could refer to and use. Almost like a community plug-in library.

Bruce

Johanna Stix

Hi,

sorry, needed some days to answer, currently, there's a lot to do.

Here is the official info for javascript  @ articulate Website

http://www.articulate.com/support/kb_article.php?product=st1&id=llwes8cn32vg

I don't have special ressources to look at, I'm just searching the web all the time

A javascript library would be great, if there's a good place to share, just tell me :)

Johanna

Nancy Woinoski

Hi, if any of you are interested in learning more about JavaScript, there is a really great website that you can use to learn the basics.

http://www.codecademy.com/#!/exercises/0

One thing to keep in mind when using JavaScript in Storyline is that JavaScript does not work with the Articulate Mobile player on the iPad so if you are planning to use this format, I would steer clear of JavaScript for now.

This discussion is closed. You can start a new discussion or contact Articulate Support.