Inline variable replacement ...
March 11, 2017 12:00 AM
Hello
I have not been working with Lectora (16) for some time and returning to it now and finding a problem that I think I may have encountered before but have forgotten how to solve. So... sweating beads of embarrassment, here is my question.
I have a page. I want to display something like "Your score is VAR(Question_Score)"
Question_Score is set during the running of the page. However, the value displayed in my textbox is the initial value of Question_Score (which happens to be zero). I can hide and unhide the box but this does not trigger the change. Nor does the correct value appear if I I change the value using "onshow".
If I use the change contents approach and change the contents of the textbox, the correct value is displayed. But... I do not want/need to do that as I will lose formatting etc.
What the heck have I forgotten to do? I feel so silly... sorry everyone... (could not find it in the manual either). I think I need some kind of trigger (and it seems to have fallen out of my head).
Thanks for any help
Andrew
Discussion (9)
Can you share a sample? Then i can see what's missing... or find a non-programmer workaround ;-)
undefined
BTW.. a sample i made ( locally ) kept all formatting... Lectora 16.2.2
Thanks a lot Math - yes what you have there works for me too. That's not quite what I am trying to do.
Basically, I have a textbox with a VAR in it. The student clicks on a button and the VAR is incremented.
I would like the changed VAR to be displayed on the same page as the button that incremented it.
I attach a little program with an explanatory text.
Thank you so much for being so helpful.
Andrew
PS Please ignore the first file
undefined
From a course i cleaned out some unneeded elements and ending up with the setup as is..showing the score in a correctly formatted way. If you dont have the fonts ( Bodoni MT Black and Belwe BD BT ) used for the scoretextfields on your end, just replace them with any custom font to see it work.
This might help you...
Regards,
Math
PS. no javascript at all...
%VAR(Question_Score)% might do the trick..
As you say, changing content of a textfield removes all formatting. I solved that in several solutions by applying the formatting again after you changed content on a textfield...
- Change Content -undefinedVar(Question_Score)
If you use GSAP-Tweenmax this works perfectly
- TweenMax.set(sometextfield,{color:blue,fontSize:24,fontWeight:"bold", fontFamily:"Arial", textAlign:"left"});
In fact you can tween/animate the formatting ;-)
If you dont use GSAP-Tweenmax use this..
var tf = getSpanWithClass("text39Font1");
tf.style.fontSize = "45px";
tf.style.fontColor = "#006400";
function getSpanWithClass(cssClass) {
var elements = document.getElementsByTagName('span');
for (var i = 0; i undefined -1) {
return elements[i];
}
}
}
The function getSpanWithClass is a custom function i use a lot to get to the actual texts in Lectora... all dumpled in spans...
Thank you Math. As usual, You have come up with a great solution. Only problem for me is that I would like this to be available to non-programming course makers - and, also, if one has to engage in such programming, why have the inline variable replacement at all? I still think I am missing something. BTW, The inline values are correct on the next page (or in a popup) - or even in a message - just not when the text is displayed on a page on which the change is made. It does not happen automatically and I expect it needs a trigger to refresh itself. But what is that trigger (cannot be set content)?
Also BTW, I tried the %VAR(Question_Score)% solution, but it did not work.
Hi Andrew,
Seeing what you want/need makes it a lot easier to solve ;-)
Attached the solution. And in fact i do think the solution was in 'change contents'.
The formatting stays as needed, since its a standard textfield. I do think the thing you forgot and thus it failed to work was initialising the variable at the start of the course/page. Added that..and it works as wanted now.
Regards,
Math
And maybe the name of your original variable caused issues inside Lectora... not sure whether 'Question_Score' is a restricted name for custom variables, but changed that to a more custom name. Might have to do with why it didnot work in your version. Have had that before using a name that was too much alike a predefined one...so got into the habit of naming my custom variables... really custom ;-)
Hello Math
Sorry for my silence. I have been out of action for a couple of days. I will try to get back to you some time today.
Cheers for now
Andrew
Hello Math
Sorry it has taken me so long to get back. Thank you too for the example. Yes, I understand how the change content works in your example, but that was not what I was trying to do. BTW, it also does it without initialization of the variable as Lectora variables are self-initializing if you set the initial value in them. The problem is not changing the value of the variable in a small textbox with little text around it but changing it, perhaps several times, in a complicated text that cannot be inserted in a change contents action. I still have not found a solution but have worked around it using short texts and change content. If I do come up with a solution I will report back here.
Many many thanks
Andrew
undefined
Discussions have been disabled for this post