Scripts and CDATA tags

Hi, I've been working with Quest offline version for a few months now on a text adventure game and noticed that not all script sections include [[CDATA[ tags in and others do, is there a requirement to have them or is it optional?
I mainly prefer working from a code view as I'm a programmer so I only use the interface for creating new objects or rooms.


The CDATA tags are required when the text (whether a script or not) contains < or > (and possibly &) as these have special meaning in XML. If those characters are not present, the CDATA tag is optional. Quest is good at working out if it is needed.


(filler for getting edited post updated)


as Pixie already stated:

if you're using the GUI/Editor, it handles it for you.

but, if you're writing in code directly (or also probably via the code-script window popups in the GUI/Editor too), you need to handle whether to add in the 'CDATA' tags or not.

what the 'cdata' tag does is to tell quest that any '<' and '>' are to be seen as 'greater than' and 'lesser than' operators/operations, rather than as xml/aslx/html code tags. This is extremely important, as it'll shift your entire code making it incoherent/unreadable.

// as xml/html/aslx 'creation' code tags:

<object name="test">
  <attr name="grade" type="string">unknown</attr>
  <attr name="score" type="int">-1</attr>
  <attr name="set_grade_script_attribute" type="script">
    <![CDATA[
      // scripting
    ]]>
  </attr>
</object>

// as 'greater/lesser than' operators/operations:

<object name="test">
  <attr name="grade" type="string">unknown</attr>
  <attr name="score" type="int">-1</attr>
  <attr name="set_grade_script_attribute" type="script">
    <![CDATA[
      if (test.score > 89) {
        test.grade = "A"
      } else if (test.score > 79) {
        test.grade = "B"
      } else if (test.score > 69) {
        test.grade = "C"
      } else if (test.score > 59) {
        test.grade = "D"
      } else {
        test.grade = "F"
      }
    ]]>
  </attr>
</object>

// without the 'CDATA' tags, and the mayhem it causes:

(due to not telling quest that some of the '<,>' are operators via the 'cdata' code tags, it causes the code to shift, and be completely error-filled (not able to even compile as can be seen by the below)

<object name="test">
  <attr name="grade" type="string">unknown</attr>
  <attr name="score" type="int">-1</attr>
  <attr name="set_grade_script_attribute" type="script">

      // now, these new/shifted lines/blocks are missing their beginning code tags (making it no longer able  to compile):

      if (test.score >

        89) {
        test.grade = "A"
      } else if (test.score >

        79) {
        test.grade = "B"
      } else if (test.score >

        69) {
        test.grade = "C"
      } else if (test.score >

       // and this is just floating data/scripting, a big no-no:

        59) {
        test.grade = "D"
      } else {
        test.grade = "F"
      }

  </attr>
</object>

and the 'cdata' tags are also used for telling quest that (for example) the html/xml: '<br>' (line break / carriage return), is to be seen as such, and not as quest's 'creation' code tags:

<object name="example_object">
  <attr name="example_script_attribute" type="script">
    <![CDATA[
      msg ("blah blah blah blah paragraph<br><br>blah blah blah blah paragraph")
    ]]>
  </attr>
</object>


Okay, great that's made it a lot clearer, thanks guys!


This is very helpful, I never actually understood what CDATA tags were, now I actually understand why I have had many of my operator problems, and why i fell back often to let the GUI help templating.


I once changed

<function name="PlaceEnterScript">
    msg ("So this is the spot... ")
  </function>

to

<function name="PlaceEnterScript">
    msg ("So this is the spot... <br />Enter TRAVEL to choose a destination.")
  </function>

image

But CDATA saves the day!

  <function name="PlaceEnterScript">
  <![CDATA[
    msg ("So this is the place... <br />Enter TRAVEL to choose a destination.")
  ]]>
  </function>


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

Support

Forums