Fun with iframes, JS, and ASLEvents

http://textadventures.co.uk/games/view/eizxbbbxc0s-xm1pwjbnhq/game-loader


CLICK HERE TO VIEW THE CODE
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Game Loader">
    <gameid>4b62879a-2b20-4397-b606-1451600777b8</gameid>
    <version>0.0.17</version>
    <firstpublished>2017</firstpublished>
    <showpanes type="boolean">false</showpanes>
    <showlocation type="boolean">false</showlocation>
    <setcustomwidth />
    <customwidth>auto</customwidth>
    <start type="script"><![CDATA[
      msg ("<center><b>Enter {command:HELP} for a few tips.</b></center>")
    ]]></start>
    <subtitle>v{game.version}</subtitle>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <description type="string"></description>
    <message>{command:load:Load an online Quest game}.  {command:Insert text}.  {command:cmd:Send command to loaded game}. {command:ASLEvent:Run ASLEvent in loaded game}. {command:continue:Emulate 'CONTINUE' in loaded game}. {command:Save loaded game}.</message>
    <enter type="script">
    </enter>
    <beforeenter type="script">
    </beforeenter>
    <beforefirstenter type="script">
    </beforefirstenter>
    <firstenter type="script">
      msg (room.message)
    </firstenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <turnscript name="commands">
      <enabled />
      <script>
        msg (room.message)
      </script>
    </turnscript>
  </object>
  <command name="load_game">
    <pattern>load;load game</pattern>
    <script><![CDATA[
      firsttime {
        msg ("<h3><center><b>This will not work in the desktop version of Quest.  It only works in the web player.</b></center></h3>")
      }
      msg ("Please paste the url of the game into the text input field and press ENTER.<br/><br/>Example of a good url: <br/><code>http://play2.textadventures.co.uk/Play.aspx?id=y_nxkvwae0oior_yrejn7g</code>")
      get input {
        if (not StartsWith(result, "http://play2.textadventures.co.uk/Play.aspx")) {
          msg ("That's not a good url for an online Quest game.")
        }
        else {
          JS.eval ("$('#myFrame').css('display', 'none');")
          msg ("<iframe  style=\"display:none;\" id=\"myFrame\" src=\""+result+"\"height=\"400px\" width=\"100%\" />")
          JS.eval ("$('#myFrame').insertAfter('#txtCommand');$('#myFrame').css('display', 'block');")
          JS.eval ("var loaded = document.getElementById('myFrame').contentWindow;")
        }
      }
    ]]></script>
  </command>
  <command name="jsEvalCmd">
    <pattern>JS.#text#</pattern>
    <script>
      JS.eval (text)
    </script>
  </command>
  <command name="inserttext">
    <pattern>insert text</pattern>
    <script>
      msg ("Please enter the text you'd like to print and press ENTER.")
      get input {
        JS.loaded.addTextAndScroll (result)
      }
    </script>
  </command>
  <command name="help_kv">
    <pattern>help</pattern>
    <script><![CDATA[
      msg ("{b:Quick help:}<br/>You can use JS.eval or just JS.*<br/><br/>You can enter LOAD GAME then paste in the url of an online Quest game.  <br/><br/>Example of a good url: <br/><code>http://play2.textadventures.co.uk/Play.aspx?id=y_nxkvwae0oior_yrejn7g</code><br/><br/>You can enter INSERT TEXT then enter whatever text you'd like the loaded game to print.<br/><br/>To send a command, enter CMD then enter your command.<hr/>NOTE:  You can use JS.loaded.* to do nearly anything in the loaded game.<hr/>")
    ]]></script>
  </command>
  <command name="command_in_load_game">
    <pattern>command;cmd</pattern>
    <script><![CDATA[
      msg ("Please enter the command to send into the loaded game:")
      get input {
        JS.loaded.addTextAndScroll ("<br/>>"+result+"<br/>")
        JS.loaded.ASLEvent ("HandleSingleCommand", result)
      }
    ]]></script>
  </command>
  <command name="send_aslevent">
    <pattern>ASLEvent</pattern>
    <script><![CDATA[
      msg ("Please enter the ASLEvent function to run in the loaded game (Example: HandleSingleCommand):")
      get input {
        a = result
        msg ("Please enter the parameter (enter NULL if no parameter):")
        get input {
          b = result
          if (not b = "NULL") {
            JS.loaded.addTextAndScroll ("<br/>>ASLEvent(\""+a+"\", \""+b+"\")<br/>")
            JS.loaded.ASLEvent (a, b)
          }
          else {
            JS.loaded.addTextAndScroll ("<br/>>ASLEvent(\""+a+"\", \"\")<br/>")
            JS.loaded.ASLEvent (a, "")
          }
        }
      }
    ]]></script>
  </command>
  <command name="continue_in_game">
    <pattern>continue</pattern>
    <script>
      JS.loaded.endWait ()
    </script>
  </command>
  <command name="save_loaded">
    <pattern>save loaded game</pattern>
    <script>
      JS.loaded.saveGame ()
    </script>
  </command>
</asl>


Anyone have a link to a list of the default ASLEvents?

HandleSingleCommand works...

IncreaseScore would work, if I could figure out how to pass that parameter as an integer. Everything I tried passes a string, which breaks scoring in the loaded game.


Log in to post a reply.

Support

Forums