Instance Variables

3

Index

Attached Files

The following files have been attached to this tutorial:

.capx

instance-variables-loops.capx

Download now 2.26 MB

Stats

5,041 visits, 8,396 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 18 Jan, 2017. Last updated 19 Feb, 2019

Instance Variables & Loops

Only thing I ask in return is some comments from you friends, nothing more

Using instance variable is easy but, many people find hard to use loop with instance variable. It is not hard look at it in logic way and using logic is easy once you know how and when to use loop. If you have 2 to 3 instance variable then you don’t need loop but, if you have more than it is best to use loop.

Let’s say you have 3 colour boxes on screen and when someone clicks on color box, person clicking box will get answer like you picked box number, color, or whatever you want to say.

Click on color square with Simple code

If mouse left button click on object boxes then set text to you clicked on box name red, green or blue. For construct 2 codes is below

To simplify let me show you in construct 2. Create new project and name it as you wish.

1. Set windows size to 640 x 480

2. Set layout size to 640 x 480

3. Ste background colour black and name it BG.

4. Add one layer and name it Sprites

Add Text TITLE and place it like I have.

Your layout should look like below:

Now to add code open Event Editor and add this code

So simple any one can do this but, what happen, if we have more objects on screen? Let’s assume you have say 8 animals Sprites, which you have imported in one ANIMATION, and which contain 8 frames. Player goal is to click on any frame of animals, which in return information should give accurate name of that animal to player.

Now you could create this project with all the animals with their own animation e.g.

1. Anim_Lion

2. Anim_fox

And so on but by doing this you are wasting valuable time and yield CPU usage processing power pointless and uncalled for, but if we can import all this Animals in default animation and use INSTANCE VARIABLES and LOOP it will be simple. In our project let’s add some sprites and name it Animals place it as shown on below:

  • 0 Comments

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