Getting Construct2 instance variables to change.

For developers using the Construct 2 Javascript SDK

Post » Sat Apr 04, 2015 11:21 pm

Hi,

I am using the Browser plugin to send and get data from an Adobe Captivate slide. The code I am using to set the data from the Captivate FO1 variable is correct as I have used it before. The get should be working also its the C2 instance variable object property I am unsure about. I'd appreciate some help with this.

Here is the example code. The set is working but the get isn't showing up.

"window.parent.cpAPIInterface.setVariableValue('FO1',1);";;;;;;;;;;;;;This works fine
"this.runtime.textmmm.V1 = window.parent.cpAPIInterface.getVariableValue('FO2');";;;;;;;;;;;;;This isn't working at all.
B
10
S
2
Posts: 50
Reputation: 1,100

Post » Sun Apr 05, 2015 10:31 am

This isn't the right forum to ask general Javascript language questions. If it's not specifically to do with the C2 Javascript SDK, then you probably want to ask on a site like StackOverflow.
Scirra Founder
B
383
S
225
G
86
Posts: 24,134
Reputation: 190,601

Post » Sun Apr 05, 2015 9:08 pm

Ashley hi,

I am asking a C2 question here. Something I can't find on StackOverflow. I need to know how I communicate directly with a C2 Instanced variable using the Browser plugin. The textmmm.V1 is the variable I want to pass data to. Any help would be appreciated.

Regards
Luke
B
10
S
2
Posts: 50
Reputation: 1,100

Post » Mon Apr 06, 2015 9:38 am

@lukeo25

You might trace the data type of private variables, they saves in an array object, so it could not wrote directly.
A simple solution is - add an expression to export wrote value, then use action to write into instance's private variable.
B
107
S
25
G
243
Posts: 4,387
Reputation: 137,466

Post » Mon Apr 06, 2015 9:44 am

So is that the same as the function that holds the array of variables. If so, doesn't that change on every runtime. Is it a requirement to do a "for loop" to find an var[] position of an instance variable.
B
10
S
2
Posts: 50
Reputation: 1,100

Post » Mon Apr 06, 2015 9:53 am

@lukeo25

In editor, instance variables are indexed by a string name.
In rumtime, instance variables are stored in an array (not a dictionary), the name-index info had been removed, even "for loop" could not get the variable back by name.

----
There is another solution to have the name-index info.
B
107
S
25
G
243
Posts: 4,387
Reputation: 137,466

Post » Mon Apr 06, 2015 10:29 am

So it's just given a random number and so on....bugger, I was hoping it was a bit more relatable to the editor name.
B
10
S
2
Posts: 50
Reputation: 1,100

Post » Mon Apr 06, 2015 10:39 am

@lukeo25

Not a random number, it maps the names in sequence numbers (array indexes).
B
107
S
25
G
243
Posts: 4,387
Reputation: 137,466

Post » Mon Apr 06, 2015 11:04 am

So is the position determined by a rule set at edit ie; the first object etc?
B
10
S
2
Posts: 50
Reputation: 1,100


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests