Trigger on variable change

approg
approg Community Member Posts: 250 ♪ Opening Act ♪
How do I trigger an action when a variable's value changes?

I thought about making a loop and test very second of so but it seems a clunky way to do it.

Comments

  • smiller7502
    smiller7502 Community Member Posts: 181
    I don't think there's a way to do that -- but you should be able to trigger an action from whatever it is that's changing the variable.
  • danam
    danam Community Member Posts: 96
    Hello approg:

    This is very simple. Stan, actually is correct. It is something that must be triggered. You know where it needs to be placed dependent on the need for it.

    If I understand correctly, you want the action to happen as soon as the modification of the variable happens. This will require a check at that very point. Add a second action, after the modification action, to do whatever is required if the variable is satisfied. Be sure to delay this action by at least 2 tenths of a second to allow the computer modification to run.

    Hope this helped!
  • approg
    approg Community Member Posts: 250 ♪ Opening Act ♪
    Thanks for the help but I should've provided more background information.

    We've had an "interesting" interaction built for us in HTML5 that I've dropped into Lectora. The interaction changes the value of an Lectora custom variable when it's been completed. A few things in the Lectora title are inactive until the interaction has been completed.

    I don't want the developer of the interaction to hardcode anything other than the name of the Lectora variable (so that I can reuse the interaction in other titles). So I'd like my Lectora title to know when the variable has been changed and to then trigger an action.
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    Ask your developer to change or add the complete action to call an Actiongroup. In that group you then can add whatever you want.
  • approg
    approg Community Member Posts: 250 ♪ Opening Act ♪
    Thanks but while that would work in this instance, it means that the action or action group's name would need to be hard coded into the interaction - which is something I'd rather not have done.
  • timk
    timk Community Member Posts: 1,176 ☆ Superstar ☆
    It may be an idea to use a button instead of an action group. The button could be targeted by classname from the interaction, so it would easier to copy or reproduce without changing the interaction.
  • approg
    approg Community Member Posts: 250 ♪ Opening Act ♪
    I like the idea of using a button, thanks.
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    Following up on Tim's idea of using a button with a className. You could use a transparant button/element, on completion trigger that transparant button to become visible ( from the Html interaction ) and on that button/element you have onShow actions that will trigger whatever you want. This way on completion things can happen without user interaction. If you design the button/element to fit into the overall design it will look seamless.
    You even can use a incredible small element ( 1 pixel ) to have no visual impact.
  • timk
    timk Community Member Posts: 1,176 ☆ Superstar ☆
    Lectora creates an action group for each button called "button123.onUp()"  that runs all On:Click actions. You can just run that function from javascript.
  • approg
    approg Community Member Posts: 250 ♪ Opening Act ♪
    I've started looking into in earnest and it seems to be a good approach.

    One issue I'm having is how to trigger the onUp from withing the interaction when the title is published for seamless. Lectora is putting the interaction within one iframe which is within another iframe.
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916
    Interesting Tim... wondering however if and how that works.. in Lectora Online ( and probably the same approach now in Lectora 18 ) a textbutton on screen is renamed in the HTML to...
    <div id="tobj3462"  class="testBttn" >
    <button name="3462button">
    The latter...button name is only given several divs deeper, since now Lectora uses SVG for creating the graphics for the button. The className testBttn can be given to it as before...

    When i check the Trivantis generated code in Lectora Online... i find these codes for the buttons on my page...
    var textbutton3025 = new jsWndTextButton(); //ExitClose
    var textbutton2386 = new jsWndTextButton(); //Prev
    var textbutton3462 = new jsWndTextButton(); //Button 5
    var textbutton2388 = new jsWndTextButton(); //Next
    var textbutton2393 = new jsWndTextButton(); //TOC

    Interesting...
  • approg
    approg Community Member Posts: 250 ♪ Opening Act ♪
    Instead of using a button I used a small text box that contains just a single space (so that the text box is never visible). The text box is hidden and then I use JavaScript to make it visible and as it shows it triggers an action(s) attached to it.

    The text box has a CSS class added to it called "foo" (it doesn't matter that the associated CSS doesn't exist.)

    The relevant js in the interaction looks like

    var p = parent.window,
    t = p.document.querySelector(".foo");

    if (t && t.id && p[t.id + "actionShow"]) {

    p[t.id + "actionShow"]();
    }
  • timk
    timk Community Member Posts: 1,176 ☆ Superstar ☆
    The code for using the button is basically the same.
Sign In or Register to comment.

So You Wanna Be An eLearning ROCKSTAR?

We're all fans of eLearning here! Want to become an eLearning ROCKSTAR? Just click on one of the buttons below to start your rocking journey!