Explore the community Forums Lectora Lectora Questions & Answers Inline variable replacement …

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #349309 Score: 0
    Profile photo of Andrew Lian
    Andrew Lian
    Member
    beginner
    intermediate
    friend finder
    advanced
    contributor
    wise owl
    curious george
    9 pts
    @mlapl1

    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

    #349319 Score: 1
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    47 pts
    @mnotermans5114

    %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…

    1. Change Content -> Target: sometextfield  -> Set Text ->Var(Question_Score)
      If you use GSAP-Tweenmax this works perfectly
    2.  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 < elements.length; i++) {
      if((‘ ‘ + elements[i].className + ‘ ‘).indexOf(‘ ‘ + cssClass + ‘ ‘) > -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…

    This post has received 1 vote up.
    #349327 Score: 0
    Profile photo of Andrew Lian
    Andrew Lian
    Member
    beginner
    intermediate
    friend finder
    advanced
    contributor
    wise owl
    curious george
    9 pts
    @mlapl1

    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.

    #349329 Score: 0
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    47 pts
    @mnotermans5114

    Can you share a sample? Then i can see what’s missing… or find a non-programmer workaround 😉

     

    BTW.. a sample i made ( locally ) kept all formatting… Lectora 16.2.2

    #349332 Score: 0
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    47 pts
    @mnotermans5114

    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…

    Attachments:
    1. SampleScore.zip
    #349349 Score: 0
    Profile photo of Andrew Lian
    Andrew Lian
    Member
    beginner
    intermediate
    friend finder
    advanced
    contributor
    wise owl
    curious george
    9 pts
    @mlapl1

    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

     

    #349357 Score: 0
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    47 pts
    @mnotermans5114

    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

    Attachments:
    1. KeepFormats.zip
    #349366 Score: 0
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    47 pts
    @mnotermans5114

    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 😉

    #349759 Score: 0
    Profile photo of Andrew Lian
    Andrew Lian
    Member
    beginner
    intermediate
    friend finder
    advanced
    contributor
    wise owl
    curious george
    9 pts
    @mlapl1

    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

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.