problem with return true and variable

Get help using Construct 2

Post » Sun Nov 20, 2011 3:19 am

Hey a problem of javascript again ;)
I did a condition

pluginProto.cnds = {};
var cnds = pluginProto.cnds;
cnds.ConfirmOKclicked = function ()
    if (confirmation=1)
    return true;     
    return false;

confirmation is a var (its value change via actions) that I defined at the beginning of the runtime as following:

var confirmation;

I tried too:
var confirmation=0;

The problem is when the condition is used, from the beginning of the application, the return is obligatory true instead to be false...

Passionate developer

If my work helped you to make your project, please consider making a donation :)
Posts: 631
Reputation: 10,987

Post » Sun Nov 20, 2011 4:27 am

In instanceProto.onCreate = function()
Make a variable this.confirmation = false;

In cnds.ConfirmOKclicked
return this.confirmation;

this. makes that the variable is intriseque part of the plugin's runtime and its value is stored over the several blocks of code.

The use of variable (their declaration and use) is directly tied to javascript.
this. is also a "standard function" of Javascript.

The SDK builds on this to make you use
this.variable_name; to store your values and have access to them within the plugin, even once it is sealed.
This is covered in the SDK - extract.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Posts: 7,358
Reputation: 73,460

Post » Sun Nov 20, 2011 4:40 pm

[code]if (confirmation=1)[/code]
A single = means assignment, so this statement means "assign 1 to confirmation and return 1", and since 1 is true the if statement is always true. You need two or three equals signs (e.g. confirmation === 1) to perform equality testing, generally three but make sure you're aware of the difference between using == and ===.

This is a basic Javascript language question - it's best not to ask about the Javascript language itself in the forum, because there are much better places to learn Javascript on the web. From the SDK docs:

[quote]Some useful resources for javascript are:

Mozilla's Javascript Guide -
A complete guide to javascript. This might be a good starting point if you are new to programming.

StackOverflow -
An excellent Q&A website. Also a good place to search to see if your question has already been asked and answered.

Javascript Garden -
Guide to the unusual parts of javascript. Very useful if you have experience with a different programming language but are new to javascript.

Mozilla Developer Network (MDN) -
An excellent reference for HTML, javascript, and more. A very useful place to look up features for the browser side of the plugin.[/quote]Ashley2011-11-20 16:40:36
Scirra Founder
Posts: 24,916
Reputation: 198,680

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests