Problem with Instance Variable

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Maybe it's a bug but i am not sure.

    I create 2 instances of the same text object (myText) in design time.

    I also create an instance variable for that object called myId with different for each intance etc. (value 1 for the first instance and 2 for the second instance).

    I put a mouse left click event for the object with the following

    action myText set text to myText.myId.

    When i test this it works good as expected and changes the text of the object every time i click in different instance.

    The problem happens if i decide to create the two instances of myText object not in design time but at runtime with javascript code inside a loop like this for instance

    let myX = 30;

    let myY = 100;

    for (let i=1;i<3;i++){

    let myNewInst = myTxt.createInstance(0,myX,myY,false);

    myNewInst.myId = i;

    myY += 30;

    }

    The two instances are created and and all seems well but if i left click

    with the mouse on each of them the text does not get the myId value of the current instance but the value of the first instance wich is already there from design time and its 0.

    It seems to ignore the fact that the variable is an instance variable and must have different values for each instance.

    Any ideas ?

  • can you try with myNewInst.instVars.myId = i;

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • can you try with myNewInst.instVars.myId = i;

    i tried it and it works !!!

    THANK YOU VERY MUCH

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