Trigger on variable change
November 8, 2018 12:00 AM
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.
Discussion (13)
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.
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.
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!
Ask your developer to change or add the complete action to call an Actiongroup. In that group you then can add whatever you want.
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.
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.
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.
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.
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.
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...
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...
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 undefined
}
Discussions have been disabled for this post