How do I - Get all of a certain tile without a ForEach loop in a different room?

Is there an easy way to “get” names or tileids of all tiles of a certain name that are not in the room the player is in?

Say i’ve got 30 tiles all the same, but I want to swap the lot based on an action (say, interacting with a switch), is there a way to do this with a while loop or similar - while I am specifically in a different room to the tiles that want switching.

Trying to get around the “calling swap on a tile that isn’t in the current room displays it in the current room” thing.

Also - is there a way to update the frame of a tile not in your current room? Calling frame 1 doesn’t seem to do it if that tile is not onscreen.

The result you want is when the player enters that other room the tiles are swapped right?

What I would do is while in room B mark a variable, say “StateOfX”. Then for those 30 tiles in room A in their script add an “on enter” handler and check the state and swap accordingly.

If you need logic to run based on this swap, I would hoist the logic out of the tiles and into the game script. Have the logic run based on your state variable, and have the tiles only reflect the visuals.

Keeping game state in variables will also help if you ever want to implement saves.

Yup, this is probably the best way to do it. (You can only manipulate tiles in the current room.)

1 Like

Hey @0x143 and @shaun ,

That’s exactly what I was thinking for it, thanks for that. Normally i’d just do a “foreeach ID” then run a function within them to do the swap but obvs that’s not available here.

Do you know if there’s a way to check what room the player is in from another object?
I know I can use if statements per object like if event.room=="start" then but wondering if I can access player location from an object not in the room, so instead of event.room is there a “player.getroom” or similar without manually logging it to a string myself?

Are you even sure scripts run on objects in “other rooms”? My assumption would be all tiles are purged when moving rooms. Thus the only room ever running is the current one. The PulpScript documentation does not talk about this to my remembrance.

Thus event.room would always be the room players are in.

Wait’s and the like still run when not in the room,

So if i’ve got the following it will still complete. Was hoping I could add a simple if/else to it:

	wait 5 then
		swap "PlantedCollectable"
end

Was hoping to add something like

if player.room!="start" then
call "OtherFunctionToTryAgainlater"
end

event.room is always the name of the current room. An event handler is never called on an object that isn’t active in the current room. (You can tell the prototype of a tile by name that isn’t in the current room but it won’t have any effect on the individual instances in the current or any other room.)

1 Like
	Hi Shaun,

Well that’s what I thought but the below code runs the swap and not the else when I move to a different room while it’s during that “wait” period.

wait 5 then
					// check if we're in the room or not
					if event.room=="start" then
						swap "PlantedCollectable"
					else
						readytoharvest = 1
						//debug
						say "you were not in the room"
					end

Ah, wait was added as more of a UI thing. Say if you wanted to script a cutscene. You could ignore user input, script a sequence of events, and then at the end of the sequence, start to listen for input again. As you’ve found, using wait in gameplay can have unexpected side effects if you’re not manually tracking relevant changes to state since the wait began.

1 Like

That makes sense! In this instance i’m using it instead of writing a timer to update swaps and frames on a set of “items” in the world.

Probably just have to do it properly and stop trying to shorthand it lol.

Cheers gents!