Creating content from a text file - I'm bringing it back!

K.V.
18 Oct 2017, 06:30

Here's the file I was recently playing with:

new=kv_special_item_1
alias=black shard of ∞
look=It's the black shard, which is the most powerful of them all!
parent=game.pov

find=kv_green_shard
parent=game.pov

new=thingy
parent=game.pov.parent

new=anotherThing
parent=player.parent

new=thing3
parent=here

And you can find the good stuff here:

http://textadventures.co.uk/forum/games/topic/ipp8zwszfkgs7gvslljsmw/pixies-quest-new-game-from-qfq-and-an-open-thank-you-to-the-man-himself#79976cde-b1e4-492e-b4dd-fce2fb330c4d


The original post by The Pixie, just over 2 years ago:

https://textadventures.co.uk/forum/samples/topic/5512/creating-content-from-a-text-file


K.V.
11 Dec 2017, 15:43

UPDATE

Now you can bring in text from a Gist (or something of that nature).


UPDATED AGAIN

Now you can set up take and takemsg.


Play or Download the example game.


Get the code here:

Quest_load-text-from-url


...or click below to view the code:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Get Text from URL">
    <gameid>3cc0685e-0493-4ece-af9e-57c7b17f6661</gameid>
    <version>example-v0.0.11</version>
    <firstpublished>2017</firstpublished>
    <attr name="example_url">https://gist.githubusercontent.com/KVonGit/395b7022073fe6e30f89f6c8911100a8/raw/4db24917bf20e8c61156dfcc13c5eac7abd61642/addtogame.md</attr>
    <description><![CDATA[To load text from a Gist (or something of that nature):<br/><br/>LoadOnlineFile(url)<br/><br/>---<br/>To load text from a file in the game's main directory:<br/><br/>LoadFile(filename)<br/><br/>---<br/>Link to this game's code:<br/><br/>https://gist.github.com/KVonGit/1824536eea4bc2697bc923be12cfee55]]></description>
    <feature_advancedscripts />
    <commandpane />
    <start type="script">
      JS.eval ("getTextFromUrl = function(url){theUrl = url;var xmlHttp = new XMLHttpRequest();xmlHttp.open( 'GET', theUrl, false );xmlHttp.send( null );ASLEvent('SetText', xmlHttp.responseText);};")
    </start>
    <inituserinterface type="script">
      JS.setCommands ("Load File", "black")
    </inituserinterface>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script">
      // LoadOnlineFile (game.example_url)
    </enter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <command name="load_data_cmd">
    <pattern>load data;loaddata;loadfile;load file</pattern>
    <script><![CDATA[
      Ask ("Would you like to load the example?") {
        if (result) {
          url = game.example_url
          LoadOnlineFile (url)
        }
        else {
          msg ("Okay.<br/>")
          msg ("Please enter the url.")
          msg ("<br/>Example url:<br/> <span style='word-wrap: break-word;'>"+game.example_url)
          get input {
            url = result
            LoadOnlineFile (url)
          }
        }
      }
    ]]></script>
  </command>
  <function name="SetText" parameters="text">
    game.downloaded_text = text
    // msg (game.downloaded_text)
  </function>
  <function name="LoadOnlineFile" parameters="url">
    JS.getTextFromUrl (url)
    msg ("Downloading online content...")
    SetTimeout (5) {
      s = game.downloaded_text
      if (not HasString(game, "downloaded_text")) {
        error (" Download failed. Try again.  If playing online, this won't work just yet.")
      }
      current_object = null
      game.setUp = false
      foreach (line, Split(s, "\n")) {
        line = Crop(line)
        if (not line = "" and not StartsWith(line, "#")) {
          bits = Split(line, "=")
          if (StringListItem(bits, 0) = "new") {
            if (ListCount(bits) = 2) {
              create (StringListItem(bits, 1))
              current_object = GetObject(StringListItem(bits, 1))
            }
            else {
              create (StringListItem(bits, 2), StringListItem(bits, 1))
              current_object = GetObject(StringListItem(bits, 2))
            }
          }
          else if (StringListItem(bits, 0) = "find") {
            current_object = GetObject(StringListItem(bits, 1))
            if (current_object = null) {
              error ("Failed to find " + StringListItem(bits, 1) + " in the game world. Things will go badly...")
            }
          }
          else if (StringListItem(bits, 0) = "exit") {
            create exit (StringListItem(bits, 2), null, null, null, StringListItem(bits, 1))
            current_object = GetObject(StringListItem(bits, 2))
          }
          else if (StringListItem(bits, 0) = "parent") {
            newParent = StringListItem(bits, 1)
            if (newParent = "game.pov") {
              current_object.parent = game.pov.name
              game.setUp = true
              list remove (bits, "game.pov")
              list add (bits, game.pov.name)
            }
            else if (newParent = "game.pov.parent") {
              current_object.parent = game.pov.parent.name
              game.setUp = true
              list remove (bits, "game.pov.parent")
              list add (bits, game.pov.parent.name)
            }
            else if (newParent = "here") {
              current_object.parent = game.pov.parent.name
              game.setUp = true
              list remove (bits, "here")
              list add (bits, game.pov.parent.name)
            }
            else if (newParent = "player.parent") {
              current_object.parent = player.parent.name
              game.setUp = true
              list remove (bits, "player.parent")
              list add (bits, player.parent.name)
            }
            current_object.parent = GetObject(StringListItem(bits, 1))
            if (current_object.parent = null) {
              error ("Failed to find " + StringListItem(bits, 1) + " in the game world. Things will go badly...")
            }
          }
          else if (StringListItem(bits, 0) = "to") {
            current_object.to = GetObject(StringListItem(bits, 1))
            if (current_object.to = null) {
              error ("Failed to find " + StringListItem(bits, 1) + " in the game world. Things will go badly...")
            }
          }
          else {
            if (LCase(StringListItem(bits, 1)) = "false") {
              set (current_object, StringListItem(bits, 0), false)
              game.setUp = true
            }
            else if (LCase(StringListItem(bits, 1)) = "true") {
              set (current_object, StringListItem(bits, 0), true)
              game.setUp = true
            }
            else if (IsInt(StringListItem(bits, 1))) {
              set (current_object, StringListItem(bits, 0), ToInt(StringListItem(bits, 1)))
              game.setUp = true
            }
            if (not game.setUp) {
              set (current_object, StringListItem(bits, 0), StringListItem(bits, 1))
            }
            else {
              // set (current_object, StringListItem(bits, 0), StringListItem(bits, 1))
            }
          }
        }
      }
      msg ("Done.")
    }
  </function>
  <function name="LoadFile" parameters="filename">
    game.splitter = GetFileData (filename)
    current_object = null
    game.setUp = false
    foreach (line, Split(game.splitter, "\n")) {
      line = Crop(line)
      if (not line = "" and not StartsWith(line, "#")) {
        bits = Split(line, "=")
        if (StringListItem(bits, 0) = "new") {
          if (ListCount(bits) = 2) {
            create (StringListItem(bits, 1))
            current_object = GetObject(StringListItem(bits, 1))
          }
          else {
            create (StringListItem(bits, 2), StringListItem(bits, 1))
            current_object = GetObject(StringListItem(bits, 2))
          }
        }
        else if (StringListItem(bits, 0) = "find") {
          current_object = GetObject(StringListItem(bits, 1))
          if (current_object = null) {
            error ("Failed to find " + StringListItem(bits, 1) + " in the game world. Things will go badly...")
          }
        }
        else if (StringListItem(bits, 0) = "exit") {
          create exit (StringListItem(bits, 2), null, null, null, StringListItem(bits, 1))
          current_object = GetObject(StringListItem(bits, 2))
        }
        else if (StringListItem(bits, 0) = "parent") {
          newParent = StringListItem(bits, 1)
          if (newParent = "game.pov") {
            current_object.parent = game.pov.name
            game.setUp = true
            list remove (bits, "game.pov")
            list add (bits, game.pov.name)
          }
          else if (newParent = "game.pov.parent") {
            current_object.parent = game.pov.parent.name
            game.setUp = true
            list remove (bits, "game.pov.parent")
            list add (bits, game.pov.parent.name)
          }
          else if (newParent = "here") {
            current_object.parent = game.pov.parent.name
            game.setUp = true
            list remove (bits, "here")
            list add (bits, game.pov.parent.name)
          }
          else if (newParent = "player.parent") {
            current_object.parent = player.parent.name
            game.setUp = true
            list remove (bits, "player.parent")
            list add (bits, player.parent.name)
          }
          current_object.parent = GetObject(StringListItem(bits, 1))
          if (current_object.parent = null) {
            error ("Failed to find " + StringListItem(bits, 1) + " in the game world. Things will go badly...")
          }
        }
        else if (StringListItem(bits, 0) = "to") {
          current_object.to = GetObject(StringListItem(bits, 1))
          if (current_object.to = null) {
            error ("Failed to find " + StringListItem(bits, 1) + " in the game world. Things will go badly...")
          }
        }
        else {
          if (LCase(StringListItem(bits, 1)) = "false") {
            set (current_object, StringListItem(bits, 0), false)
          }
          else if (LCase(StringListItem(bits, 1)) = "true") {
            set (current_object, StringListItem(bits, 0), true)
          }
          else if (IsInt(StringListItem(bits, 1))) {
            set (current_object, StringListItem(bits, 0), ToInt(StringListItem(bits, 1)))
          }
          if (not game.setUp) {
            set (current_object, StringListItem(bits, 0), StringListItem(bits, 1))
          }
          else {
            set (current_object, StringListItem(bits, 0), game.pov)
          }
        }
      }
    }
    msg ("Done.")
  </function>
  <function name="Crop" parameters="s" type="string"><![CDATA[
    start = 1
    end = LengthOf(s)
    for (i, 1, LengthOf(s)) {
      if (Asc(Mid(s, i, 1)) < 33) {
        if (start = i) {
          start = i + 1
        }
      }
      else {
        end = i
      }
    }
    return (Mid(s, start, end - start + 1))
  ]]></function>
</asl>