Creating situational events.

  • 5 favourites

Stats

600 visits, 820 views

Translations

This tutorial hasn't been translated.

Tools

One of my first obstacles I encountered with Construct 2 is creating a means of telling one object to send a message to another specific object. When I created events in the event editor, It would apply to every object in the screen. I've figured out a quick and easy way to circumvent this problem. There are no doubt, more elegant solutions, but this one should be easy for the beginner to implement.

Create a new empty project in Construct 2

Create 3 sprites with whatever you wish to draw:

* Player sprite: give it the 8 direction behavior

* Inbox sprite

* Outbox sprite

Create event:

* Player: on collision with Inbox spite

* Player: set position to (Outbox.x, Outbox.y)

Run the program. If you done the above, you should be able to move the player character with the arrow keys. If you collide with the in box, your character should teleport to the out box. So far that's expected.

Let's complicate things a little bit.

Drag another inbox and outbox sprite from the projects bar to the layout.

Run the program and note the behavior. The original in box will teleport to the original out box, but the new in box will teleport to the original out box instead of the new one. We would like to make it so that the new in box will teleport to the new out box, but we don't want to create two separate sprites to do so, nor keep track of IIDs and UIDs. Fortunately, we don't have to.

Select the original in box

* Add an instance variable "ToTarget", set it as a number and leave it 0

Select the original out box

* Add an instance variable "FromSource", set it as a number and leave it 0

Select the new in box

* Notice that the instance variable is already there. Set it to 1 in the properties bar.

Select the new out box and set the instance variable to 1.

Basically, we're pairing up the objects by giving them unique matching numbers. If you have more pairs of objects, you can label them 2, 3, etc.

Now go to the original event in the event sheet. Add a new condition by right clicking on the condition side and selecting Add>Add another condition(c)

select Outbox, compare instance variable

* the instance variable "FromSource" should already be the first argument and the second argument should be equals. Replace the third argument to "Inbox.ToTarget"

Please note the order in which the objects were selected. If you selected Inbox first and told it to compare to outbox, it wouldn't work because the inbox was already selected from the first condition, the one that the player collided with. Selecting the outbox first allows it to choose from all the available outboxes. See Ashley's event tutorial for further explanation.

Running it again should produce the effects we're looking for. It's my hope that you can use this method to solve your own cause and effect situations.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!