Library Issue

Hi All,
I'm trying to create my own custom library, featuring functions I've modified and played around with as well as commands, so that I don't have to constantly enter them into each new game.
I've come across a small problem, in that one of the commands is throwing up an error:
Failed to load game. Object reference not set to an instance of an object.
I've looked at the command, and the only thing I can think of is the use of object1 and object2.
I thought these two operators were special cases.
Any help is appreciated.


K.V.

Hello,

Could you post the command's script?


The scripting should look familiar to 'The Pixie' and 'KV'
The first section is the command script that I'm having problems with.

<command name="CmdTie Object1 to Object2">
    <pattern type="string"><![CDATA[^(tie|attach|fasten) (?<object1>.*) to (?<object2>.*)$]]></pattern>
    <unresolved type="string"></unresolved>
    <script>
      // Originally from The Pixie. Modified by Doctor Agon. GetCmdVerb inspired by KV.
      // 1: Checks for the command used (tie/attach/fasten) and puts it into the variable 'cc'.
      cc = player.currentcommand
      // The function GetCmdVerb(cc) is used to display (tie/attach/fasten).
      if (GetBoolean(object1, "tiedto") and (object1.attachedto = object2)) {
        msg ("You've already done that.")
        // 2: Check if object1 is already attached to object2.
      }
      else if (not object1.parent = player) {
        msg ("You are not holding " + GetDisplayName(object1) + ".")
        // 3: Check if you are carrying object1.
      }
      else if (not GetBoolean(object1, "tie_able")) {
        msg ("You cannot " + GetCmdVerb(cc) + " the " + GetDisplayAlias(object1) + " to anything.")
        // 4: Check if object1 can be attached.
      }
      else if (not GetBoolean(object2, "attachable")) {
        msg ("You cannot " + GetCmdVerb(cc) + " anything to the " + GetDisplayAlias(object2) + ".")
        // 5: Check if object2 can be attached.
      }
      else {
        // 6: Success. Attach the two objects.
        msg ("You " + GetCmdVerb(cc) + " the " + GetDisplayAlias(object1) + " to the " + GetDisplayAlias(object2) + ".")
        object1.tiedto = true
        object1.attachedto = object2
        object2.attachedto = object1
        object1.parent = player.parent
      }
    </script>
  </command>

This next section is the 'GetCmdVerb' function that is used in the above script. This function hasn't been put into the library yet as I'm doing it in sections to check where the problem occurs.

<function name="GetCmdVerb" parameters="cc" type="string">
    // Doctor Agon. GetCmdVerb Inspired by KV.
    // 1: Set Variable cc=player.currentcommand. Use GetCmdVerb(cc) in script calling function.
    // 2: This section checks for the command used (push/pull/move) and puts it into the variable 'cmdverb'.
    if (StartsWith(cc, "push")) {
      cmdverb = "push"
    }
    else if (StartsWith(cc, "pull")) {
      cmdverb = "pull"
    }
    else if (StartsWith(cc, "move")) {
      cmdverb = "move"
    }
    // 3: This section checks for the command used (tie/attach/fasten) and puts it into the variable 'cmdverb'.
    if (StartsWith(cc, "tie")) {
      cmdverb = "tie"
    }
    else if (StartsWith(cc, "attach")) {
      cmdverb = "attach"
    }
    else if (StartsWith(cc, "fasten")) {
      cmdverb = "fasten"
    }
    // 4: This section checks for the command used (untie/unattach/unfasten) and puts it into the variable 'cmdverb'.
    if (StartsWith(cc, "untie")) {
      cmdverb = "untie"
    }
    else if (StartsWith(cc, "unattach")) {
      cmdverb = "unattach"
    }
    else if (StartsWith(cc, "unfasten")) {
      cmdverb = "unfasten"
    }
    return (cmdverb)
  </function>

I hope I've attributed the scripting correctly.


K.V.

Hrmm...

It works for me when I drop these two scripts into a fresh game.

Things I added to be able to test:

  • I added a rope, with "tie_able" set to true, and made it so you can pick it up.

  • I created a script for taking the rope (checking to see if it's tied to something first).

  • I made a tree, with "attachable" set to true.

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Tying">
    <gameid>2690094a-cc15-47ab-ac65-60d69b8e51ba</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
  </game>
  <command name="CmdTie Object1 to Object2">
    <pattern type="string"><![CDATA[^(tie|attach|fasten) (?<object1>.*) to (?<object2>.*)$]]></pattern>
    <unresolved type="string"></unresolved>
    <script>
      // Originally from The Pixie. Modified by Doctor Agon. GetCmdVerb inspired by KV.
      // 1: Checks for the command used (tie/attach/fasten) and puts it into the variable 'cc'.
      cc = player.currentcommand
      // The function GetCmdVerb(cc) is used to display (tie/attach/fasten).
      if (GetBoolean(object1, "tiedto") and (object1.attachedto = object2)) {
        msg ("You've already done that.")
        // 2: Check if object1 is already attached to object2.
      }
      else if (not object1.parent = player) {
        msg ("You are not holding " + GetDisplayName(object1) + ".")
        // 3: Check if you are carrying object1.
      }
      else if (not GetBoolean(object1, "tie_able")) {
        msg ("You cannot " + GetCmdVerb(cc) + " the " + GetDisplayAlias(object1) + " to anything.")
        // 4: Check if object1 can be attached.
      }
      else if (not GetBoolean(object2, "attachable")) {
        msg ("You cannot " + GetCmdVerb(cc) + " anything to the " + GetDisplayAlias(object2) + ".")
        // 5: Check if object2 can be attached.
      }
      else {
        // 6: Success. Attach the two objects.
        msg ("You " + GetCmdVerb(cc) + " the " + GetDisplayAlias(object1) + " to the " + GetDisplayAlias(object2) + ".")
        object1.tiedto = true
        object1.attachedto = object2
        object2.attachedto = object1
        object1.parent = player.parent
      }
    </script>
  </command>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="rope">
      <inherit name="editor_object" />
      <tie_able />
      <take type="script">
        if (HasAttribute(this, "tiedto")) {
          if (this.tiedto) {
            msg ("You can't.  It's attached to "+GetDisplayName(this.attachedto)+".")
          }
          else {
            msg ("You pick it up.")
            AddToInventory (this)
          }
        }
        else {
          msg ("You pick it up.")
          AddToInventory (this)
        }
      </take>
    </object>
    <object name="tree">
      <inherit name="editor_object" />
      <attachable />
      <take type="boolean">false</take>
      <takemsg>It is fixed in place.</takemsg>
    </object>
  </object>
  <function name="GetCmdVerb" parameters="cc" type="string">
    // Doctor Agon. GetCmdVerb Inspired by KV.
    // 1: Set Variable cc=player.currentcommand. Use GetCmdVerb(cc) in script calling function.
    // 2: This section checks for the command used (push/pull/move) and puts it into the variable 'cmdverb'.
    if (StartsWith(cc, "push")) {
      cmdverb = "push"
    }
    else if (StartsWith(cc, "pull")) {
      cmdverb = "pull"
    }
    else if (StartsWith(cc, "move")) {
      cmdverb = "move"
    }
    // 3: This section checks for the command used (tie/attach/fasten) and puts it into the variable 'cmdverb'.
    if (StartsWith(cc, "tie")) {
      cmdverb = "tie"
    }
    else if (StartsWith(cc, "attach")) {
      cmdverb = "attach"
    }
    else if (StartsWith(cc, "fasten")) {
      cmdverb = "fasten"
    }
    // 4: This section checks for the command used (untie/unattach/unfasten) and puts it into the variable 'cmdverb'.
    if (StartsWith(cc, "untie")) {
      cmdverb = "untie"
    }
    else if (StartsWith(cc, "unattach")) {
      cmdverb = "unattach"
    }
    else if (StartsWith(cc, "unfasten")) {
      cmdverb = "unfasten"
    }
    return (cmdverb)
  </function>
</asl>

If it works in this game, it should work in a library.

NOTE: Before anything else, I created a new game. I pasted that command into full code view. I pressed play. I saw no error. Then, I added everything else.


I've been using both scripts as part of my games for ages, but I thought that instead of copying and pasting each time I'd put them into a library. For some reason Quest produced the error message. Would it have anything to do with the order I'm adding the scripts to the library. For instance if I put the command script before the function script, Quest won't know what 'GetCmdVerb' is. Would that cause the error.


it might not be the library's code... it could be your game code is not adding an Object as an argument for whatever library code it's using.


unfortunately, the 'not an Object' ERROR MESSAGE is the most ambigious of all, it can mean anything is wrong... this will be harder for us to help you, the best thing you can do... is to provide your entire game code and all library (if you're using multiple libraries) for us to look through, to find the issue.


I'm not sure if positioning within a library matters, but if you're using multiple libraries, then their positioning matters for your game. As your game is built-up ("initialized") first from the libraries (top to bottom) and then by your game's code itself. This is the same as 'patch/mod' errors/compatibility-issues with other games...


As HK says, that is one of the less useful error messages...

The order things occur does not matter, in that you can have the command in the library before the function it uses in your game. The only time order matters is when you have two things with the same name, and in that case the first is ignored (so may be worth checking if there is something with the same name as your command in either file, as this could have been ignored before, but moving to the library would reverse the order).

Do you get the error when you try to edit your game, when you start playing it, or during play?

What happens if you paste the command back into your game? It might be worth going back a step, to not using a library, then add a blank library to your game. My guess is thatit is probably not an issue with libraries and will still be there when you paste the command back into your game.

ETA: I had a quick play around with variables and objects that do not exist and could not get that error message. Let us know what caused it and I will make a note of it for next time.


The error message occurs in loading the game.

I have the command file saved as a library file.

<library>

<<<COMMAND SCRIPT>>>

</library>

I have then gone to the section at the bottom of the tree on the left-hand side.
Include libraries. Added the corresponding file name for my library, pressed 'save', pressed 'reload'.
It's at this point that as the game loads or reloads, it produces the error message.


K.V.

I am messaging you my email address.

If you'd like, you can send me all the files in your game's directory (or just that one library), and I shall investigate.


Success. I was just going to email you KV, when I thought I'd have another go at trying to get this to work.
Do not know what I've done differently, but it worked.
Thanks all for all your help.


K.V.

Yay!

...and it's no problem.

I like to solve problems and learn stuff.

Everything else bores me.

Me: You mean your game works? Well, why would I want to fool around with a game that works?!? That doesn't sound challenging at all, does it?


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums