Copy and Paste Multiple Variables?

Dec 07, 2021

Hey Heroes! This forum has always been super useful to me, but I may have come across a problem I don't yet see an answer for. 

I'm writing a course on how to tell your personal story, and I'm having the learner write out each component individually, which will be brought back to them at the end of the course. I've gotten all the variables to show at the end - but I need the learner to be able to copy them into another text field to perform final edits. 

I was able to come across this javascript which *almost* does what I want:

https://www.rabbitoreg.com/examples/p99/#/lessons/NPQ2NG0PlDgwjy_ZLbmw6t0PPaoWFEB6

However, the copying is limited to *one* variable at a time, and I don't have the javascript knowledge to have it copy multiple variables to the clipboard at once (preferably with some paragraph breaks between them). Does anyone know how to do this? 

Basic file with .js attached. 

Thanks!

3 Replies
Richard Watson

Hey Daniel, 

I'm sure Zsolt will see this and respond eventually. In the meantime, I'm working my way around JavaScript too. I was able to get it to capture multiple variables and allow me to copy them to the clipboard. Unfortunately, the formatting is a problem as you can see below. But, hey, some progress to be happy about!

I'm sure Zolt will have a much more elegant solution! :)

Richard

 

var player = GetPlayer();
var text1 = player.GetVar("MyIntro");
var text2 = player.GetVar("MyWhy");
var text3 = player.GetVar("MyChallenge");
var summary = text1 + ' ' + text2 + ' '+ text3;
player.SetVar("summary",summary);
var text = player.GetVar("summary");
copyFunction (text);
function copyFunction(tt) {
const copyText = tt;
const textArea = document.createElement('textarea');
textArea.textContent = copyText;
document.body.append(textArea);
textArea.select();
document.execCommand("copy");
alert("Copied to clipboard!");
}