GetPlayer GetVar in javascript
Jan 27, 2016
By
cyber tech
Hi,
I'm testing some of the javascript features. Using a trigger and calling functions in external javascript file (e.g. "user.js") is working correctly. From within the function I can get the player and get or set vars.
In a different scenario, I'd like to control (get or set) variables without an explicit call associated with a trigger.
For instance, in user.js I have a pure javascript "document ready" handler, and a function the simply gets storyline player and fetch a variable.
docReady(function() {
var player = GetPlayer();
if (player) {
var page = player.GetVar("maxPage");
}
});
The error is Uncaught TypeError: player.GetVar is not a function
this not supposed to work or am I doing something wrong?
thanks
7 Replies
Hi Cyber Tech,
We can't offer support for specific Javascript elements, so hopefully someone in the community is able to weigh in here. In the meantime you may also want to review the information here in regards to the Javascript Best Practices. Best of luck with your project and I hope someone in the community is able to assist.
This is an old thread but I would use the browser developer tools to set a breakpoint on the
if
statement and probe to see exactly what kind of object you have in theplayer
variable at that point.I would expect that if
player
is not a null value (and checked by theif
statement) then it ought to be a legitimate reference to the player and therefore theGetVar
function should exist (but you can check this when the breakpoint is hit).The other thing to do is check the console for any other errors that may have occurred prior to the breakpoint that might mean that the
player
object is not in a fully initialised state.Old or not, we always appreciate the updated info and ideas!
hi chris,
stumbled across this because i'm facing the same issue as original poster. the breakpoint doesn't seem to be showing anything specific and all im trying to achieve is to trigger the function.
Hi Ariff,
Can you provide more info about what you see on the breakpoint. Specifically:
var player = GetPlayer();
, what is the value of theplayer
variable? Is it null? or is it an object?player
is not null, does it contain a function calledGetPlayer()
? You can test this by typing the following in the console window:player.GetVar
(note that no brackets are present).player.GetVar
function exists, what is the result of the call toplayer.GetVar("var_name_goes_here")
? (don't forget to changevar_name_goes_here
with your variable name and also be aware that the string value is CaSe SenSiTiVe!!!Drop feedback and I might be able to help more. Good luck.
Any updates on this?
copy this function in your user.js
Jürgen