Problem with checking for player death.

I'm using the off-line editor.

I have an attribute called Courage, which is initially set to 10, connected to the 'player' object, and is effectively 'hit points'.

I clicked 'add change script', and went into Code View.

I put in the following, which was meant to end the game if Courage got below 1.

<changedCourage type="script">
if (player.Courage < 1) {
  msg ("You have lost all hope. You kneel in despair, waiting for death.")
  finish
}
</changedCourage>

However when I try to run the game, I get the following error message:

Failed to load game.
The following errors occurred:
Invalid XML: Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 30, position 29.

I've tried replacing 'player.Courage' with 'Courage', but got the same result.


in code, it'd look like this, an example:

(I'm not familiar with the GUI/Editor's usage of the 'change' Script, but I know how it's done in code)

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

<object name="player"> 
  <attr name="parent" type="object">room</attr>
  <attr name="Courage" type="int">999</attr>
  <attr name="changedCourage" type="script">
    <![CDATA[
      if (player.Courage < 1) {
        msg ("You have lost all hope. You kneel in despair, waiting for death.")
        finish
      }
    ]]>
  </attr>
</object>

or like this (quest changed its syntax a bit over the versions, so there's 2 possible syntaxes that'll work, lol. I personally like using the above syntax better than the below syntax. Except a few, scripts / Dictionary Attributes, don't work with using the top syntax... might be a simple oversight by Alex and co, or maybe it's more technically difficult to code it, no idea why, but some stuff doesn't work using the top syntax):

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

<object name="player"> 
  <parent type="object">room</parent>
  <Courage type="int">999</Courage>
  <changedCourage type="script">
    <![CDATA[
      if (player.Courage < 1) {
        msg ("You have lost all hope. You kneel in despair, waiting for death.")
        finish
      }
    ]]>
  </changedCourage>
</object>

what the '<![CDATA[ scripts ]]>' tag does, is to tell quest that any '<' or '>' characters/symbols nested-within the code tag (its body/content/scripts) are to be recognized/seen as the 'greater than' or 'lesser than' operations/symbols/characters, instead of as the tag arrows, to prevent an error from quest wrongly reading your code, and thus it sending you an ERROR message.

so, unles there's something else going on, it looks like the GUI/Editor's specific code view for your 'changedCourage' special 'changed' Script Attribute of-within your 'player' Player Object, might also require you to put in the 'CDATA' code tag too:

<changedCourage type="script"><![CDATA[
  if (player.Courage < 1) {
    msg ("You have lost all hope. You kneel in despair, waiting for death.")
    finish
  }
]]></changedCourage>

or (whichever syntax/format convention/system you like using better)

<changedCourage type="script">
  <![CDATA[
    if (player.Courage < 1)
    {
      msg ("You have lost all hope. You kneel in despair, waiting for death.")
      finish
    }
  ]]>
</changedCourage>

or (whichever syntax/format convention/system you like using better)

<changedCourage type="script">
  <![CDATA[
    if (player.Courage < 1) {
      msg ("You have lost all hope. You kneel in despair, waiting for death.")
      finish
    }
  ]]>
</changedCourage>

or... etc etc etc combinations... lol

(doing the scripting in the GUI/Editor itself: 'add new script->etc etc etc' / NO use of: the specific code view mode or global-game code view modes, does not require the 'cdata' tags, as quest's GUI/Editor will handle it for you)


Invalid XML: Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 30, position 29.

This says a Quest attribute has a space at the start of its XMG tag. Looks like the change script itself is okay, but check Courage itself (and other attributes; in full code view, do CTRL-F, and search for "< ").

<changedCourage type="script">
 ^ check here, between the less than sign and the name

ah, so it's an accidental space (especially beware of highlighting too far: highlighting a space, and then copying and pasting --- at least this is what I accidentally do too often, lol)... those are the worst (hardest to find/spot/notice/realize) !!!

Nice find/work Pixie !!!, in tracking down what the error was (or in looking up / knowing that the hexidemal value given is that of a space or however you tracked down the error, meh-lol)


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

Support

Forums