Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Action Dependent Events

Action Dependent Events
written by Sparkiness

Download Demo



Ever wanted to make your games more interactive?

In this tutorial, you will learn how to create a chest that relies on input actions in order to be opened. The tutorial will be taught as so: a screenshot will be shown, and underneath, an explanation will follow analyzing the events and what each performs.
First off, download the demonstration linked above, and give it a couple shots. Try pressing at faster/slower speeds on each attempt; do you notice a difference in the outcome?
Open the RPGXP Project. We'll take a look at the first page of the chest event.

http://img328.imageshack.us/img328/9291/01zv1.jpg[/IMG]

It starts off with two Show Text commands which merely states the instructions. Since these do not necessarily effect the performance of the event as a whole, we'll take a look at the next one, Button Input Processing. This command stores a variable with a set number when a key is pressed. We want the A key, and only the A key to effect whether or not the chest will open. So, we use that command, Button Input Processing, to prepare for a button input (which we will set to the A key) later on.

The next command on the list is called Control Timer. This begins a timer of a duration defined by the user; in this case, I set it to five (5) seconds.

After that, I created a Control Switches command and made a switch called RepeatProcess which I then set to ON. This switch activates the second page of my chest event.

http://img340.imageshack.us/img340/2850/02ya7.jpg[/IMG]

Notice I set the Trigger to Autorun: this was to prevent the player from moving out of place while the actions were being executed. Since the trigger was set to Autorun, the event will repeadly execute the command (there's only one on this page) in a continuous cycle. The desired effect here was to continuously prepare for a button input; thus the reason for a combination of an Autron trigger and a Button Input Processing event.

I also had, right next to the chest event, an invisible event. We'll take a look at that right now.

http://img281.imageshack.us/img281/1977/03hj7.jpg[/IMG]

Take note that the trigger of this event was set to Parallel Process, meaning that it will begin once it's residing level finishes loading! It also, like the Autorun, repeadly executes the commands.

Let's take a look at the first Conditional Branch. This Conditional Branch is checking whether variable ButtonPress (this is the variable from the two previous Button Input Processing events) is equal to 14.

Here's a chart:

2 - DOWN, NUMPAD 2
4 - LEFT, NUMPAD 4
6 - RIGHT, NUMPAD 6
8 - UP, NUMPAD 8
11 - Z or shift
12 - X or ESC or NUMPAD 0
13 - C or ENTER or SPACEBAR
14 - A
15 - S
16 - D
17 - Q
18 - W

This is what the previous Button Input Processing events have been waiting for. Once a button has been pressed, it takes a look at the chart and stores a variable set to the number it is designated with. Thus, A is designated to 14.

In order words, the Conditional Branch is checking if A is being pressed. If it is being pressed, it will execute the commands within the branch. In this case, when A is being pressed, I made a sound effect play, made and increased a variable PressedAmount by 1 (this records how many times A has been pressed) and set variable ButtonPress to 0 to allow for further button input preparations.

Underneath this Conditional Branch, is yet another one. This time, however, checks if the timer we set earlier had already reached 00:00. If the timer has reached 00:00, we stop the timer and make a switch called ConfirmComplete which we then set to ON.

This switch deactivates the invisible event and activates the third page of our chest event.

http://img121.imageshack.us/img121/7905/04kj8.jpg[/IMG]

This contains yet another Conditional Branch. Did you remember that when we pressed A, events were executed, one being the increase of a variable called PressedAmount? This conditional branch checks if PressedAmount has at least a value of 30. If it does, a switch is made and called SucessfulTry and set to ON. If it doesn't, all the events within the Else section are executed including, but not limited to, the reset of all variables and operations of all switches to allow the player another attempt to open the chest.

Also, the SucessfulTry switch we was recently switched to ON activates the fourth page of our chest event.

http://img296.imageshack.us/img296/6199/05gl0.jpg[/IMG]



Here, the animation of the chest sucessfully opening is shown, music is played and variables and switches are reset. More importantly, Self Switch A is turned ON which activates the fifth page showing a static sprite of an open chest.

Have fun with this and remember you could also incorporate this into different events!

Thank you for reading!

 
Wouldn't it be easier to do with self switches? Well... not easier but it would use less switches and the event could be copied.

Still great.
 
You could use labels.
At the end of the event ask if the player wants to try again, if yes go to label 'retry', and at the beginning make a label called 'retry'. It should work then.
 

RAWR

Member

you know what would be awsome! you could like have strength training and if you hit the button the amout of times you need it in that time would make your strength go up >> im so smart
 
Hehe. I was wondering, are you going to make more?

Because I'm pretty sure there are more events that depend on certain actions. Like jumping inside a window for example.
 
I think the hard thing about this whole thing is thinking up those kind of things, like who would think of pressing a button a lot of open a chest.
I didnt have to read the tut to understand it though, i jst looked at the coding.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top