Problem with the "Turn Based Events" sample code?

I'm trying to learn how to do turn based events and I copied the example code from the documentation page almost exactly, but I must have messed something up because I'm getting this error whenever it tries to trigger:

Error running script: Error compiling expression 'evt.turn <= game.turn': CompareElement: Operation 'LessThanOrEqual' is not defined for types 'Int32' and 'String'

This is the relevant section. Did I mess up some indent or what? I keep comparing it to the sample code and I can't find what I messed up.

<object name="dead_events">
    <inherit name="editor_room" />
    <object name="event2">
      <inherit name="editor_object" />
      <inherit name="event_type" />
      <auto type="boolean">false</auto>
      <action type="script">
        if (player.parent = room2) {
          msg ("Event 2")
          event3.turn = 2 + game.turn
          event3.parent = active_events
          this.parent = dead_events
        }
        else {
          msg ("... waiting")
        }
      </action>
    </object>
    <object name="event3">
      <inherit name="editor_object" />
      <inherit name="event_type" />
      <action type="script">
        msg ("Event 3")
      </action>
    </object>
  </object>
  <object name="active_events">
    <inherit name="editor_room" />
    <object name="godzilla_event_1">
      <inherit name="editor_object" />
      <inherit name="event_type" />
      <turn type="int">3</turn>
      <nextturn type="int">2</nextturn>
      <next type="object">event2</next>
      <action type="script">
        msg ("Event 1")
      </action>
    </object>
  </object>
  <turnscript name="eventhandler">
    <enabled />
    <script><![CDATA[
      game.turn = game.turn + 1
      foreach (evt, GetDirectChildren (active_events)) {
        if (evt.turn <= game.turn) {
          do (evt, "action")
          if (evt.auto) {
            evt.parent = dead_events
            if (HasAttribute (evt, "next")) {
              evt.next.turn = evt.nextturn + game.turn
              evt.next.parent = active_events
            }
          }
        }
      }
    ]]></script>
  </turnscript>
  <type name="event_type">
    <done type="boolean">false</done>
    <auto />
    <turn type="int">-1</turn>
    <action type="script">
      msg ("TODO")
    </action>
  </type>
</asl>```

Have you given the game an attribute called turn?

The error message suggests that game.turn is a string, when it needs to be a number. So go into the attributes of game and make sure that its turn attribute is the right type.


I had not made a turn attribute, and I also hadn't given some of my events the auto attribute or the turn attribute with an actually usable turn count. It's working now, thank you!


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

Support

Forums