error on restoring game (SOLVED AT LAST!)

Keep getting the following error when trying to restore a game,

Error: Object reference not set to an instance of an object.
[Sorry, an error occurred]


Was working fine earlier this evening and not changed anything in the code


I've narrowed this down, it occurs only if the player has performed a certain series of actions in a location (thrown 3 darts at a dartboard), the error doesn't occur at the time of playing, only if you save and then try to restore you get the

Error: Object reference not set to an instance of an object.
[Sorry, an error occurred]

I can't see anything wrong with my code, but here it is, this is driving me crazy so any help appreciated!

following is the script that runs when you 'play darts'

if (GetInt(Dartboard, "throws") = 0) {
msg ("You've not played darts in long time, but have always fancied yourself a good shot. You pick up the three darts and taking careful aim throw the first one...

....It bounces off the wall above the board and lands in the Pool table..The Landlord walks over and removes it, eying you wearily.")
AddToInventory (two darts)
IncreaseObjectCounter (Dartboard, "throws")
}
else if (GetInt(Dartboard, "throws") = 1) {
msg ("Ok, you've got your eye in now...you throw the second dart..

... it flies though the air, bounces off one of the wires and embeds itself in the bar. The Landlord walks over and removes it, cursing under his breath.")
RemoveObject (two darts)
AddToInventory (a dart)
IncreaseObjectCounter (Dartboard, "throws")
}
else if (GetInt(Dartboard, "throws") = 2) {
msg ("Feeling embarrassed and aware of the Landlord glaring at you, you take a deep breath and throw the last dart...

..it flys out of your hand and lands plumb in the middle of the treble-twenty area! In your relief you fist pump the air. The Landlord walks over and says "Nice throwing.." and then take the remaining dart and hangs a sign on the dartboard reading, "Do Not Touch!."")
MakeObjectInvisible (Dartboard)
MakeObjectVisible (Out of Order Dartboard)
RemoveObject (a dart)
IncreaseObjectCounter (Pub, "game")
}


The restore error only happens after throwing the third dart, if you then save and try to restore you get the error, but no error comes up while playing


In my experience if there is a prpoblem with the code it will refuse to save, so this is odd. However, in your last msg command, you havbe double quotes inside the text, which will confuse Quest. Put a \ before each one.

msg ("Feeling embarrassed and aware of the Landlord glaring at you, you take a deep breath and throw the last dart...

..it flys out of your hand and lands plumb in the middle of the treble-twenty area! In your relief you fist pump the air. The Landlord walks over and says \"Nice throwing..\" and then take the remaining dart and hangs a sign on the dartboard reading, \"Do Not Touch!.\"")

Thanks, just to be sure I removed all the " from the print message box, but still getting the error!


Before I delete the offending code (the throw of the 3rd dart is the issue, but god knows why) and re-write it could someone answer a more general question that might help.

Why would an error not show up in playing, compiling or saving, but only when restoring?


It's a mystery to me...


Just a thought... Would removing an object cause an error on loading the game if the removed object is referenced in code?

Try moving the dart to a storage room or making it invisible instead of removing object dart.


the 'RemoveObject' Function just sets the 'parent' Object Attribute's Value from 'YOUR_WHATEVER_OBJECT' to 'null', example below:

// before we use the 'RemoveObject' Function:

<object name="room">
  <object name="player">
  </object>
</object>

// or

<object name="room">
</object>

<object name="player">
  <attr name="parent" type="object">room</attr>
</object>

// after we use the 'RemoveObject' Function:
// RemoveObject (player)

<object name="room">
</object>

<object name="player">
</object>

// or

<object name="room">
</object>

<object name="player">
  <attr name="parent" type="object">null</attr>
</object>

we need to see your entire game code, for us to troubleshoot your issue and fix it for you, so if you're interested in finding out what the problem is, we'll need to see your entire game file, as fragments of code is not enough to help anyone fix an issue, due to how interconnected and all over the place the nature of code is, so to be able to fix your issue, we need the entire game code.

if you're game is online, you need to download it, and then unzip it (to be able to get into your 'xxx.quest' web/published game file to get at the needed 'xxx.aslx' game file, which you can then right click on and open with a text editor software)

all you got to do, is to right click on your game file (xxx.aslx), open it with a text editor software (notepad, wordpad, notepad++, Apple: texteditor, etc), highlight the entire code (this is your entire game code), copy it, and then paste it here in a post, but put it into the post's code box, via doing this:

M```
(paste your mass of entire game code here)
M```

but without the 'Ms', which will create this:

(paste your mass of entire game code here)

also, those 3 symbols is the keyboard key to the left of the '1' key of the horizontal row of numbers and above the 'TAB' key


Ooh, good suggestion! @XanMag


Making the darts invisible instead of removing them doesn't make any difference still get same error after saving after throwing 3rd dart and restoring.

I'm on a mac and don't know how to unzip the .quest file

Thanks for your help, appreciate it


Unlisted link is here if you can have a look, the player is currently located in the room where the error is (near end of game), rather than in their starting position which is in the room 'Your Hovel'

LINK REMOVED


Oooh. Online version. Yikes. I tried to create a new game and, as best I could duplicate your pub. But... I created a new game and the loading wheel spun for an eternity. If it ever starts to run more smoothly, I'll try again.

For what it is worth, I did play one of the "games" I have online, saved, and reloaded and everything works fine.


Solved it!! I had a counter name on the pub called 'game', change it to another name and now it saves and restores properly after playing darts,


Ah. Yes. For future reference, don't name anything in Quest by some common name used in Quest/Quest Code - game, open, closed, isopen, isclosed, object, save - etc. I did that a lot early on with doors and containers and the built-in code got confused with my flag names. Took me forever and a lot of frustration to figure that out! Can't believe I missed that. I looked at the counter name and didn't see it anywhere but it did not really cross my mind that it was interfering with the game.

Glad you got it resolved!


And the easiest way to avoid that is to put numbers after everything so calling a game element Game00 is fine. A good habit to get in to.


Thanks for your help everyone, what a lovely community this is.


or use unique labeling/conventions as I do: long descriptive ones (including the type of Element) with underscores, laughs:

player.strength_integer_attribute
player.strength_string_attribute
hegemonkhan_player_object.strength_integer_attribute
player_2_player_object.strength_integer_attribute

it's hard not to accidentally over-write the built-in stuff if you use simple labeling conventions, as there's so much built-in stuff...


Would be useful if this problem was flagged up in the tutorials for beginners like me


you should never over-write the built-in code, unless you know what you're doing, as either those built-in things will no longer work and/or you have issues like this, where you confuse quest.

there can only be one 'game' Object as it's a special Object for the game settings and etc stuff

also, here's some other requirements that the underlying quest code uses/requires:

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


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

Support

Forums