September 28, 2021
Struggle with Javascript
Comments
(9)
September 28, 2021
Struggle with Javascript
Newbie 1 posts
Followers: 0 people
(9)

Hi all,

I am a newbie on Javascript. Got inspired by Greg Stager during last week’s Adobe EL World 2021. And now I want more 🙂 !!

In my project I control an object via Javascript: I can rotate that object while pressing buttons. It’s like a compass pin: per click it rotates 9 degrees. No problem.

What I want is that these degrees are shown in Cp. Neither a problem since  I declared a Cp-variable that contains the value of the rotation in degrees after each button press.

But now I want to know the contents of that Cp-variable string on “character level”. That string can contain 1 character (like 9 degrees), two (like 45 degrees) or at a max 3 characters (like 351 degrees). Stated differently: I want to know if the string contains 3, 2 or 1 characters + what is the contents of the 1st, 2nd and 3rd character.

I tried to do that with the Javascript command charAt(). But there’s no output in Cp, nor an error message. I tested my solution in a free Javascript editor website: no error.

Objective:

I want the degrees being projected as digital numbers (0-9), which are separate pictures of digits. For each position (max 3) I planned to use an object with 10 states (10 small pictures of digits from 0 to 9). So in total 3 objects of the samen kind. When I know what number is on each spot in the string, then I can change the object state to that specific number.

I assume the “non responding Javascript” in Cp has something to do with the fact that the Cp-Variable string length is not constant: it grows from 1 character -> 2 characters -> 3 characters max. But my Js knowledge and definitely my Js skills are poor…

Who wants to help me??

Thanks in advance!!!Play

9 Comments
2021-11-23 19:26:45
2021-11-23 19:26:45

great question, thank you for posting!

Like
()
2021-10-16 15:53:52
2021-10-16 15:53:52

In general, you should only use JS when it cannot be done in Captivate.

Like
()
(2)
>
cferran1
's comment
2021-11-03 19:18:03
2021-11-03 19:18:03
>
cferran1
's comment

I agree

Like
()
>
cferran1
's comment
2021-11-03 19:23:01
2021-11-03 19:23:01
>
cferran1
's comment

It seems a couple of you are in agreement with this statement.

I would ask you to provide some reasons for why you believe this to be true.

Like
()
2021-10-02 01:30:23
2021-10-02 01:30:23

I should really learn Java. Seems fun!

Like
(2)
2021-10-01 11:40:56
2021-10-01 11:40:56

Hi Greg,

YES! OMG!! The splitting was the key!
It’s a way of thinking which I must get used to as a Js newbie.

As you might understand, I “translated” your Js lines and put them into my project and… it works!

I think I could not have reached this objective when using a bunch of advanced actions.
For now, at this stage of my first experiences, I regard the use of Js as the fine tuning of my projects. I need to get more acquainted to this language, need to know what I can do with Js (the commands, functions etc).

I discovered your  Interactive Guide on JavaScript with Captivate.
So I will start there.

One last question:
How do you know if Js code works well when you run it in Cp, because Cp does not provide you with (error)messages when something goes wrong: it simply shows nothing. Do you use something on the internet?

But for now:
Thank you VERY MUCH for helping out.

Greetings from The Netherlands,
Maurice Verhalle

Like
(2)
(1)
>
mauricev36610906
's comment
2021-10-01 12:04:55
2021-10-01 12:04:55
>
mauricev36610906
's comment

Glad to hear that the idea worked for you.

Three things I do …

  1. Often when I am coding in Captivate I am asking myself what is supposed to happen when I click a button or enter a slide, etc. If the effects are things I should see happen on screen, that alone may tell me if the code executed or not. That is the pseudocode part.
  2. I will use “troubleshooting boxes”. These are just smart shapes used to display variables. I keep an eye on these and make sure that they change when they are supposed to.
  3. I make heavy use of the console in my browser. I like to print things to the console so that I know if certain blocks are working. The console will also provide its own error messages. They can be cryptic at times but they will at least let you know something is broke. The console is your friend.
Like
()
2021-09-30 12:30:32
2021-09-30 12:30:32

Nice JavaScript implementation idea!

I have often done something similar to display numbers.

What made this one a little tricky is that the numbers are not linear and span three places.

I chose to take the number value in degrees, convert it to a string and split the characters out into an array. For single digits – I need two leading zeroes and for two digits – I need one leading zero.

To solve that issue – I checked the length of the array – if it was only one digit, I specifically set the first two array index values to be  “0”.

If it was two digits, I just set index [0] to be “0”

At that point I was able to display the characters using concatenation.

I have attached the file for your study.

Hope it helps.

Attachment  compass.cptx

Like
(5)
(1)
>
Greg Stager
's comment
2021-11-03 19:19:03
2021-11-03 19:19:03
>
Greg Stager
's comment

Good idea!

Like
()
Add Comment