Highlighted

Why While loop deosn't work?

Explorer ,
Nov 01, 2018

Copy link to clipboard

Copied

After a lot of efforts, I found a code thanks to TLCMediaDesignhere : Re: How to Execute javascript in Specific Frame of the Timeline?

This is the code in JS Window :

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",function(){

if(window.cpInfoCurrentFrame === 90)

{

  JavaScript Goes Here

}

},"cpInfoCurrentFrame");

It will fire JavaScript code on a specific frame (for example frame 90) in the timeline...

Then I build my project based on that JS code to fire my own JS code on second 2 of the timeline.

Here is Screen Shot of my simple project :

Base.png

And these are my decisions that construct "reza" script :

1.png

First three actions calculate the exact frame of second 2 of the slide, and save that frame number to "exactFrame" variable.

Then thanks to TLCMediaDesigncode it executes the Script_Window right at second 2 of the timeline.

in Script_Window I have a JavaScript to change the value of my variable named "SpeechReceived" and also it pauses the timeline

using this code :

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",function(){

if(window.cpInfoCurrentFrame === window.exactFrame)

{

  cp.movie.pause(cp.ReasonForPause.CPCMNDPAUSE);

  SpeechReceived = "hello";

}

},"cpInfoCurrentFrame");

Now please look at my last decision :

2.png

I want to continue my paused timeline whenever "SpeechReceived" is equal to "hello" but here is the problem : although my variable "SpeechReceived" changes to "hello" nothing happens ... it seems that while loop doesn't work and something goes wrong here...Am I missing Something ???

Any Idea how to fix that bug ???

TOPICS
Advanced

Views

557

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Why While loop deosn't work?

Explorer ,
Nov 01, 2018

Copy link to clipboard

Copied

After a lot of efforts, I found a code thanks to TLCMediaDesignhere : Re: How to Execute javascript in Specific Frame of the Timeline?

This is the code in JS Window :

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",function(){

if(window.cpInfoCurrentFrame === 90)

{

  JavaScript Goes Here

}

},"cpInfoCurrentFrame");

It will fire JavaScript code on a specific frame (for example frame 90) in the timeline...

Then I build my project based on that JS code to fire my own JS code on second 2 of the timeline.

Here is Screen Shot of my simple project :

Base.png

And these are my decisions that construct "reza" script :

1.png

First three actions calculate the exact frame of second 2 of the slide, and save that frame number to "exactFrame" variable.

Then thanks to TLCMediaDesigncode it executes the Script_Window right at second 2 of the timeline.

in Script_Window I have a JavaScript to change the value of my variable named "SpeechReceived" and also it pauses the timeline

using this code :

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",function(){

if(window.cpInfoCurrentFrame === window.exactFrame)

{

  cp.movie.pause(cp.ReasonForPause.CPCMNDPAUSE);

  SpeechReceived = "hello";

}

},"cpInfoCurrentFrame");

Now please look at my last decision :

2.png

I want to continue my paused timeline whenever "SpeechReceived" is equal to "hello" but here is the problem : although my variable "SpeechReceived" changes to "hello" nothing happens ... it seems that while loop doesn't work and something goes wrong here...Am I missing Something ???

Any Idea how to fix that bug ???

TOPICS
Advanced

Views

558

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 01, 2018 0
Adobe Community Professional ,
Nov 01, 2018

Copy link to clipboard

Copied

You most likely are running into an issue because you paused and continue will not release the playhead. You would need to use resume.

Don't understand the logic of the while loop though.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Explorer ,
Nov 01, 2018

Copy link to clipboard

Copied

"Don't understand the logic of the while loop"... Well I want to continue the movie whenever "SpeechReceived" is changed by javascript window to "hello".

just after javascript sets the value of variable "SpeechReceived" to this string "hello", I want to proceed and continue the movie ...

To be more clear I used these lines of code to inject my string variable ("hello" for example) from javascript to captivate and I was successful because I can see changing variable "SpeechReceived" on my screen. But the poblem is eventhough I see "SpeechReceived" is changed to "hello" while loop doesn't work and I can't "Continue" the movie ...

Code Here :

window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",function(){

if(window.cpInfoCurrentFrame === window.exactFrame)

{

  cp.movie.pause(cp.ReasonForPause.CPCMNDPAUSE);

speechResult ="hello";

    window.cpAPIInterface.setVariableValue("SpeechReceived",speechResult);

}

},"cpInfoCurrentFrame");

I don't know what do you mean when you say "You would need to use resume" ? How can I do that ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Adobe Community Professional ,
Nov 01, 2018

Copy link to clipboard

Copied

What I'm saying is that you pause the movie with JavaScript and then turn right around and want it to resume if the variable is set to Hello, which you just did in the script..

I really don't know exactly what you are trying to do on the timeline, but it just looks like you are setting a couple of variables and changing a display variable at a specific point.

After SpeechReceived is set to "Hello", how would it be set to something else?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Explorer ,
Nov 01, 2018

Copy link to clipboard

Copied

Ok... It's a voice recognition app that changes "SpeechReceived" to "hello" on user voice input ...

User says "hello" and the timeline continues the movie ... actually we wait for the user's voice ("hello") in order to continue...

It sounds mysterious why in the world that while loop doesn't work ...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Explorer ,
Nov 01, 2018

Copy link to clipboard

Copied

It should have been said that No Action inside that loop will work... Not just "Continue" but any action...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Explorer ,
Nov 01, 2018

Copy link to clipboard

Copied

And I thought while loops work even if the movie ends or pauses...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Explorer ,
Nov 01, 2018

Copy link to clipboard

Copied

God, Really? We can not do such simple thing Using Captivate ?! Please Someone Tell Me That I missed Something

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2018 0
Engaged ,
Nov 02, 2018

Copy link to clipboard

Copied

It seems to me that the logic is a bit off. I think what you really want is to wait until you get the response that you expect. In other words,

While SpeechReceived is NOT "hello"

     No action (waiting for the correct response, so do nothing)

If SpeechReceived == "hello"

    Continue (or jump to a frame, or somehow exit from the loop and advance the playhead)

    

At least that's how I would approach it writing code. I'm still on CP9 and so can't test out the loop as an AA.

But do you really need the loop in the first place? Is anything else happening that has to continue happening while waiting for the response? If not, and the listener will fire the action when the value of SpeechReceived changes, just do the simple IF statement and forget the loop.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2018 0
Explorer ,
Nov 02, 2018

Copy link to clipboard

Copied

I really don't need while loop but If statement doesn't work too ... It just doesn't ...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2018 0
Adobe Community Professional ,
Nov 03, 2018

Copy link to clipboard

Copied

I just did a test with while loop.

1. It executes about every second.

2. Checking if current frame was less than a number, it worked

3. Checking if current frame was greater than a number, didn't work.

You should try using a setInterval in JavaScript to see what the value of the variable is.

var myInterval = setInterval(myTimer, 500);

function myTimer() {   

     if ( window.SpeechReceived === "hello" )

     {

          //execute code here

          clearInterval(myInterval);

     }

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 03, 2018 0