Variables - Adding (Numbers or Text)

Jun 03, 2013

Brand new to using SL, not to creating ICW.

I need to create variables I can add to (not using Data Entry fields) but a simulated alpha numeric keyboard I have working with grahics.  A user clicks on 1, then clicks on 2,  I want the number 12 to display in a text box.

I have my textbox called 'DEScratchPad'

I have a variable called "ScratchPad'

I've created a trigger when Button 1 is selected, a 1 is assigned to variable ScratchPad (I can display this using the reference with the textbox DEScratchPad.)  *Same works for the number 2.

1. How can I just add one character to another character in the variable (without it adding the two numbers)?; and

2. How do I send the contents of my variable to the textbox?

These are easy questions, I just see it in the 600+ page manual.

Thanks for the assist.

Note:  The only option in my trigger (using Adjust Variable) is "= Assignment"; the ability to add, subract or anything elseis not displayed in the dropdown (only = assignment)

Thanks for the assist.

13 Replies
Art Smith

I get the gist of what you are illustrating.  Unfortunately (after publishing), the story did not display anything after typing in text into each layer.  Not a JS guy so I don't know why it didn't work for me.

If I can get this to work, I believe it will work for my story.

Can you create an example for me works as I described above?  I won't be using Data Entry fields.

first button = 1

second button =2

I can push each button multiple times and display a number such as 12, or 212, or 122112112221112 

Thank you all very much!

Art Smith

Phil,

Great example...very simple (just what I needed), I'm learning to think in Storyline program (eeze).

So I can experiment with decimal points in the mix...I think I can figure that out.

Any examples on working with Alpha-numeric strings?

Example:

From a button Keyboard I've created (like yours with the numbers), can I spell out a word like "AIR12"

xxxx Also...

Not being a JS guy, I sort of need to understand not just the code, but how the code passes the variable information to and from a variable within SL.

Example:

If in SL, I have a var called "ScratchPad" and I'm going to use that in my JS, then how does JS know that var ScratchPad already exists with in SL?  So here's what I mean.  Is it possible to have a line of JS that reads something like  var ScratchPad = ScratchPad + "R".  So if var ScratchPad already contained "AI", then after the user pushes Button "R", then the user will see "AIR displayed in the textbox.

This already has been helpful!

Thank You

Art Smith

Phil, Geert, thanks for the assist so far...

I never did get Geet's story to run properly so I don't know what the illustration should looked like.  I copied the JS just the same and modified (see below).

What I'm trying to accomplish in this code (if I understand it correctly)...concatenation (Treat all characters as String variables)

-Get value of SL text var "CLRhold1" (which is 8)

-Add CLRhold1 and a period "." (to result in "8.")

-Send the result "8." to SL var "DEScratchPad"

Am I close?  how do I fix the code to get concatenation to work as I described?

var player = GetPlayer();

var a = player.GetVar("CLRhold1");

var c = a + ".";

player.SetVar("DEScratchPad",c);

Thanks Team!

Art Smith

It worked.  Yesterday I was testing with web output (only) and using Chrome without success.  Switched to IE (now default) and it worked.  Then tested CD and it worked too!  

My confidence was shaken there for a minute.  I usually don't struggle so early in the game like.   Hopefully it will be more intuitive for me as I proceed.

Thanks for the support!

Haydn Howard

Hi trying to do something similar for an Assessment im working on. There are 10 questions after each question you get feedback, if you get the answer incorrect you get text to say which section in the course to look at. So for example get Question 1 incorrect, "look at section 1", get Question 2 incorrect, "look at section 2" and so on. A the results I want to list the sections that the user needs to review in a text box, so for exmple the user gets Questions 1, 2, 5 and 7 incorrect the list would be:

look at section 1

look at section 2

look at section 5

look at section 7

i have tried to do this with Javascript but can't get it to work from the example here:

if (Q1Incorrect == 1) {

var Q1 = "look at section 1";

}

if (Q2Incorrect == 1) {

var Q2 = "look at section 2";

}

if (Q1Incorrect == 1) {

var Q3 = "look at section 3";

}

var list= Q1+"\n"+Q2+"\n+Q3+"\n;
player.SetVar("concatenate",list);

Having no luck, any help much appreciated.

Haydn

Ashley Terwilliger-Pollard

Hi Haydn,

This thread is a bit older, so I'm not certain that folks are still subscribed here, but you may want to look at sharing the .story file so that community members can see what you're taking a look at and how it's set up. Also as a reminder here is additional information in terms of the Javascript best practices. 

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