Reset the positions of items in a room?

Is there an easy way to "reset" a room? I have items that I push around, but I want them to reset back to their start positions when coming back to that room.

When I place a tile in the room editor, where do those x,y coordinates get stored? I'd love to record that start position of that item as a variable, then just call upon it every time I go back to that room instead of hard coding all the coordinates of every item.

I did this for the game I was fiddling around with. I don't know the secrets and shortcuts so I had to hard code each piece back to it's original location. It's not ideal but the only way I could figure out. I'm sure someone here has an easier solution, though. I'd love to go back and tweak it so it's more streamlined.

Had this problem too. I didn’t find a solution then, but thinking about it again, it might actually not be impossible. I guess you could do something like this in each item, that should be reset (itemName should be different for every item/sprite)

on enter do
   itemName_X = event.x // Store starting position
   itemName_Y = event.y
end

on exit do
   swapX = event.x // Get current position
   swapY = event.y
   tell swapX, swapY to // We have to delete the item at current location
      swap „white“ // or another world tile of your choice
   end
   tell itemName_X, itemName_Y to // Swap in item at starting position 
      swap „itemName“
   end
end

(I don’t know if that’ll actually work, as I don’t have time to test it right now, but I don’t see why not)

Also, feature request, if Shaun reads this: I feel something like config.resetRoom to reset a room once the player leaves it would be a nice addition to PulpScript!

Thanks so much! I'll try this out.

Does anyone know where the information is stored as far as when you place tiles in the room edit mode?

It totally worked! Thanks so much!

I have an open feature request for this ability.

2 Likes

I was wondering if you could clear up a few things about this for me (still trying to figure it out):

Is this script added to each item, meaning am I adding it into the sprite script or the room script?

When you say "itemName should be different for each item/sprite" do you mean within the script I have to swap out every instance of "itemName" (ex: itemName_X = event.x, etc.) for the script to run properly or just the "itemName" next to the swap function?

Any help would be appreciated and thank you in advance.

You add it into the sprite script. It has to be there in order for event.x and event.y to target the right tile.

Concerning itemName: The main point here is, that all variables are global, meaning they can be accessed from anywhere in your code and can be overwritten in other events. For this reason itemName_X and itemName_Y have to have a unique name for each sprite/item. The itemName in the swap is just the name of the tile you’re running the script in. You don’t have to follow my naming convention, I just find it very clear that way :slight_smile:

(I’m just realizing, itemName_swapX and itemName_swapY can just be named swapX and swapY, as we don’t care about them anymore once the exit event for a particular sprite/item ran trough. They can be overwritten by the exit event of other sprites/items afterwards, thus don’t have to be unique in every sprite. I updated my previous answer accordingly.)

Thanks for the help, I really appreciate it!

I too was wondering if I could make a room reset, and I think I've just about solved it! The good news is it's a generic, scalable-to-many-rooms solution that technically works, the bad news is each room takes roughly 37.5 seconds (I think) to load because it resets the room at a rate of 1 tile every 2 frames :smile:

+ Resetting rooms are completely reset on reentry regardless of what item, sprite or world tile changes have been made
+ Exits into a resetting room work as-is
- Exits out of a resetting room don't work (due to the room layout being duplicated on load into an empty room) so any exits in a resetting room need to be done in code with gotos
- Each resetting room takes an entirely impractical amount of time to load!

Here is all the code you need:

In the game script add this custom event:

on resetRoom do
	if resetting==0 then
		ignore
		destroom = event.room
		destx = event.px
		desty = event.py
		resetting = 1
		resetx = 0
		resety = 0
	end
	if resety==15 then
		resetx += 1
		resety = 0
	end
	if resetx<25 then
		resettile = name resetx,resety
		goto destx,desty in "main"
	else
		listen
		resetting = 0
		goto destx,desty in "main"
	end
end

Create an empty room called main - this is the room that the resetting rooms are actually copied into during loading - and add this event handler to its script:

on enter do
	if resetting==1 then
		tell resetx,resety to
			swap resettile
		end
		resety += 1
		goto destx,desty in destroom
	end
end

Finally, for every room you want to be resettable, add this event handler to the room script:

on enter do
	tell event.game to
		call "resetRoom"
	end
end

Now this looks like an absolute mess when loading, so I covered it all up with a simple loading screen, complete with percentage loaded (which you really need given how long it takes!). Just add this event handler to the player script:

on draw do
	if resetting==1 then
		hide
		window at 0,0,25,15
		resetpercent = resetx
		resetpercent *= 15
		resetpercent += resety
		resetpercent /= 375
		resetpercent *= 100
		resetpercent = round resetpercent
		label "LOADING {resetpercent}%" at 7,7
	end
end

Quite neat? I think so. Entirely impractical? Absolutely! That's because it is limited to loading one tile every 2 frames by the constant gotos back-and-forth between the room to be loaded and the main room it is loaded in to.

I think an actually useful version could be made in principle if an independent variable was used to store the tilename for every room tile, but that's 375 tiles that have to be hardcoded rather than using a loop like I do here, so it certainly wouldn't be as neat...

Here's a zip of the json of a demo you can load into pulp:

Resettable Rooms Demo.zip (2.5 KB)

For my use-case, I allow players to have a save point in the game. Unfortunately, any health power-ups (items) they pick up after the save are gone on the next attempt/play-through. My solution is somewhat tedious, but I reset them each time they enter the room:

on enter do
	tell 6,13 to
		swap "health_pack"
	end
end

(If the reset thing can't be added, it would be great if loops were a bit more elaborate, so I could loop through a list of coordinates to "reset" in this style.)

Found this thread when searching for a similar feature. I came up with a solution that works for resetting whole rooms, but I don't need any item-specific state saved within the room, so not sure if it applies to your case.

It basically "ends" the game early, and the game's finish handler calls the game's load handler, which restores to the last room the player left (stored on exit). It doesn't work correctly if I tell event.game to call "finish" , but it does if I use fin :face_with_monocle:.

Example game json attached. Careful of what you're storing though, note in the example that I'm storing disks and then on reset the disk items come back (so disks can go up forever).

Brando's room reset example.json.zip (3.2 KB)

EDIT: You can see another example implementation in rasapberrybrain's game Snakes, download the code here: Snakes (Playdate Pulp) by raspberrybrain