Familie and instance variable

  • I create a families "Enemies" of sprite with an instance variable "heatlh".

    I made an event:

    "mouse" click on" "families Enemies" => "families Enemies" changes instance variable "health".

    I was thinking that only the sprite who was click on will have his instance variable change. It seems that alls the object of the families get their variable changes.

    How can i correct this?

    Thanks

  • Should just be the one that is clicked, lets see a screenshot of your events and structure.

  • It should only affect the clicked instance. You must have done something different to what you explained. It's easiest to help if you share a project.

  • here it is. Thanks for your answear.

  • Do you change the "health" variable in "VerificationResponse" function? The function doesn't know which instance was clicked. You need to pass Element.UID to the function in a parameter, and pick Element instance by UID inside the function.

    Also, it's difficult to read your screenshots as they are in French. Please next time switch C3 language to English, or post your project file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I will put it in english :)

    The familie instance variable is "ReponseJoueur" , the familie is "Element".

  • The code you posted should work correctly. If ReponseJoueur is changed for all instances, there is probably some other event that causes it.

  • Maybe, i confuse and the problem is not that all the instance variable are change.

    I beleived it's that because i test by creating "text" to show the instance variable of each element and that's what i saw.

    Here is the rest of the code.

  • Again, I don't see any problem with ReponseJoueur variable.

    Have you tried running the project in Debug Mode and checking instance variables there?

  • The problem is probably somewhere else, sorry to disturb you for nothing i will check everything.

  • There were a number of minor problems...

    your sprite font should be 16x16 (not 20x20)

    the animation speed for Cadenas was not 0, so it was playing the whole animation. You want it to stay at the frame you assign, so it should be 0.

    You want to unlock levels Less than or equal to Niveau

    In VerificationReponse, you want to check if every piece in the puzzle is set to the correct colour, so you need a for each Element loop, and if the number that are correct matches the total number of Element, then show Victoire and go back to the menu.

    https://www.rieperts.com/games/forum/CouleurFix.c3p

    oh, I added a TextInput box in the top right corner that shows what each piece is set to for debugging... so I would know what to set each piece to :)

    Edit: the family instance variable was being set correctly. It was how you were checking if the puzzle was complete that was the problem.

  • Thanks for everything :)

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