Getting and setting variables from javascript console?

Sep 29, 2015

Is it possible to open up the browser's JS console and run the getplayer, getvar and setvar functions from there?

We've got some fairly complex projects that will need debugging sometimes. Chasing after "alright when and why did that variable not change" right now is something I handle by putting hidden triggers and text boxes in projects, but it means messier .story files. If I could peer inside a running project a little better, it'd be a huge help.

6 Replies
Christie Pollick

Hi, Brett -- Thanks for your question, and hopefully one of our JS gurus in the community will be able to stop in to assist with an example! I also wanted to note in case you weren't already aware that we are not able to provide support for JS coding, but here is our JS Best Practices sheet just so you have it handy. Best of luck with your project! :)

Aubrey Berish

Actually it looks like it's doable! I just made a silly mistake originally.

In case anyone in the future is looking for how to check on variables in a running storyline project:

1. pop open the dev tools (f12 in most browsers) and click on Console.

2. In the bar in the bottom paste var player = GetPlayer() and hit enter. You have to do this every time you open the course, in order for any following functions to be able to find the Storyline project. It'll probably just spit back "undefined" which is fine, as long as you don't get an error or angry red text.

3. Paste console.log(player.GetVar("StorylineVariableGoesHere") to have it say whatever that variable is.

TIP: if you tap the up arrow, the console will repeat whatever you had it do last. So if you're going step by step through a project trying to find exactly where something broke, you can keep clicking the console and hitting up+enter at each step instead of re-pasting the whole thing.

4. set a variable by entering player.SetVar("NameOfTheStoryLineVariable","WhatYouWantToSetItTo") . An example case where you'd want to set this is you have a conditional trigger that's looking for a certain answer, it's not working correctly, but you want to continue through the course to find other errors to go and tweak before re-publishing: you could use this to set the variable right and not get the project hung up on that tone spot.

Hopefully this helps someone else!

This discussion is closed. You can start a new discussion or contact Articulate Support.