I'm making a simple game based on the basic collecting keys to unlock the door sample game. In my game the player has to press locks (by collecting them) to open a door in each stage. In one stage I want some tiles representing vines (called "vinesfake") to change into normal locks when the first lock (called "lockspecial") is collected. The script I've used for this is below, and is contained within the "lockspecial" item:
on collect do
say "You've released a pressure lock!\n\n\n\nYou heard something shift somewhere"
locks++
tell vinesfake to
swap "lock"
swap "lockoff"
end
end
("lockoff" is just a world tile that shows the lock having been pushed)
Pulp is happy enough to run with this bit of script, but now whenever the player tries to interact with "lockspecial" (just done by walking into it), the game freezes. Am I going about this the wrong way? I originally tried using Emit to create a function called "extralocks" that would cause "vinesfake" to swap to the lock tile but I didn't seem to be doing it correctly as Pulp couldn't reconcile the script. I've also tried swapping the order of events to
If you want to tell a specific tile in the room to swap you need to target it using coordinates like this:
tell x,y to
swap "lock"
end
If you want every matching tile in the room to be told to swap, an easy way is using emit. On the tile add an event like this:
on removeVines do
swap "lock"
end
Then in your lockspecial tile script:
on collect do
emit "removeVines"
end
Beware that multiple emits in the same frame can have a performance impact, but just one like this on collect should be fine.
As for why your approach isn't working it's because tell tileName to targets the tile prototype instead of any specific tile instance. That might sound a bit confusing if you're not a programmer but think of the tiles in the editor as "prototypes" that get instantiated in the room when you place them. You can have many instances of a tile in a room (a lock at 12,7 is a different tile to a lock at 18,4 but they are both the same type of tile).
Certain functions, like swap, only work on instances of tiles and not the prototype. Basically anything that only makes sense to happen to a tile that is in a room!
As a rule of thumb most of the time you'll probably want to use tell with coordinates, not a tile name.