Quick question about instances and instance variables

0 favourites
  • 10 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have the "btn1" sprite object type linked to the "btn1" png image. I want 2 "btn1" instances on my main menu layout. 1 for play (click and it goes to the next layout) and 1 for quit (quit and it closes the browser). I already know what my events will be but what I am trying to figure out is how instance variables come into play. I have 2 instance number variables of the "btn1" sprite object. 1 is named play, the other is quit.

    tl;dr Am I supposed to link which instance goes with which instance variable? If so, how would i go about doing that.

    I just picked up Construct 2 yesterday and I don't know if Construct Classic had this functionality because I have never tried it.

    Thanks for any and all replies.


  • All you need to do is add for example text variable (called "state" on image below) to btn1 object. Then when you place two instances of this object on layout you need to set this variable accordingly for each instance.

    Events are similar, just compare value you put in "state" variable and do your actions.

  • Thanks for the quick reply!

    Oh I think I get it now. So the instance mapping is done through the event sheet? When, in my game's system setup, do I (should I) set the instance variables?

    Also, in the actual editor: if i have btn1 sprite set to layer: "buttons", size: "100, 100" and position: "0, 0" and btn1 text set to the exact same size and position on the same layer, how do I select the sprite if it is behind the text without having to like move it out of the way temporarily if I want to edit the properties of that "btn1" sprite's instance

    Thanks again!

  • I (for the most part) figured out a decent workaround for the second question through the z order panel. As for the first question:

    I have a "button" family setup with my "btn1" object in it. I also have a family instance variable named "button". I clicked both instances of my object and set the first one's variable value to "play" and the second to "quit". I went into the event editor and tried setting up the following:


    Mouse-On left button click on [family] "button"

    Condition 1

    [family] "button" value = play

    Condition 1 Action

    Go to "game" layout

    Condition 2

    [family] "button" value = quit

    Condition 2 Action

    Close Browser

    As soon as I click DONE in the "Parameters for buttons: Compare instance value" dialog box I get an error that reads:

    "Unknown Expression 'play' (or 'quit')

    This is not a system expression or variable name in this scope"

    What am I doing wrong? I can't seem to figure it out. The instances clearly have the text values of "play" and "quit".

    Thanks in advance.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • discoverthecurse

    Put " " around the text/sting value, otherwise it thinks it's a variable e.g. "play" not play

  • Wow. Simple fix

    Haha thanks. I don't know why I didn't think about that.


  • Actually the best way to do Buttons is call backs.

    Button.callback text variable

    Button.param text

    OnTouch/MouseDown... on Button

    --Function.Call( Button.callback, Button.param)

    then on your ES you only need to create OnFunction("callback string whatever")

    In fact i've built a GameFrameWork that does this to the Nth degree and I almost do nothing with GUI button.

  • Can you explain that one a little better. I feel like I should follow you but at the moment I don't haha.

  • Can you explain that one a little better. I feel like I should follow you but at the moment I don't haha.

    It's an advanced concept, you might want to wait until you have the basics. But here is a tutorial.


  • I mean I am pretty familiar with the program but I haven't really touched on functions and expressions yet. Kind of working on it on an '"as needed" basis. I'm planning on getting into it pretty soon. Just working on fine tuning some of the cosmetics of the game.

    I appreciate all the replies and help from everyone!


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