[Solved] Hotbar/inventory system

I thought the overlapping was being cause because there were 2 stacked sprites. So, you could have a card for each slot since they had their own Boolean variable.

You can’t see the slot objects but they are also doubled on top of each other. When the layout is added I set it to 10,10 instead of 0,0

No, the bug has nothing to do with duplicating cards. It’s just that some cards manage to stay on top of the others even though they’re in slots

I haven’t seen it happen. Do you know under what circumstances that it’s happening? I can try later today when I’m on my PC. Have you made changes lately? If you post a screenshot of the current slot events or upload your current project and share a link to it, I’ll have a look later.

I haven’t made any changes to the inventory code, but I even showed the bug happening in the previous screenshots

I’ll play around and see if I can get it to happen. When it happens check the debugger. Make sure there’s no extra objects and check the variables. If you can record video then record it so you can play it back and try and see what actions are causing it.

Good news. I was able to recreate it. It’s being caused by the last few solid-colored cards. The automatic mask for 1 pixel is huge. Although, it looks normal if you use the debug action to show the masks.

I never added the blank cards, So, that’s why I wasn’t seeing it.

The cards are colliding with 2 slots at the same time. The one it is in and the one to the right of it. So, the line here was setting 2 slots as empty even if the one slot had a card.

The solution seems to be to set the masks manually. Click the use manual mask button. Just make sure you uncheck the share same collision mask for all animations before you adjust the masks or you’ll change the others.
image

Edit: The automatic mask seems to use the first animation for all of the masks. If the first 1 is 20x20 then that’s the size of all the masks. If the 1st is only 1 pixel, then they’re all 1 pixel.

Alternatively, you could make all of the images all the same dimension. That way the mask would be the same size. I still don’t really understand it. I’m guessing either it’s not scaling correctly or maybe it’s not centering.

I did some testing. The debug action to show the collision mask does draw a huge box for the last 3 cards but the collision itself is only slightly larger than the image.

The red box doesn’t even fit on screen.

I added another sprite, made it draggable and had it change color on collision. You can see the collision mask is slightly larger on the bottom and the side.

ScreenRecorderProject68

Oh, I didn’t know I hadn’t made the right collisions of the solid color cards! I really didn’t realize that, but from what I’ve seen, it also happens with the cards with the correct collision that aren’t solid-colored.

Here, I couldn’t record the debugging together I think, but here it is.

To make it happen, I had to try many times to put a card in and take it out, and then try to put a card in again

From what I see the larger mask is triggering 2 slots when a blank card is picked up. This sets both slots to empty even if there’s a card in the slot. Once a cards is either added or both are removed, it will behave normally.

Adding a 2nd card fixes it temporarily. When the 2nd card is removed it resets the slot even if a card is still there. Only after all of the cards are removed will things be back in sync.

This particular bug shouldn’t happen once the masks are all the same size.

Did you set the masks manually or change the images so they’re all the same size? It seems to be tied to image size and resizing.

Currently, all collisions are correct. The cards that are solid color, they have the collision that should

And are you still seeing multiple cards being placed in the same spot.

Yep, look: https://www.youtube.com/watch?v=aZNNCO4JdIM

Can you post a screenshot of the collisions using the debug action?

Your hitboxes should look similar. I added a few textbox objects to aid debugging. Before, the box around the last 3 cards was huge. It extended off the scene.

I’ve just tried to replicate the bug, and apparently it was a fault with one line of code, but it wasn’t in the inventory part.
I just have one more headache, could you help me?
I’m trying to make an enemy detection based on: If X is bigger than the plant, and if it is within +80 and -80 of Y of the plant, it can attack.
My problem is that the plants still attack even if it’s not on the same line as them

IDK anything about the gameplay mechanism. I only clicked on the game part a couple of times. I have no idea what’s supposed to happen. All I see is shaky bushes.

Can you post a screenshot of the lines in question?


The problem in question is in the line “Plants.Y()+80” and -80 as well

ok. i see you need to press the center button to add zombies. I don’t see anything obvious and I don’t have the time now. Maybe someone else can help. If not, I should have some later tonight.

Where is force applied to the bullet? I only see create actions.

That’s where there are some of the first actions in the code, about text being on the screen and all that

I’m not at my pc. People are more likely to help when events are posted. IDK if it the problem is in the most recent screenshot or the one that applies the force. I wish you well. I’ll try to check in later.

1 Like