Convert Values to Text

Hello,

I am new to working with variables in Lectora. I know that you can create actions that add values to a variable. However, my question is, is it possible to change values/numbers in a variable to text strings and then combine them together. For example, instead of adding the numbers 1,2,3 together in the variable, the numbers would be stored as 123. The idea behind this would be to ultimately have these numbers display in a text box on a page.

Don't know if this is possible, but thought I would ask.

Thanks,

Brian

Discussion (6)

If you only add numbers Lectora will calculate the mathemical result. To prevent Lectora from doing that you have to use a string somewhere, e.g. four actions to a button

1.

Action: Modify variable

Type: Set equal to

Value: a

2.

Action: Modify variable

Type: Add to variable

Value: 1

3.

Action: Modify variable

Type: Add to variable

Value: 2

4.

Action: Modify variable

Type: Subtract from variable

Value: a

The result will be "12"

Tim

If you use Tim's tip that will work.

For each button add a sequence of actions as Tim suggests.

That will add the current key as a String to that variable..

in the end you will have the keys you choose in your variable.

A few things need to change to Tim's sequence though..

1.

Action: Modify variable

Type: Add to variable ( if you leave this as in Tim's version to set equal to, your old values are gone )

Value: a

2.

Action: Modify variable

Type: Add to variable

Value: 1 <-- the value on your button

3.

Action: Modify variable

Type: Subtract from variable

Value: a

4.

Action: Change content

Target: textfield your using

Value: Set Text

Text: VAR(typedValues) undefined

Ensure the value of your variable at start is empty else you see 0 upfront.

Thanks, Math. I was able to figure that out before I got your post. I basically did what you suggested.

The one other thing I would like to be able to do is if necessary, remove the last value in the variable. So if the variable stored 3214, the action triggered would remove 4.

For something like this though, I'm thinking I would probably have to use a JavaScript function, right?

Tim,

Thanks for replying to my original post. This actually works pretty good, but I would like to take this one step further.

What if I have some buttons on my page that replicate a keypad on a phone or laptop keyboard. I would like to tap random number keys (buttons) so that it stores the numbers I tap in the order I tap them into the variable. So for example, if I tap the 241 keys, it stores those numbers in the variable in that sequence. Is that possible to do in Lectora?

Ideally I would like to have the numbers display as I type in a text box. Don't know if that is doable though.

Thanks,

Brian

Yeah cant think of a Lectora action to remove the last 'character' of a variable. A simple javascript like:

var theString = 'Brian Dombrowski1';

var theStringMinusOne = theString.slice(0, -1);

console.log(theStringMinusOne);

will do the trick...

That makes, sense, Math. I like can use javasscript to perform operations that are not native to Lectora.

Thanks,

Brian

Discussions have been disabled for this post