It is kind of hard to know what you are doing with what you've posted here.
"var name = player.GetVar("Name"); " will work fine if you have already set the statement "var player = GetPlayer();
Either way, this function returns the variable "Name" from the player. Have you created the variable Name in your project in the variables panel?
The statement "document.getElementById("score").setAttribute("value", "score");" get an html element with the ID of "score", and sets its attribute value to the value of the variable of the variable "score". This would be a variable in your html code, not in the player. Is that what you wanted? (Id of score and a variable named score are not the same). If you wanted to set the value of "score" in the player, you need to use SetPlayer();
In Storyline, %TXT% displays the storyline variable TXT. Is this variable set in the variables panel?
Try adding a statement to produce output at the console. This way you can see what is happening as your code runs. For example, after you run var name = "player.GetVar("Name");" run the statement 'console.log("Name " + Name);' This will print the Name variable to the console.
When you run your project, Press F12 to open the debug window, and select the console tab. The you can see the messages that are sent to the console.
4 Replies
I also have a variable for score that is %TXP%
var score = player.GetVar("TXP")
document.getElementById("score").setAttribute("value", "score");
Now I thought var score =TXP at this point and setting the attribute as score is the way to go, but no score posted to the database either.
The variable has to be defined in the variables panel. And you'd need this:
GetPlayer().GetVar("var"), not just player.GetVar("var");
I'd debug to see if your dom selector is selecting anything. If it is, and if the GetVar is working, it should work.
This post was removed by the author
have you tried adding alerts to see where it is breaking?
I would expect it is this line
As I think in javascript you can only access the client side and not the server when run in the intended environment.
It is kind of hard to know what you are doing with what you've posted here.
"var name = player.GetVar("Name"); " will work fine if you have already set the statement "var player = GetPlayer();
Either way, this function returns the variable "Name" from the player. Have you created the variable Name in your project in the variables panel?
The statement "document.getElementById("score").setAttribute("value", "score");" get an html element with the ID of "score", and sets its attribute value to the value of the variable of the variable "score". This would be a variable in your html code, not in the player. Is that what you wanted? (Id of score and a variable named score are not the same). If you wanted to set the value of "score" in the player, you need to use SetPlayer();
In Storyline, %TXT% displays the storyline variable TXT. Is this variable set in the variables panel?
Try adding a statement to produce output at the console. This way you can see what is happening as your code runs. For example, after you run var name = "player.GetVar("Name");" run the statement 'console.log("Name " + Name);' This will print the Name variable to the console.
When you run your project, Press F12 to open the debug window, and select the console tab. The you can see the messages that are sent to the console.
This discussion is closed. You can start a new discussion or contact Articulate Support.