So I'm having a problem with escape characters in a series of MWL functions - it's kind of hard to explain, but I'll do my best!
I have an MWL timer function, which ticks once, and then calls iterateClass, and another repeating timer, which itself calls iterateClass. This needs to be created in javascript and set via the setAttribute function, because the length of the timer is dynamic. Obviously, because there are several nested functions here, I need to escape the quotation characters, sometimes more than once. So, what I end up with is:
I know that looks pretty awful, and is probably hard to make sense of, but in the local simulator it does work - the first timer goes off once, iterates the class correctly, and then starts a new timer which periodically ticks that same class.actionString += "mwl.timer('timer2', '" + ((digit3 * 1000) + 1000) + "', '1', 'mwl.iterateClass(\\\'#timer_digit2\\\', \\\'clock_digit\\\', \\\'prev\\\', \\\'10\\\', \\\'true\\\', \\\'\\\'); mwl.timer(\\\'timer2\\\', \\\'10095\\\', \\\'0\\\', \\\'mwl.iterateClass(\\\\\\\'#timer_digit2\\\\\\\', \\\\\\\'clock_digit\\\\\\\', \\\\\\\'prev\\\\\\\', \\\\\\\'10\\\\\\\', \\\\\\\'true\\\\\\\', \\\\\\\'\\\\\\\');\\\'); ');\n";
When this is properly parsed by the browser, the resulting code is as follows, which is correct:
Note that the long strings of slashes have translated into groups of 3 slashes, as they should do.<td id="start_button_btc" onclick="mwl.timer('btc_game_timer2', '8000', '1', 'mwl.iterateClass(\'#timer_digit2\', \'clock_digit\', \'prev\', \'10\', \'true\', \'\'); mwl.timer(\'btc_game_timer2\', \'10095\', \'0\', \'mwl.iterateClass(\\\'#timer_digit2\\\', \\\'clock_digit\\\', \\\'prev\\\', \\\'10\\\', \\\'true\\\', \\\'\\\');\'); ');
">Start!</td>
Ok so, hopefully this has been clear so far! The problem I am having is as follows:
When running in the cloud preview simulator, this only works the first time. So the first time through this code, everything works nicely - the player clicks the button (the code for which is above), the <div> containing that button is hidden and the app progresses. When it comes back around (ie, this button is displayed again, for the second time), those groups of 3 slashes have been replaced with only 2 slashes: ie, the html in the browser the second time around is as follows:
The groups of "\\\" in the final function have been replaced with "\\", which obviously doesn't work correctly when the button is clicked.<td id="start_button_btc"
onclick="mwl.timer('btc_game_timer2','10000','1','mwl.iterateClass(\'#timer_digit2\',\'clock_digit\',\'prev\',\'10\',\'true\',\'\');mwl.timer(\'btc_game_timer2\',\'10095\',\'0\',\'mwl.iterateClass(\\'#timer_digit2\\',\\'clock_digit\\',\\'prev\\',\\'10\\',\\'true\\',\\'\\');\');');">
Start!</td>
So, my question is, is this something I'm causing somehow? It seems strange to me that this code would work the first time through, but not the second (and works constantly in local simulator mode). Is there any way to fix it? Or is there a better way to have nested MWL functions like this?
Like I said, this is a pretty tricky problem, so hopefully I've explained it clearly. Any assistance on this problem will be greatly appreciated.

Reply With Quote

