Forum Discussion
Creating downloadable pdf files in Storyline - an update on earlier methods
Replace the following part of the code with the one below. Ensure that const formUrl = ''; exactly matches the name of the PDF file located in the root folder.
var player = GetPlayer();
Role1 = player.GetVar("Role1") ?? "";
Role2 = player.GetVar("Role2") ?? "";
Role3 = player.GetVar("Role3") ?? "";
Role4 = player.GetVar("Role4") ?? "";
Role5 = player.GetVar("Role5") ?? "";
Role6 = player.GetVar("Role6") ?? "";
Role7 = player.GetVar("Role7") ?? "";
Role8 = player.GetVar("Role8") ?? "";
RolePicked1 = player.GetVar("RolePicked1") ?? "";
RolePicked2 = player.GetVar("RolePicked2") ?? "";
RolePicked3 = player.GetVar("RolePicked3") ?? "";
Action1 = player.GetVar("Action1") ?? "";
Action2 = player.GetVar("Action2") ?? "";
Action3 = player.GetVar("Action3") ?? "";
Body = player.GetVar("Body") ?? "";
Mind = player.GetVar("Mind") ?? "";
Spirit = player.GetVar("Spirit") ?? "";
Heart = player.GetVar("Heart") ?? "";
Time1 = player.GetVar("Time1") ?? "";
Time2 = player.GetVar("Time2") ?? "";
Time3 = player.GetVar("Time3") ?? "";
What does this part
?? ""
do?
- Nedim7 months agoCommunity Member
I'm pretty sure you were initially getting this error during testing. At least, that's what I saw in my console when I first tested your project.
This error shows the sequence of function calls leading to the issue. The setText() function in PDFTextField.js fails because it expects a string but receives null. This suggests that the Storyline variable may not have been initialized yet, causing player.GetVar() to return null when the script tries to retrieve it.
To prevent this, the ?? "" (Nullish Coalescing Operator) ensures that if player.GetVar() returns null, it defaults to an empty string ("") instead of breaking the setText() function. Once the actual Storyline variable values become available, they will automatically replace the empty string.
In short, this approach prevents errors when calling setText(), ensuring that the code remains functional even if a Storyline variable hasn’t been initialized yet.
- HunterBlake7 months agoCommunity Member
Thank you. It worked! You rock!
Related Content
- 7 months ago
- 2 months ago