Pulpscript Solution: Calling Events on Walkable World Tiles

I just wrote some Pulpscript for someone who absolutely want to attach scripting functionality to walkable world tiles. In short, this can be done by hardcoding the coordinates in the player's update event. Details follow.

First of all, the Pulpscript if statement is limited to simple conditions, so I used a trick to combine the X and Y values for a chain of comparisons. This is not important if you only have one or two hardcoded coordinate values, but it is very handy if you have a ton of hardcoded locations.

// event_position = player XXYY
event_position = event.px
event_position *= 100
event_position += event.py

The next thing I did was assign a developer friendly room id to each room in the enter event. I also renamed rooms with leading numbers to match. So, if my room is 012_sleepy_inn, then the enter event looks like this.

on enter do
  room = 12
end

The next thing I did was gate world tile code behind the room id in the player's update event. Obviously, you would need a block for each room with world tile event functionality. Putting it all together for a single room looks something like this.

on update do
  // one block per room
  if room==12 then
    // event_position = player XXYY
    event_position = event.px
    event_position *= 100
    event_position += event.py
    if event_position==608 then
      say "Do something at coordinates 6, 8."
    elseif event_position==2010 then
      say "Do something else at 20, 10."
    elseif event_position==1604 then
      say "Another event at 16, 4.."
    end
  end
end

Note that the same general hardcoded coordinate approach could be used to create something like sprites that warp the player when interacted with.

on interact do
  // one block per room
  if room==999 then
    // event_position = sprite XXYY
    event_position = event.tx
    event_position *= 100
    event_position += event.ty
    if event_position==1205 then
      goto 12,5 in "001_first_room"
    elseif event_position==1612 then
      goto 21,13 in "002_second_room"
    elseif event_position==602 then
      goto 19,2 in "003_third_room"
    end
  end
end
1 Like

does this allow different functionality than just placing an "item" tile, and making it's on collect do event empty? (ie, it won't be collected, but you can then script in additional behaviors)

Different functionality? If I understand correctly, likely not. It does not rely on item tiles, and all event handling code is collected in one place, if that is useful. The event will be triggered every time the location is entered.