Struggling with a Javascript call inside C2

For developers using the Construct 2 Javascript SDK

Post » Sat Sep 24, 2016 9:55 am

Hello All,

I am heavily struggling with getting the below function to be called in C2. Essentially what I am doing, is defining a set number of times for the Correct Answer to occur and when it does occur returns a 1 that I can then display in C2. However, I can't get this to pop in C2 at all...

I've thoroughly tested the code from a javascript perspective in my environment and it's running perfectly, returning exactly what I expect every step of the way. I have spent too many hours at this point trying to figure the C2 piece out so I am here to ask for help/direction.

I would be happy to donate or pay for any assistance.

The function that exists on my website, in the same .js as other functions that I am having no difficulties calling, is shown below. I want it to run in Construct 2, and then return the Value 1 into Construct 2 as a global variable.

When an event occurs, (e.g. Timer = 0) run this function, a popup occurs on my website and requires you to answer some questions. If you answer the specified number of questions correctly it returns a 1.

function WaitForCorrectAnswers(num){
var numCorrect = 0;
var correctFlag;
var timer=setInterval(checkAnswer,100);

function checkAnswer(){
correctFlag = ShiftCorrectFlag();
if (correctFlag > 0){
numCorrect++;
}
if (numCorrect >= num){
clearInterval(timer);
var done;
done = 1;
return done;
}
}
}

Appreciate any and all help!

Thanks,
Warren
B
16
S
4
G
3
Posts: 1
Reputation: 2,352

Post » Sat Sep 24, 2016 4:15 pm

probably the way to do it would be to call a c2 function inside the checkanswer() function and set the global from c2.
B
91
S
31
G
103
Posts: 5,234
Reputation: 67,754

Post » Sat Sep 24, 2016 4:29 pm

Where did you put this WaitForCorrectAnswers(num) function ? I can't help you further if you don't post the full runtime script.

Here is a hint, this function cannot be called anywhere, it should be inside an instanceProto
Banned User
B
17
S
7
G
23
Posts: 388
Reputation: 13,964


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests