Hi,
I’m trying to code a battle menu similar to that of Undertale, but I’m having trouble with the menu’s Back button. The issue is that when the back button is pressed in previews, it doesn’t do anything half the time (?), softlocking the player in the items menu. Below is my code and screenshots of the game menu.
Hi!
Try “is released” and not “clicked”
Funny your alias “AppleIIeIIe”. I had an Apple IIe there is a long time.
Say us if the situation is Ok after correction.
A+
Xierra54
@appllelle, where are you deleting obj_button_back? You are creating it in multiple places, but I can’t see any event in your screen shot that deletes it.
That won’t make a difference. Clicked is set to true after the mouse button is released and the cursor is on the button.
Hi, I added ‘delete obj_button_back’ to all the false states and altered my code a bit, but now the back button straight up doesn’t show up when I click on “Attack” or “Items”. However, it works in “Actions” with the exact same code. Below are screenshots of code and the preview.
You have some serious refactoring to do with your events.
Your issue is that the last group of events, the ones that check the value of the variable “actions” over-ride all the other events that create and delete various buttons. When the variable attack is “display_moves”, the variable action will be false. So the back button is created by the “variable attack = 'display_moves'
” event but is deleted straight after by the “variable action is false
” event.
You really should use an FSM (finite state machine). It’s no way near as daunting as it sounds. It’s just a way of keeping track of what part of the game you are in. So for your game, you could have states like “action”, “attack”, “items”, “bandaid” etc. You then group events by the state they belong to. Something like:
In the example above, when the game first changes to a state (by using a trigger once condition) the relevant buttons are created. No other buttons are created or deleted at that stage.
Then, while the game is still in the state, the button clicks are checked only for the buttons that were created. If one is clicked, the state is changed and the buttons initially created are then deleted.
This ensures each game state only creates and deletes the buttons it needs, and only actions button clicks that can happen in that state.
Hi! Thank you so much. It totally worked so well! I have another question: I’m trying to display the bandaid count in the game menu, but for some reason it displays as a random number when the real variable value is 1, nor does it change when a bandaid is used. Any ideas on how to fix this? Thank you so so so much for your help so far, you’re a lifesaver. So sorry for the amount of questions.
What are the events that change the value of inventory.bandaid?
Also, when you use the bandaid, you aren’t updating the text on the bandaid button.
The game state is not just to create or delete the buttons. It’s also to control the game flow. The bandaid hide and show events shouldn’t be where you have them; they’ll get actioned for any game state. Instead, they should be as subevents of the items events:
Hi, I’ve edited the code, but now the bandaid button doesn’t work at all, and the back button is also back to just working half the time… I feel like my program is cursed…
So you click items, the bandaid button shows but clicking on the bandaid button doesn’t show the hidden use/don’t use buttons?
For what game states does it not work? Remember you need to refactor all your events to fit the FSM model. It can’t be done for a few events and the rest ignored. It’s an all or none situation, otherwise things may not work as expected.
OK, it works now? I’m really not sure what happened. However, the bandaid button still doesn’t show the correct number of bandaids, nor does it change to “no items” when you run out of bandaids. Thank you for your help once again.
That suggests that the inventory.bandaid value does not reach 0. Where does it’s value get set?
I’d suggest you search the event sheet for “inventory.bandaid” and check each result, making sure it’s part of the correct game state.
And if that doesn’t show up anything, preview the game using the debugger and check the value of inventory.bandaid before you click on the items button.
Here’s the culprit:
A key can be pressed for multiple game frames. So it’s almost certain that the X key is pressed and these conditions are true for multiple frames. Remember, hidden objects can still collide with other objects. I’d suggest you include the condition to that event that checks obj_bandaid is visible.
BTW, you don’t need the “Trigger once
” conditions in clicked events or where the scenes change. You only need them where the condition stays true over multiple game frames and you only want the events to action once. In the case of clicked conditions or scene changes, they are only true once as it is:
Hi! It now displays the correct number, and the no items works as well. Thank you so much!