Question about solving this weird alias error...

Error running script: Error evaluating expression 'ToString(eval(section))': Error compiling expression 'GetDisplayName(this)': Unknown object or variable 'this' 

So basically, I want the name on the "monster type" to refer to the current monster's name/alias in an expression.

I used this...

You are attacking the {=GetDisplayName(this)}

But in spite of "this" already being defined it's still throwing the above error.

Would this be the solution?

GetDisplayAlias(this)

OR 

You are attacking the "+ GetDisplayName(this) +"

Thank for your help in advance!

Anonynn.


I think it's merely that 'this' can't be used with/within the text processor commands...

(using 'this' goes "hand in hand" with using the Types, but unfortunately --- I think, 'this' doesn't go with using the text processor commands, unfortunately)

(if you can understand them... you might want to use the 'Templates' instead... as I think they'll work for doing all of this stuff you want --- maybe mrangel/pixie can help you with using Templates)

so, use this code line that you already posted (corrected up a bit though for you, lol --- you can change it up if you want it to be different sentence and/or ending punctuation of course):

msg ("You are attacking the " + GetDisplayName(this) + "!")


<!-- I think it has to be a Script Attribute, unfortunately -->

<object name="orc">
  <inherit name="monster_type" />
</object>

<type name="monster_type">

  <attr name="attack" type="script">

    do (this, "attack_prompt_message")

  </attr>

  <attr name="attack_prompt_message" type="script">

    msg ("You are attacking the " + GetDisplayName(this) + "!")

  </attr>

</type>

<verb>

  <pattern>attack</pattern>
  <property>attack</property>
  <defaultexpression>You can't attack that!</defaultexpression>

</verb>

this is a variable; and you can't use variables in text processor commands.

Variables only exist in the function where they're created; they're not visible inside any other functions that one calls. This includes built in and hard coded functions like ProcessText(), msg() and eval().

You can either tell the tex processor which object you mean by doing game.text_processor_this = this (using an attribute to pass the value of 'this' to the text processor), or use the "You are attacking the "+ GetDisplayName(this) +"." method.


game.text_processor_this = this

Yeah, this is how I originally got the "this" identified. But it still didn't recognize {=GetDisplayName(this)}

But I'll definitely try what you and HK suggested and get back to you ^_^

Anonynn.


But it still didn't recognize {=GetDisplayName(this)}

that's wrong


you'd do this (argh, un-intended pun, 'this' is too general a word, like 'type', lol):

{=GetDisplayName(game.text_processor_this)}

(the 'game.text_processor_this' is an 'Attribute' VARIABLE, which the text processor command CAN use, and so we use this Attribute, the 'game.text_processor_this' Attribute, which is storing the 'PARENT_OBJECT' Object in it, the 'this = PARENT_OBJECT' 'Variable' VARIABLE, as we can NOT use this 'Variable' VARIABLE, the 'this' 'Variable' VARIABLE, in the text processor command directly)

(ach... I used 'this' too many times in the above... hopefully it's not confusing... lol)


Yeah, this is how I originally got the "this" identified. But it still didn't recognize {=GetDisplayName(this)}

Sorry, my brain was on the wrong track there.
Use of this in the text processor can be a little confusing. At present, it doesn't work in eval sections.

To fix this, you can override this function from CoreOutput:

  <function name="ProcessTextCommand_Eval" parameters="section, data" type="string">
  <![CDATA[
    params = NewObjectDictionary()
    if (HasObject (game, "text_processor_this")) {
      dictionary add (params, "this", game.text_processor_this)
    }
    if (not IsRegexMatch("[^\\w\\s]", section, "tp_punctuation_check")) {
      section = section + "()"
    }
    return (ToString(eval(section, params)))
  ]]>
  </function>

HK's solution works too. But the function override above (off the top of my head) should make this work a lot more easily.

Sorry about that ^_^ I've poked the code for the text processor a lot, trying to get it to work more intuitively, but I'm not so good at remembering which bits I've shown Pixie.


Log in to post a reply.

Support

Forums