Inquiry and clarification for instance variables.

0 favourites
  • 2 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • construct.net/en/forum/construct-2/how-do-i-18/enemies-paths-56275

    Currently using this method to create a patrol path for my enemy characters. The trouble I have is that the post doesn't clearly indicate how to add certain steps which is crucial to getting the system to work. The following steps include...

    1. How to automate instance variables for each instance that doesn't modify every instance. I notice that each individual instance can have different instance variables, but I still don't really understand how it assigns it to each instance of the enemy in the example. (

    2. How does the instance variable reset back to 0 whenever enemy reaches the final waypoint back to the first waypoint. The capx doesn't seem to clarify it and nor does the forum post.

    Any help and clarification are appreciated.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 1 - Each instance of the object manages it's own instance variables. In other words, when you trigger an action: Enemy -> set current patrol point, it will only change it's own current patrol point. If you are looking for how to set each enemies starting value for their instance variable, you can select the enemy and look at the left side menu. There is a list of the instance variables there and setting them only affects the selected instance.

    2 - All you have to do is, set the point you are giong to next back to the first one if it would be set to a point that doesn't exist. If you only have 3 patrol points and adding 1 to the current point variable would increase the number to 4, set it to 0 instead. There are lots of ways to do this. You could increment the number, then immediate check if it is invalid and change it. You could use an if statement (if value < 3 set value to value + 1 else set value to 0). This could also be done in a ternary (value < 3 ? value + 1 : 0). Personally, I prefer to use the MOD (%) operator. Using MOD divides the value you are passing into it from the total number of points you are using and returns the remainder ( 3 % 10 = 3 and 13 % 10 = 3 because both return a remainder of 3. This is also the case for 100000000003 % 10 = 3)

    Finally, you can see this information in use in the linked example.

    drive.google.com/file/d/1DezxktPQOyTO7XzIwLjc0c_g2PA1GvXS/view

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)