Help with simple start screen (or level select screen)

I'm trying to create a simple start screen by swapping the player with a cursor tile, and setting Confirm to act differently based on the player's/cursor's y coordinates. I'd also like to swap back to the player's default tile upon exiting the screen.

For example I'm trying something like this:

on draw do
	if event.room=="startscreen" then
		swap "cursor"
	end
end
on confirm do
	if event.py==0 in "startscreen" then // go to starting area
		goto x,y in "house"
	elseif event.py==1 in "startscreen" then // restore last save point
		restore
	else
		act
	end
end
on exit do
	if event.room=="startscreen" then
		swap "down"
	end
end

startscreen2

I tested this but I think I've made an error somewhere. Also the on exit part doesn't seem to work as intended either. Any ideas?

if event.py==0 in "startscreen" then

This isn't valid pulpscript unfortunately! You will need to separate out what you want to check into two lines:

if event.room=="startscreen" then
  if event.py==0 then
    // do something
  end
end

As an aside, your on draw code is telling the player tile to swap every frame which isn't necessary, you only need to swap it once. I'd suggest using the room script's enter and exit events (which might fix your problem with your exit code too):

on enter do
  tell event.player to
    swap "cursor"
  end
end

on exit do
  tell event.player to
    swap "down"
  end
end

I see! I was unsure if I could use multiple if statements like that, since I didn't see any examples in the pulpscript docs. The startscreen menu is working now, and I added a third option (Start, Continue and Credits).

Here's an example of the current confirm script I'm using:

on confirm do
  if event.room=="startscreen" then
    if event.py==0 then // cursor next to Start option
      // do something
    elseif event.py==1 then // cursor next to Continue option
      // do something 
    elseif event.py==2 then // cursor next to Credits option
      // do something
    end
  else
    act
  end
end

Note: this could be used to create a simple level select screen as well.

When I tried using the room script's enter and exit events to swap the player tile, I found that the player only appeared as a "cursor" before any dpad movement occurred. This small bug was caused by the player's update event which swaps the player tile upon any directional movement, so I fixed this by adding another if statement to the player's update event.

on update do
  if event.room== "startscreen" then
    // do nothing
  elseif event.dy==1 then
    swap "down"
  elseif event.dy==-1 then
    swap "up"
  elseif event.dx==-1 then
    swap "left"
  elseif event.dx==1 then
    swap "right"
  end
end

However, once one of the startscreen options are selected the "cursor" swaps back to the "down" player tile before exiting the room. I guess I'll need to find a way to briefly hide the player between confirming one of the startscreen options and transitioning to the next room. I'm thinking of making the "cursor" flash by playing a quick animation once one of the startscreen options is selected, and then hiding the player somehow until the game starts.

Anyway, thanks for your help once again orkn, you're a legend :slight_smile:

1 Like

No problem, glad to have helped!

The swap on exit being visible for a single frame before the room changes is something I've also hit before. It's because room transitions are split over two frames, the first where all the exit events are called for the old room and the second where all the enter events are called for the new room.

There's a pretty useful "trick" for delaying things in Pulp by a single frame, and that's to use wait with a value of 0. Try this and it might sort it out!

on exit do
  wait 0 then
    tell event.player to
      swap "down"
    end
  end
end

Using wait 0 has fixed things for me on multiple occassions!

2 Likes