Changing a tabbing inventory immediately (SOLVED)

Greetings,

Since I’ve posted a lot lately, I’ll keep it brief, I’m working on making a powerful inventory as a POC, and I ran into a problem I couldn’t fix

So basically, I want to have multiple inventories, and I want them to be tabbable. You know, switching to a different inventory when you click on the tabs above

Right here, I have foods, key items, and trinkets:

So, what I tried is when I press p, it opens whatever inventory is currently active, and when you click on a tab, it changes the active tab:

Altho, something’s not quite right. The inventory does not change instantly. Only once I close the inventory and reopen it again after pressing a tab, THEN it changes. I want the inventory to change IMMEDIATELY

I tried mixing around the events, disabling stuff to test, debugging, all that nitty gritty, but most solutions either just froze the game up (Because of the time scale), or doesn’t show the inventory at all

Can any of you see what I’m doing wrong here? Thanks

Hi,
The thing is, the event that display items according to the Active Tab is inside the press p condition. So that’s why it doesn’t change directly but only when pressing p again.

One practice that I could advice (at least it’s good for me, making things clearer) is to well separate in the code what is :

  • the player interactions/commands (key pressed, tab clicked). This commands are recorded in variables, preferably boolean. The p key pressed would toggle a boolean variable “inventoryshown”, the click on tab, if inventory shown is true, would change the value of variable Activetab, like you did already.
  • the display. This part of the code just focus on displaying things, inventory and tabs, according to the variables.

Doing so, you could clearly separate parts of the code, and there would be no pb like having to press p again to change tab, cause your 2 parts are independant, the display is not triggered by the command. I think it’s a good way to avoid bugs.

Remark:
Still, the display part can have a general condition (if tab clicked or if p pressed) just in order to avoid the computer to continuously checking and displaying or not the inventory. This is just to avoid unnecessary condition checks and actions.

Alright, I see how that was an issue before

Moved the changing logic out of the P pressing logic, and this is what it looks like now:

Good news: The tabs now change INSTANTLY like I wanted

Bad news: Fixing this problem created 2 more problems. The inventory is now ALWAYS open, and won’t close no matter how many times I press P. Also, when the game pauses (Time scale event), it won’t unpause again for some reason (The player won’t move)

Can you please help me fix this new issue? I want to keep the instant tabs, but fix all the new problems that spawned from this

I don’t have an answer but I want you to know, I feel your pain. I’m working on a project myself and fixing one thing often breaks other things. Stay stong. Stay determined.

1 Like

Hi Shadowbonnie7, I haven’t had a good look at your events or tried to troubleshoot, but I always like to put the action that changes the condition to the opposite - at the end.

For example: GlobalPause variable = 0 is your condition. Then I would put Change GlobalPause variable to 1 as the last action in the event to make sure the other actions happen. Maybe I’m overly cautious, I don’t know haha.

No Bubble is right. I just wrote your exact p release condition and drug in a text object to display the value of the global variable pause and it never leaves 0 the way it’s written. But changing the order, it does go to 1 the first time, then stays there.

Ok I got the variable to finally change right by doing this:

Now not saying that fixes everything you were writing about cuz that’s the only thing I tried so far.

1 Like

No, you’re right, that DOES fix everything. Thanks for the quick fix, you saved my tail there

Now the tabs are working just like I want them to!

Thanks again

1 Like

Your pause issue looks like a classic case of: How to toggle states using Variables [GDevelop wiki]

2 Likes