Error running script: Object reference not set to an instance of an object. (SOLVED)

I recently wanted to try making my own text adventure and stumbled upon quest! I went through the tutorial and everything seemed to be alright, except I keep getting the error: Error running script: Object reference not set to an instance of an object.

Whenever I do anything in the game, look at, go north, turn on, etc. It will show the text I set for that command on that object, or the description of the room if its a movement command, and then that error right after. It doesn't seem to be affecting my game at all other than the fact that I keep getting the error. I don't have very much coding knowledge so I'm not quite sure what this error means. Please help!


It is hard to say without seeing your game, but some possibilities, based on the fact that it happens each turn:

Is there a player object?
Do you have any turn scripts? If so, try disabling them. Could you paste the code into a post?
Do you have status attributes? If so, it might be worth deleting them, and seeing if that solves it.


to see (and then post here) your entire game code:

  1. right click on your 'xxx.aslx' Game File, and open it up with a text editor software (notepad, wordpad, notepad++, Apple: text editor, etc). highlight all of it (this is your entire game code), copy it, and then paste it here (see further below within this post for how to post it)

or

  1. within the GUI/Editor, click on the 'notepaper' like button/option in the horizontal menu bar at the top of the screen, which is between the 'play' and 'help' buttons/options. This is a toggle for going between the (full/entire game) Code View mode and the GUI/Editor mode. Once in the (full/entire game) Code View mode, highlight all of it, copy it, and then paste it here (see below on how to post it here)

to post your code (or just walls of text) here, you want to preserve your formatting (spacing, indenting, etc), which you do by using the 'code box' posting command:

m```
(paste your mass of code here)
m```

those weird characters/symbols is the key to the left of the '1' key (the horizontal row of numbers at the top of your keyboard) and above the left 'TAB' key. The key also shares (via: holding shift + key press) the tilde (~) character/symbol

but-and without the m's in front, which will produce this:

(paste your mass of code here)

for example, this is the default new game code (for English language users):

<asl version="550"> // I'm still using an older version of quest, the most recent is either: version="560", or: version="570"

  // these are the library files that actually make up this quest engine and GUI/Editor (yes, you can create your own game engine and GUI/editor, if you're a good programmer and know quest well):

  <include ref="English.aslx" />
  <include ref="Core.aslx" /> // this is a 'hub' file containing 'include ref' links to all of the individual 'core' library files

  // this is the special 'game' Game Settings Object, providing a lot of global (game wide) controls/options/features and game info (author, published, version, category, etc) and also info ('description') about your game for people looking at whether to download your game, and etc like stuff:

  <game name="NAME_OF_YOUR_GAME">

    <attr name="gameid" type="string">SOME_RANDOMLY_GENERATED_HASH_STRING</attr> // This is the full/long form, but String Attributes are (by quest engine/GUI/Editor) shortened into this form (which you may like better or not): <gameid>SOME_RANDOMLY_GENERATED_HASH_STRING</gameid>
    
    <attr name="version" type="string">1.0</attr> // this is just for your own versioning history as you make/update your game // again the shortened form is: <version>1.0</version>

    <attr name="firstpublished" type="string">2017</attr> // again the shortened form is: <firstpublished>2017</firstpublished>

  </game>

  <object name="room">

    <inherit name="editor_room" /> // this disappears upon playing the game, as it's just for adding GUI/Editor controls/options

    <object name="player">

      <inherit name="editor_object" /> // this disappears upon playing the game, as it's just for adding GUI/Editor controls/options
      <inherit name="editor_player" /> // this disappears upon playing the game, as it's just for adding GUI/Editor controls/options

    </object>
  
  </object>

</asl>

this is a library file:

(library files use the same extension as a game file does: xxx.aslx)

<library>
  // code
</library>

A library file is just code (almost the same as your game file), that upon adding the library file to your game (and having the library file in the same folder as your game file, so it can be found and used by your game), that library file's content/code is added to your game.

So, think of a library file as like a 'patch,xpac,mod,add-on' for your game (and/or it can even be the engine and GUI/Editor for your game too, if you're a good programmer and know quest well, as I already mentioned about in my previous post)

so, a library file can be as simple as adding a single Object for your game:

library file name example: dragon.aslx

<library>
  <object name="dragon">
  </object>
</library>

and for adding the library file to your game file, an example:

<asl version="BLAH">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <include ref="dragon.aslx" />

  <game name="BLAH">
    // BLAH ATTRIBUTES
  </game>
 
  // BLAH Objects, Functions, Verbs, Commands, Timers, Turnscripts, Objct Types, etc --- the rest of your game content/code

</asl>

and lastly, your 'dragon.aslx' is in the same folder as your 'xxx.aslx' game file


more details about library files:

they are used to "build-up" (initialize) your game (and/or the game-quest engine and/or GUI/Editor), so the order of them (top to bottom) matters, as well as any compatibility issues between them as well... (have you ever played a game that let's you add/manage/use mods? if so, then you should understand this stuff and its issues well)

upon starting up to play your game:

  1. first, the library files' content/code is added to your game (from top to bottom)
  2. then lastly, (after all of the library files' code/content is added to your game), then your game file's own content/code is added to your game
  3. your game begins, (... after the 'game' Game Setting Object's 'start' Script is done, if you have scripting for it), you can now play your game

back about your error/error-message:

unfortunately, it's one of the most broad/general errors/error-messages, as it could be many different types of errors in your code...

which definately means we're going to need to see your entire game code, in order to find and fix the issue(s) with your game/code.


in general, here's a bit about programming:

computers are stupid, you need to tell them what (types of stuff that) they're working with, which is known as: Data Types

Quest's Attribute's Data Types:

  1. Strings (aka, text: a single collection of characters/symbols, but not all of them)
  2. Integers (Non-Decimal Numbers), Doubles (Floats/Floating Points/Decimal Numbers)
  3. Booleans (true/false)
  4. Objects (names of Objects which are references/pointers to the actual Object)
  5. Scripts (actions/events of individual Objects: 'method' Attributes)
  6. Lists
  7. Dictionaries

anything (including numbers: numerical characters/symbols) in double quotes, is a String Value

anything not in double quotes, and is not a number, and is not a reserved/special value (such as 'true', 'false, 'this', and etc VARIABLE'S names), is an Object (reference/pointer) Value

some examples (using direct code scripting):

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION

(in the GUI/Editor: run as script -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION)

(quest uses the Value in scripting, to determine/parse what Data Type the Attribute is. Whereas, I'm just using the Attribute's name to show you how the Data Types differ and work: the Attribute's name has NOTHING to do with what Data Type it is)

(however, if using the GUI/Editor and/or directly in the xml/aslx tag block coding, you're setting the Attribute's Data Type, and so when you give it a Value or when you change it's Value in scripting, those Values' Data Types must match up with the Attributes' Data Types)

(I'm just using the 'player' Player Object for my Object, for this example, but it can be any Object: 'game', 'room', or your own/custom Objects, such as: 'orc', 'dragon', 'katana', 'room_99', etc etc etc)

(also, you'd give the Attribute an actual name, but I'm using it to just show how the Data Types differs and work)

player.string_attribute = "HK"
player.string_attribute = "34"
player.integer_attribute = 34
player.object_attribute = HK // also, there of course actually has to be an existing 'HK' Object, else you get an error
player.boolean_attribute = true
player.boolean_attribute = false
player.string_attribute = "true"
player.string_attribute = "false"
player.double_attribute = 4.3
player.string_attribute = "4.3"


mis-matched Data Types causes errors... so you got to be very careful

for example with doing addition arithmetic operation (again in direct code scripting):

// -----------------------

// NO error:
player.strength_integer_attribute = 0
player.strength_integer_attribute = player.strength_integer_attribute + 5
// player.strength_integer-attribute = (old: 0) + 5 = 5

// --------------------

// ERROR:

player.strength_integer_attribute = 0
player.strength_integer_attribute = player.strength_integer_attribute + "5"
// ERROR: can't arithemtic addition compute 'INTEGER' + "STRING' = HUH? computers (and humans too) have no idea what this would be, as it defies logic of math addition: 23 + hi = ILLOGICAL

// ----------------

// ERROR:

player.strength_string_attribute = "0"
player.strength_integer_attribute = player.strength_string_attribute + 5
// ERROR: can't compute arithmetic addition of: 'STRING' + 'INTEGER'


// NO error:

in programming, since it also involves Strings, there's concatenation (literally putting things together), which often uses the same '+' operation symbol as arithmetic addition:

player.strength_string_attribute = "0"
player.strength_string_attribute = player.strength_string_attribute + "5"
// player.strength_string_attribute = "05"


arithmetic addition vs concatention:

5 + 5 = 10
55 + 55 = 110

"5" + "5" = "55"
"55" + "55" = "5555"

"mama" + "mia" = "mamamia"
"mia" + "mama" = "miamama"

"mama" + "9" = "mama9"

"mama" + 9 = ERROR
9 + "mama" = ERROR

"mama" + " " + "mia" = "mama mia"
"mama " + "mia" = "mama mia"
"mama" + " mia" = "mama mia"
"mama" + " " + "9" + " " + "mia" + " " + "9" = "mama 9 mia 9"


you can see greater detail (though some of it is wrong, as this was back when I still didn't full understand some of the programming concepts such as the logic operators vs bit-logic operators) about Attributes and the 'if' Script usage here:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk

ask if you got any questions


I HATE that error message... Error running script: Object reference not set to an instance of an object.
It is the MOST unhelpful message!!!
(Other than the one I got so often in early BASIC... "Something is wrong"...)
But... One idea...
Typo...
or you are using a variable that you have not set a starting value...
IE:
player.hp=player.hp +1
but you forgot to tell Quest earlier...
player.hp=10


here's a step by step guide walkthrough creating your own demo/sample game, to understand the basics of Attribute usage:

http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help#37375

(let me know if you need help with anything, or if it doesn't work --- I might have made mistakes in my instructions and/or in my code, in the link above)


Thanks for the responses everyone.
I would also like to note that I have been receiving this error within multiple games. I first did the tutorial, and then tried making my own. The error continues to appear in both with the same nature. If you would like the other tutorial game's code as well let me know. Thanks for the help :)
Here is my game code:

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Test">
    <gameid>46142e44-44a6-42d1-8934-bfee04146603</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
  </game>
  <object name="Cave Entrance">
    <inherit name="editor_room" />
    <description><![CDATA[You are in front of a large cave. Its great rocky maw looms before you. <br/><br/>Visible exits are to the North, East, West, and South.]]></description>
    <object name="Cave">
      <inherit name="editor_object" />
      <scenery />
      <look>The cave entrance is large and almost menacing. Rotted boards of wood are covering the entrance. There is a gap big enough for a person to get through.</look>
      <alt type="stringlist">
        <value>Entrance</value>
        <value>Cave Entrance</value>
        <value>Maw</value>
      </alt>
    </object>
    <object name="Sign">
      <inherit name="editor_object" />
      <look>There is an old rusty sign nailed to the side of the cave. Its letters are a faded red.</look>
      <read>The sign says, "DANGER. Condemned Minecave. DO NOT ENTER."</read>
      <visible />
    </object>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="south" to="Open Plain">
      <inherit name="southdirection" />
    </exit>
  </object>
  <object name="Open Plain">
    <inherit name="editor_room" />
    <description><![CDATA[You are in an open plain. Tall grass stretches as far as the eye can see.<br/><br/>Visible exits are to the North.]]></description>
    <exit alias="north" to="Cave Entrance">
      <inherit name="northdirection" />
    </exit>
    <object name="Flier">
      <inherit name="editor_object" />
      <look>The flier is caught on a rock in the grass. It waves gracefully in the wind.</look>
      <take type="boolean">false</take>
      <takemsg>The flier is stuck in the grass. </takemsg>
      <read>Try out the newest text adventure by Lorelei Marcus! CAVE ADVENTURE. Cave Adventure will have you on the edge of your seat with excitement! PLAY IT NOW!</read>
    </object>
  </object>
</asl> 


hmm... nothing I could see looks wrong...

maybe has to do with the use of 'scenery' and/or maybe it doesn't like the spaces in your names (spaces are often BAD! Use underscores instead of spaces for your names, and then you can use the built-in 'alias' String Attribute for what you want their names to be, for example: Name: orc_grunt_1, Alias: orc grunt)

also, maybe you might want to give your Exits, names, too...

also, there might be parsing issues too (though getting rid of the spaces in your names should help with the parsing), as your various names begin the same...

(does the error at least say what is not an Objct reference? for example: 'orc_grunt_1' is not an Object error)


Hi. Just loaded up your game. Seems to be working ok for me. Not seeing an error message at all. Without seeing the error message myself, I'm not much help. Sorry!


It might be worth downloading a popular game (make sure it is Quest and a text adventure), and seeing if that plays okay, as it sounds like this is your install of Quest. That said, a bad install usually gives a more dramatic error.


Thank you for the help everyone, my game seems to be working now!


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

Support

Forums