Categorised Rooms OR other methods for Room Rules

Hi all,

I'm making a game that has the player moving around on foot in some parts and by ship in others.

The game is split up into rooms where the player sprite is a ship and rooms where it's a person. In the ship rooms, movement reduces a variable called "Food". On foot, this won't happen.

I'm using the following in the Player script to change the player sprite when it enters an island for the first time:

on enter do
if event.room=="island1" then
goto 8,11
swap "capnright"
end
end

And then multiple If functions stacked on tip of each other to deal with player movement:

on update do
if event.room=="ocean1" then
if event.dx==-1 then
swap "shipleft"
food--
elseif event.dx==1 then
swap "shipright"
food--
elseif event.dy==1 then
food--
elseif event.dy==-1 then
food--
end

if event.room=="island1" then
if event.dx==-1 then
swap "capnleft"
elseif event.dx==1 then
swap "capnright"

						end
					end
				end
			end

There are two problems with this:
First, it doesn't work. On "Island1" the sprite doesn't swap when you move left.
Second, it's unmanageable because even if it worked properly, I'd have to make a separate set of conditions for each room in the game which would spiral completely out of control.

Is there a streamlined way to use a different player sprite (or manage other functions) in different types of rooms, rather than just individual rooms? Alternatively, is there another way to have more than one set of rules to change the player sprite based on direction and telling Pulp which one to use at which time?

Interested to know if anyone else has come up against this. The easy solution is to have player sprites that don't change direction, but I'd rather be able to do it if I possibly can.

Thanks in advance for any help!

Hi,

There is a streamlined way to use different sprites with separate directions and with various rooms.

You can use variables inside strings meaning that you only need to use swap once per sprite.

on update do
 if event.room == "ocean1" then
  swap "ship {event.dx}"
  food--
 elseif event.room == "island1" then
  swap "capn {event.dx}"
 end

Note that the left and right tiles should be renamed to the horizontal direction of the player. For example ship -1 and ship 1.

As for the rooms, my best solution is to set a variable in each room or at the entrance of the room. For example, for every island:

on enter do
 OnFoot = 1
end

And change the player's update to

on update do
 if OnFoot == 0 then
  swap "ship {event.dx}"
  food--
 elseif OnFoot == 1 then
  swap "capn {event.dx}"
 end

Hopefully, this should help both of your problems.

1 Like

Thank you very much, interestingly I had just come up with the idea of using variables for the rooms on my walk home, and just saw this reply before I was about to test it out. Your response gives me confidence it was the right solution!

Thank you very much for your answer to the first question too, that's extremely helpful.

Sorry I actually have a follow up question - this works perfectly except that the player needs to be able to move along the Y axis as well as the X. With the script as it is trying to move up or down crashes the game; how would I allow the player to move on both axes?

I've created new sprites for vertical movement but I can't name them the same way as the horizontal sprites so I'm unsure how to best make use of them. Is there an addition I can make to this script so I can allow the player to move up and down when Onfoot=0 and when it =1?

Thank you again for your help.

EDIT: I've now fixed this, I hadn't noticed I was using multiple 'if' statements instead of 'elseif'. Works perfrectly!

1 Like

Just add event.dy inside the string and that should do it. The sprites need to be renamed again, this time the opposite axis needs to be zero.

on update do
 if OnFoot == 0 then
  swap "ship {event.dx} {event.dy}"
  food--
 elseif OnFoot == 1 then
  swap "capn {event.dx} {event.dy}"
 end
end