How do I change instance variables before on create

Get help using Construct 2

Post » Mon Oct 30, 2017 2:24 pm

Hello everyone!

I have another problem: I wanna...
  • ... create an object
  • ... set the object's instance variables before OnCreate is called
  • ... check within OnCreate the value of the instance variable
My problem with that is, that OnCreate is called immediately after I create the object. But I want to change the instance variables of the created object first before OnCreate is executed

Here's an example:
I have an enemy spawner. The spawner has 2 different modes
  1. Spawn the enemies behind a door and set the "invading" boolean to true. In OnCreate of the enemy check if "invading" is true and let the enemy run into the room
  2. Distribute the enemies in the room (they're standing still when created). "Invading" is left false

How can I access the instance variable before the "OnCreate"-event is called?
Posts: 13
Reputation: 528

Post » Mon Oct 30, 2017 2:36 pm

Short answer - you can't use On Create for this.
On Create is triggered before the instance is actually created, so many properties and instance variables are not accessible at this time..

You need to use some other event. Or maybe even add "Wait 0" - this will wait till the next tick, when instance creation is complete.

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
Posts: 2,028
Reputation: 77,137

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests