Things to do with "this"

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">
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    <object name="thingy">
      <inherit name="editor_object" />
      <look type="script">
        msg ("It's just an average thingy.")
        this.prefix = "the"
        this.usedefaultprefix = false
      <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} {}).<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} {}.)<br/>")
          ShowMenu ("Click something here, too:", Split("one choice;another choice", ";"), true) {
            msg ("(ShowMenu msg) You use "+GetDisplayName(game.text_processor_this)+".<br/>")
      <feature_usegive />
      <displayverbs type="stringlist">
        <value>Look at</value>

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

this works inside of a wait script block, too:

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

What else can we do with "this"?

While playing around, I ran into this:

I tried to go by this example:

You are in the {=CapFirst(}

Here's my code:

 msg ("(wait script - text processor msg): You use {this.article}. (FYI: \"{=CapFirst(this.article)}\", in this case, is {this.prefix} {}.)<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.

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

Log in to post a reply.