Platform-Style Video Games with Construct

Collecting Items and Updating Variables with Events

Your browser needs to be JavaScript capable to view this video

Try reloading this page, or reviewing your browser settings

This video shows how to update variable values after the player character collects the corresponding items.

Keywords

  • Construct 2
  • User Interface
  • Variables
  • Text Objects
  • Events

About this video

Author(s)
Lee Stemkoski
First online
15 February 2019
DOI
https://doi.org/10.1007/978-1-4842-4446-3_14
Online ISBN
978-1-4842-4446-3
Publisher
Apress
Copyright information
© Lee Stemkoski 2019

Video Transcript

Lee Stemkoski: Next, it’s time to add some events. So let’s go over to our Event sheet. We’re going to change the values of these variables, Coins, Health and TimeLeft every time the Koala collides with one of those objects.

So let’s add a new event. These events will all be Koala-based conditions, so select the Koala and choose Next. In this list of conditions, let’s scroll down and underneath the Collisions category, let’s choose On collision with another object. And then click on Next. We have to see which object we’re testing for collision with. So let’s click that button. First, we’re going to check if the Koala has collided with a Coin. Click on OK and Done.

In this case, the coin should disappear, and we’ll add one to the Coins variable. So let’s click on the word Add action. So let’s say System, because all the variables are contained under system. The action is in there, the category Global and local variables. Let’s choose Add to. Add to coins, the value 1. That sounds good and click on Done. Next, we need to add some more actions. So let’s add another action. The coin should disappear after we collide with it, so we can’t keep recollecting it. So let’s make this a Coin action and choose Next. Underneath the category Miscellaneous, let’s choose the action Destroy.

We’ll use similar logic to interact with the Heart and the Clock objects. Let’s add a new event. Again, the condition is a Koala condition. We’re going to check if the Koala has collided with another object and click that button to choose. In this case, the Heart object, and click on Done. Then we’ll add an action. We’re going to change the value of a variable, so that’s a System action. Under the category Global and local variables, choose Add to. Change the variable to Health, and sure, let’s add 1 to Health whenever you collect a heart. Once more, we need to destroy that heart. Add action, Heart. In the category Miscellaneous, Destroy.

One final event. Let’s click on Add event. Again, a Koala condition. We’re going to check if the Koala has collided with another object. Click to choose the object. That object is a Clock. We’ll add an action, a System action, because we’re going to add to the TimeLeft. So Global local variables, Add to. Change the variable to TimeLeft, probably want to add more than just one second. Maybe add 15 seconds. We’ll click on Done. And as before, we should destroy the object we have collected. We’ll choose Add action, Clock, Next. Scroll down to the Destroy action.

Excellent. Those are the events we need to change the values of the corresponding variables. We should always test when we’re done. Let’s go back to the layout. Save our project and run. Web browser loads. All right. Let me collect that time right away, collect that health and collect five coins. Excellent. Game’s working as expected. One more thing I should change before I forget, I’d really like to start with 60 seconds, so I have time to explore my level. So going back to the Event sheet and scrolling back up, TimeLeft, I’ll right click to edit that. Change that back to 60. Excellent. We’ve added some interactive collectible objects.