Highlighted

How to set an object state with a variable?

Community Beginner ,
Aug 11, 2019

Copy link to clipboard

Copied

Hi all! I am working on a project where I want the user to choose an avatar at the beginning, and have it appear throughout the slides.

So far I have created a 'hair' object with different object states for each hair style. I can create a button with an advanced action that sets the object state on the first slide, but I'm a bit stuck displaying the correct object state on subsequent slides. It feels like I need to put the selected object state in a variable, then use the value of the variable to set the object state in each slides On Enter but I can't figure out how to do this. When I choose the 'change state of' action in my advanced action, I can choose the object name and the state, but I can't seem to use a variable value for the state.

I have also tried executing the following javascript but nothing seems to happen - I'm not sure if I need to put this in a function or if it can be executed straight from the script window and my syntax is wrong?

hairstate=window.cpAPIInterface.getVariableValue("v_HairSelection"));

cp.changeState("ImageName",hairstate);

If anyone could offer suggestions it would be greatly appreciated!

Most Valuable Participant
Correct answer by Lilybiri | Most Valuable Participant

Some questions: which version are you using (Help, About Captivate)?

Do you have the same avator (pose included) on all slides, then I would choose to time the avator for the rest of the project. If not, continue reading

You will  need to create a user variable (Boolean) for each state. You could do it with JS or with an advanced action with multiple decisions. You didn't tell how many states you have in total? Duplication of a decision in an advanced action is a breeze, and not much editing is needed. But if you have tons of states, would opt for JS.

A good labeling system can help. Use the same name for a particular state for all avator, like 'Blonde', 'Black'. It is one of the rare  situations in Captivate where you don't need to have unique names. Do NOT use the ELSE part of the IF decisions, only the first part since they will be mutually exclusive.

If you need more details, answer the questions above.

Views

237

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

How to set an object state with a variable?

Community Beginner ,
Aug 11, 2019

Copy link to clipboard

Copied

Hi all! I am working on a project where I want the user to choose an avatar at the beginning, and have it appear throughout the slides.

So far I have created a 'hair' object with different object states for each hair style. I can create a button with an advanced action that sets the object state on the first slide, but I'm a bit stuck displaying the correct object state on subsequent slides. It feels like I need to put the selected object state in a variable, then use the value of the variable to set the object state in each slides On Enter but I can't figure out how to do this. When I choose the 'change state of' action in my advanced action, I can choose the object name and the state, but I can't seem to use a variable value for the state.

I have also tried executing the following javascript but nothing seems to happen - I'm not sure if I need to put this in a function or if it can be executed straight from the script window and my syntax is wrong?

hairstate=window.cpAPIInterface.getVariableValue("v_HairSelection"));

cp.changeState("ImageName",hairstate);

If anyone could offer suggestions it would be greatly appreciated!

Most Valuable Participant
Correct answer by Lilybiri | Most Valuable Participant

Some questions: which version are you using (Help, About Captivate)?

Do you have the same avator (pose included) on all slides, then I would choose to time the avator for the rest of the project. If not, continue reading

You will  need to create a user variable (Boolean) for each state. You could do it with JS or with an advanced action with multiple decisions. You didn't tell how many states you have in total? Duplication of a decision in an advanced action is a breeze, and not much editing is needed. But if you have tons of states, would opt for JS.

A good labeling system can help. Use the same name for a particular state for all avator, like 'Blonde', 'Black'. It is one of the rare  situations in Captivate where you don't need to have unique names. Do NOT use the ELSE part of the IF decisions, only the first part since they will be mutually exclusive.

If you need more details, answer the questions above.

Views

238

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
New Here ,
Aug 12, 2019

Copy link to clipboard

Copied

Did you try the if/else action?

If v_hairSelection = 1

change state.....

Then create an if statement for each hairstyle. 

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...
Most Valuable Participant ,
Aug 12, 2019

Copy link to clipboard

Copied

Some questions: which version are you using (Help, About Captivate)?

Do you have the same avator (pose included) on all slides, then I would choose to time the avator for the rest of the project. If not, continue reading

You will  need to create a user variable (Boolean) for each state. You could do it with JS or with an advanced action with multiple decisions. You didn't tell how many states you have in total? Duplication of a decision in an advanced action is a breeze, and not much editing is needed. But if you have tons of states, would opt for JS.

A good labeling system can help. Use the same name for a particular state for all avator, like 'Blonde', 'Black'. It is one of the rare  situations in Captivate where you don't need to have unique names. Do NOT use the ELSE part of the IF decisions, only the first part since they will be mutually exclusive.

If you need more details, answer the questions above.

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...
Community Beginner ,
Aug 12, 2019

Copy link to clipboard

Copied

Thanks so much for the suggestions everyone!

@ullaTH This could definitely work. I'll need to see how much work is involved having an if statement for each element of the avatar in every slide I guess - or is there a way to reuse the same action with different objects in each slide?

Lilybiri I will have possibly two poses (front and side) and 3-4 elements of the avatar with up to 5 options for each. When you say create a variable for each state, what do you suggest to then set the state from that variable? And when you say to time the avatar for the whole project, does that mean I can have an object persisting across multiple slides? If so maybe that would be the easiest solution - set the states once on the front page and then just show/hide the same object on each slide as appropriate?

Stagprime​ Thanks for the link, very helpful info. How do you handle your avatar when the slide is changed? I assumed the avatar object name would change in each slide requiring a new script for each slide which I was trying to avoid.

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...
Advocate ,
Aug 12, 2019

Copy link to clipboard

Copied

You are correct - additional instances of an image would have new names.
I would reiterate what Lilybiri stated in her post.

Some possibilities

  1. Set the timing of the avatar images to 'Rest of Project' - This works well when the avatar image has a static location on each page. It also eliminates the naming issue - show the one you want and hide the rest and you should be good for the rest.
  2. Place a copy of the avatar on each page that you intend to use it. Then use a variable for the tracking of which avatar is selected. You could make a conditional statement for the check. This is where you maybe have other conditions that change things up a bit.
  3. With some well planned naming could carry you a long ways when paired with a function - especially if you have different representations of the avatar like a headshot on one slide and a full head to toe shot on another. For example, if I have a Bob and a Betty avatar - I could name all the pics like Bob1, Bob2, Bob3, etc for the Bob pic on slides 1, 2, and 3, respectively. I could even have different states for each slide. Then have the function do some variable concatenation. You still put the function on the slideEnter action but it would be the same function since it is using variables. This one would be more complicated, of course, but might allow you to achieve some interesting things.

In another post, I used avatars as drag and drop elements - then at the end, in the feedback phase - the avatars are shown based on the avatar that was selected during the question phase. This one uses option 2 above.

Training Supplement - eLearning

Hope that helps.

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...
Community Beginner ,
Aug 12, 2019

Copy link to clipboard

Copied

The 'rest of project' timing looks like it will solve my problem nearly perfectly. I can see that it is easy to show or hide the avatar on subsequent slides if necessary - is there any way to change the position of the object by actions? I have been googling this and can see a method to do it using javascript which I will try out if there's not a built-in method.

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...
Advocate ,
Aug 12, 2019

Copy link to clipboard

Copied

You can apply some effects to the objects and even do some custom paths - HOWEVER, if you move an object that is set for the rest of a project - you are going to end up with some weird results such as seeing two of your object on the stage. One in the original position and one in the new position.

If you want to do some custom movements - I would use separate objects in that case.

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...
Lilybiri LATEST
Most Valuable Participant ,
Aug 13, 2019

Copy link to clipboard

Copied

Do not use any motion path on an object timed for the rest of the project!

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...
Advocate ,
Aug 12, 2019

Copy link to clipboard

Copied

I did a write up on a similar concept.

Maybe you can find something useful from it for yours.

Using Javascript to Concatenate - A Real State Changer - eLearning

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...
Resources
Captivate User Guide
New Group