• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Is there a way to poll the current state of an object for use elsewhere?

Community Beginner ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

Hello fellow intrepid adventurers, I have a question that has been bugging me for some time.


Question summary:
Is there any way in Captivate (2017) either pass an object's state name either directly to a variable, or use that value directly in an if/then statement? I don't think Advanced actions are quite advanced enough for this, though there may be a way in JavaScript.

OR is there a way to automatically change the state of an object as a variable changes?

Backstory

Current method: What I usually do is create  a "state counter" variable to "track" state changes. The learner clicks a button, it switches the object to a particular state, and assigns/increments/decrements the assigned counter variable to a corresponding value. When it comes time to check the answer, I simply use a lengthy if/then statement to check for the appropriate variable combination, and then trigger a success or failure caption.

For example: here's what my increment button might look like.

The only purpose of this variable is to assign some sort of significance to the changes in state.

Alternate method: I realize when using purely numerical or text-based values, I can simply display "$$VariableName$$" on the screen, without tying a multistate object to it, however there is a mix of text-based and non text based data displayed, and i'd like to not use 2 different methods.  

So what's the problem?

It's frustrating having to script resets for the variables on slide re-entry, while I can simply check a box to get the multistate object to revert to its default state. Furthermore, I don't see any way of setting the range of a variable to automatically reset. like if the object it's tracking only had 5 states, I cant set the range of Variable_A to be 0-5.  instead, I have to script an if/then statement to reset the variable back to zero if it is incremented past 5.   

I admit this may not seem like much of an issue for the single example I quoted, however imagine this script buried in one of 15 different tabs in an advanced action. Then repeat this process for 15 different buttons. That's an awful lot of placeholder variables whose sole purpose is to parrot what is displayed on the screen. Now imagine trying to troubleshoot why a correct answer isn't registered after shuffling around between slides.

So then I got to thinking, Object states naturally reset back to their normal state when you increment them past their final state. Furthermore, it's easy to set whether or not an object retains its state on revisit. What if there were a way (either through JavaScript, or through something I'm missing in advance actions) to just use that data instead of a counter variable? Wouldn't it be great if I could just say something like:

IF (the state name of MS_screen1 = config_Menu1 )

     trigger steps 1,2,3

ELSE

     trigger steps 4,5,6

TOPICS
Advanced

Views

465

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
community guidelines

correct answers 1 Correct answer

Contributor , Aug 07, 2018 Aug 07, 2018

Yes there is - in Javascript!

var myState=cp.model.data.myObject.currentState;

myState is what ever variable you want to use, if you have a variable already set in Captivate, drop the var and just use yourVariable =

myObject is the name you gave the object in the properties panel

It only returns a number, not the state name.

This can only read the state, not change it.

Votes

Translate

Translate
Community Expert ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

There are several areas where Advanced Actions could be improved and you have highlighted one of them.  I suggest you log an enhancement request for the ability to use object states as part of a condition.

From what you describe, you could also benefit from being able to execute the conditional action whenever the value of a specific variable is changed in any way.  Currently there is no default event in Captivate that can be used this way (ON Variable Change).  Articulate Storyline has had it for several versions.  Captivate should have it too.

Votes

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
community guidelines
Contributor ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

Yes there is - in Javascript!

var myState=cp.model.data.myObject.currentState;

myState is what ever variable you want to use, if you have a variable already set in Captivate, drop the var and just use yourVariable =

myObject is the name you gave the object in the properties panel

It only returns a number, not the state name.

This can only read the state, not change it.

Votes

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
community guidelines
Contributor ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

To change the state via JavaScript:

cp.changeState("myObject","stateName");

myObject is the name given to the object in the properties panel

stateName is the name of the state you want to change the object to

Votes

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
community guidelines
Community Expert ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

If I understand well, the problem is to link the state number to the state name. Is the numbering starting with  0 or with 1?

Votes

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
community guidelines
Contributor ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

Lilybiri - good call.

The numbering starts at 0.

Below is the state javascript array for a Captivate object. It has 3 states: Normal, red and blue which correspond with the array positions: 0, 1, and 2.

  1. 0:{stn: "Normal", stt: 0, stsi: Array(1)}
  2. 1:{stn: "red", stt: 9, stsi: Array(1)}
  3. 2:{stn: "blue", stt: 9, stsi: Array(1)}

and here is the state view of the Captivate object:

Screen Shot 2018-08-07 at 1.03.33 PM.png

Votes

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
community guidelines
Community Beginner ,
Aug 22, 2018 Aug 22, 2018

Copy link to clipboard

Copied

LATEST

THANK you to everyone on this thread. After a lot of trial and error, I got this to work, and it works beautifully in HTML5 preview, and when I FileZilla it to a test web server.

Votes

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
community guidelines
Resources
Help resources