Things to do with "this"

K.V.
11 Nov 2017, 05:13

Everything in this example works:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="This">
    <gameid>ba9f4d22-b97a-4444-8da9-dceebd775455</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="thingy">
      <inherit name="editor_object" />
      <look type="script">
        msg ("It's just an average thingy.")
        this.prefix = "the"
        this.usedefaultprefix = false
      </look>
      <take />
      <use type="script"><![CDATA[
        this.prefix = "the"
        this.usedefaultprefix = false
        msg ("(normal msg)  You use "+GetDisplayName(this)+".<br/>")
        game.text_processor_this = this
        msg ("(text processor msg): You use {this.article}. (FYI: \"{this.article}\", in this case, is {this.prefix} {this.name}).<br/>")
        wait {
          msg ("(wait script - normal msg) You use "+GetDisplayName(this)+" inside of the <code>wait</code> script.<br/>")
          msg ("(wait script - text processor msg): You use {this.article}. (FYI: \"{this.article}\", in this case, is {this.prefix} {this.name}.)<br/>")
          ShowMenu ("Click something here, too:", Split("one choice;another choice", ";"), true) {
            msg ("(ShowMenu msg) You use "+GetDisplayName(game.text_processor_this)+".<br/>")
          }
        }
      ]]></use>
      <feature_usegive />
      <displayverbs type="stringlist">
        <value>Look at</value>
        <value>Take</value>
        <value>Use</value>
      </displayverbs>
    </object>
  </object>
</asl>

This is where the magic's at: game.text_processor_this = this.

http://docs.textadventures.co.uk/quest/quest5_7.html


this works inside of a wait script block, too:

wait{
  msg ("'this' is "+GetDisplayName(this)+".")
}
'this' is a thingy.

What else can we do with "this"?


K.V.
11 Nov 2017, 05:21

While playing around, I ran into this:

I tried to go by this example:

You are in the {=CapFirst(player.parent.name)}

Here's my code:

 msg ("(wait script - text processor msg): You use {this.article}. (FYI: \"{=CapFirst(this.article)}\", in this case, is {this.prefix} {this.name}.)<br/>")

...and here's the output:

Error running script: Error evaluating expression 'ToString(eval(section))': Error compiling expression 'CapFirst(this.article)': Unknown object or variable 'this'
Error running script: Error compiling expression 'Instr(text, "{")': FunctionCallElement: Could find not function 'Instr(Object, String)'
(wait script - text processor msg): You use it. (FYI: "", in this case, is the thingy.)


NOTE: The example, itself, works. It's the "this" that's the problem there. This explains the "to some degree" in this statement:

Historically, the text process cannot cope with “this” in the embedded code. Now it can, at least to some degree. You do have to tell it what “this” refers to first, by setting game.text_processor_this.


K.V.
11 Nov 2017, 05:26

I'm only messing with this to help with this.