Forum Discussion
SL360: Javascript GetPlayer() function is not defined
Hi, Everyone.
How to get a variable value from the storyline 360 using external javascript with GetPlayer, SetVar, and GetVar, but it doesn't work. It always gives an error like this "Uncaught ReferenceError: GetPlayer is not defined" can someone help with this?
I'm trying to get a variable value from storyline to use in frame.js (html5\data\js\frame.js) which holds the strings for defaults texts on Storyline/SCORM. Basically, I'm trying to translate texts inside the frame.js based on the user's selected language from the storyline.
Example:
- A user open the course and selected the Tagalog language from the storyline.
- The user will submit the selected language.
- When the user closes the course and opens the course again this screen will be shown.
- But the texts on this screen will be translated based on the user's selected language in the storyline. For this one, the user selected the Tagalog language.
Please see attached files for reference.
Thank you so much!
- Jürgen_Schoene_Community Member
use in trigger
var player = GetPlayer();
not
var player = parent.GetPlayer();
this is used in web object (= iframe)
Jürgen
- DarrylPalaub492Community Member
Thanks for this, but still got an error when I'm using this code:
var player = GetPlayer();
Error: Uncaught ReferenceError: GetPlayer is not defined
- Jürgen_Schoene_Community Member
upload a storyline source file with your javascript code
- PhilMayorSuper Hero
Is your external javascript in a web object?
Or where is it being called from?
- DarrylPalaub492Community Member
Not on the web object, please see the post, it's now updated and more detailed. Thank you!
- PhilMayorSuper Hero
I could be wrong here but I do t think this will work. I suspect the player and the player variables are not loaded at this point.
Sent from my iPhone
- OwenHoltSuper Hero
Where are you running the external script? Where are you trying to show the retrieved variable information? What exactly is the use case?
Player is an object within the Storyline published files and the Get and Set functions are associated with that object. I'm not sure you can call or trigger any of them from outside of the Storyline published environment but I'm not the JavaScript expert that others here are.
A work around might be to use JavaScript triggered by something inside of your Storyline project to retrieve your StoryLine variables send them to local storage and then, subsequently retrieve them from there.
In other words, instead of pulling values externally directly from Storyline, you push the values internally from Storyline to local and then pull the values externally from there.- DarrylPalaub492Community Member
Thanks for this. I updated the post and it's now more detailed.
- MathNotermans-9Community Member
Best to share a Storyline sample of your setup...as too many open questions for any of us to help you.
- DarrylPalaub492Community Member
Post updated and it's now more detailed. Thank you!
- Jürgen_Schoene_Community Member
my first idea was waiting with "window.setTimeout", like
function updateDOM(){
var player = GetPlayer();
...
}
function waitStorylineReady(){
console.log("wait", typeof GetPlayer );
if( typeof GetPlayer === "undefined" ){
window.setTimeout( waitStorylineReady, 1000 );
} else {
updateDOM();
}
}
waitStorylineReady();but this doesn't work
storyline needs the function "window.globalProvideData( ... )" to start
you have moved the function to "frame-english.js", "frame-tagalog.js" (for later loading)
-> now storyline doesn't start, "GetPlayer" is never initialize, waiting is useless(the waiting animation is a simple css animation without javascript)
Jürgen
- DarrylPalaub492Community Member
This makes sense thanks for this, I tried putting the GetPlayer code at the end of the function "window.globalProvideData( ... )" but still GetPlayer is not working.
- MathNotermans-9Community Member
Im afraid you made some wrong assumptions ( or im wrong, thats possible too ;-)
The texts on the Resume screen ( black screen with Resume ) is not set by variables in Storyline. As they are not yet loaded there...you cannot set those texts the way your trying. These texts are hardcoded in the player. You can change or add these texts in the player.
Here you can define a language for the player. I guess its saved somewhere in xml or other Storylinedata, but for sure not in the variables...as they are not yet available when getting the resume screen. - MathNotermans-9Community Member
What i did for a similar case where the Storyline player was needed and text needed to be in the choice of the user...create multiple versions... Dutch, English, French... and on a normal page before the Storyline let the user choose the language and then the appropriate language will be started.
- DarrylPalaub492Community Member
Thanks for this, do you have the source files for this one? so I can check and replicate it, thanks!
- JakobFritschCommunity Member
I have the same problem. Any solution found yet?
- MathNotermans-9Community Member
Share a storyline file...then someone might be able to help.