Wait for Key Press bool then save level?

So I’m trying to create a level saving and loading system.

At the moment I have a saving system working as well as a loading system. My issue is extending the saving system to include a save data overwriting option.

I have a function to save the game which checks if the user has saved before. If they have, then it runs the overwrite function. as seen below.

Inside this function, it checks whether the overwrite bool is set to true.

69556-overwritecheck.png

The overwrite bool is set via button press.

69557-set+bool.png

If the overwrite variable true it should save the game, and if it is false it should create a new slot. However, when I get to the branch to check if the overwrite bool is true, it is always FALSE.

Is there any way to wait for a key press for multiple buttons?

I did try the node ‘Is Input Key Down’ but the overwrite bool check never gets fired.

I think you have the programmer’s blues running and are too fixed on the problem! :slight_smile:

Don’t wait for the key, let the key be the trigger for an action!
So instead of starting the save process upon the player’s “save now”, you should do this:

  1. when the player triggers “saving game”, you only do a check if the file already exists
  2. if it exists, you come up with the “are you sure you want to overwrite?”
  3. he then has to press one of two keys, so you set the variable then and then trigger the saving process (eg in a function)
  4. if he chooses a new savegame, you trigger the saving function immediately (step 2 and 3 not neccesary)

This way you have an asynchronous process without the need to do some akward check-if-the-player-did-something cycle in the background.

@ Would you be able to give me a quick example as I’m really hitting a blank here.

I’ve tried taking the save stuff out of the save function and put it into the Event Graph (to be able to add input). I’ve also tried using a gate (see below) to make the overwrite bool change but it never exits the gate? I’m assuming because it always ends up closed.

The way you are trying to do this, the save action is triggered immediately. At this point, the user wont be holding down any key yet, because he simply does not know yet that he has to do so, right? You first have to tell him to press the key, before you check if he pressed it.

The root of your problem is, that you try to check user input and you tried to handle it like a momentary state. The problem with this is, that it is not defined WHEN the user presses the keys, so your logic may have run but you were not pressing the key at that very moment. So you need to wait on the user to press a key.

you have two [or more, hehe] ways to achieve this:

constantly check if one of the two keys is pressed inside Tick

While it works, you should try to avoid doing stuff in Tick, especially stuff that’s not used often, since it’s executed on every frame.

make your process asynchronous

@ Thanks dude. I’ve managed to get it working. I guess I was just in a bit of a rut. You’ve been a big help, cheers.