Collectible Display

Hello. What I'm about to say may sound a bit complex, but please hear me out.

So, I am trying to make my main collectible be shown on the top left or right side of my screen.
(The icon of the collectible and beside it the amount I've collected)

However, I do not want it constantly on the screen, I only want to see it when I use the crank. Like a little drop-down thing that isn't too distracting.

That's about it. I would really appreciate it if someone could help me out with this. Thanks

The player's draw event is intended for HUD elements like this, especially the label function. If you want the label to show the value of some variable, like your count of collectibles, you can use some string formatting like this:

label "{variable_name}" at x,y

The slightly more complex part is making it only display some of the time. One way this could be done is to only call label if some other variable is set to a value of 1.

if show_hud==1 then
  label "{variable_name}" at x,y
end

We're going to make that show_hud variable only equal 1 on frames where the crank is being turned. To do that, first we should set it to 0 at the beginning of every frame. The game's loop event is always called first, so in that event handler just add show_hud = 0.

The player's crank event will be called on frames where the crank is being rotated, so to that event handler we just add show_hud = 1. And that's it! Your collectible count will only appear when the crank is being rotated.

You might find this is a little too strict. As an improvement you might change things so show_hud is assigned a value of, say, 10 in the crank event, and rather than setting it to 0 at the start of every frame you instead decrement the value like show_hud-- if it is greater than 0. Then in the player's draw event check for show_hud>0 to display the collectible count. Doing this will mean the count stays on screen for 10 frames (half a second) after the crank is rotated, which might look a little nicer and stop it "flickering" if the crank is not being constantly rotated.

1 Like

Annotation 2022-05-14 170300

Thank you for responding. I tried your method but it didn't work for me. When I used the crank nothing had happened. I know I did something wrong here, I just don't know what.

I'm still learning script, so I apologize for my inconvenience.

No worries, you're almost there!

The loop event handler needs to be in the game script. Think of it as some repeating logic for the game as a whole.

The crank and draw event handlers need to be in the player script. Think of crank as being a kind of input to the player. As for draw, even though we're using the event to make a HUD element you just have to remember that draw is an event in the player script.

You also have load instead of draw, perhaps you just forgot to change it :slight_smile:

1 Like

Ah, it started to work!

I've actually run into another problem though. When I collect the collectible the value doesn't change. It stays at 0 whenever I collect it. other than that, everything else seems to be working fine.

Double check the name of the variable you are using. By default when you collect an item in Pulp it will increase a variable that has the same name as the item tile but with an "s" on the end. So if I have an item called coin, collecting it will increase a variable called coins.

Of course if you change the collect event on an item tile then it will behave however you script it instead.

1 Like

It's all working! Thank you so much for your help, I really appreciate it!

1 Like