How exactly do families work?

0 favourites
  • 7 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • I checked up on the documentation for family properties, but I still have some questions.

    I am trying to make a simple puzzle where turning a light on adds 1 to a counter, and turning a light off removes the addition from the counter

    I have a master event that sets the total lights value to be each light's value manually (Light1.value+Lightx.Value-etc.)

    Does anyone have better ideas for a system to check through each light and do this without recoding it every time? I can imagine making a puzzle with 10 lights will start making this process annoying

    Is there a check every instance in this family type of thing? I've had problems earlier with incorrect addition when I've tried other methods.

    I have it working right now but I just want to be more efficient about it.

    Alternatively if this would work better with another system I'd love to hear about it.

    Code to start process

    Code to set values

    Code to add values together to global variable

    Tagged:

  • If all lights have the same animations/images, then you don't need 10 identical sprites. Use just one sprite with 10 instances.

    Also, you can remove either On or Value variable, since they both mean the same thing.

    On click -> Toggle On and call the function.

    Inside the function -> If On, set animation to "On", else set animation to "Off". Also pick lights with On=true and use Light.pickedCount to get the number of lights that are on.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • As dop2000 mentioned this is an ineffective method

    drive.google.com/file/d/1yeiRj7hQchI5-pxlpeH5Eks3KNpGGiAB/view

  • thank you guys so much for the explanation, this definitely makes one part of my puzzle a lot simpler to code!

    There's one part that still stays confusing for me which is the activation of each light. Part of my puzzle is that a light will activate itself plus the next light instance in order. For now I just have it hard coded

    Would there be a solution to have it turn on self and (self)+1?

  • If you have an instance variable on and then set that to 0 or 1 depending on whether light is ON, ( set to 0 if OFF )

    You can go through all of them and add them up with

    System> for each> light

    Add light.on to your global total variable

    To turn the next light in line, yeas, I guess you could have an ID instance variable, then when you click light with instance variable of ID+1, or just pick the closest to the one clicked if that is how it is supposed to work

  • You can use IIDs. When a light is switched on, save Light.IID in a temporary variable. Then pick the next Light number (SavedIID+1) using "System pick Nth instance" and turn it also on.

    Light On click -> Light Toggle On
    ...............-> set SavedIID to LightIID
    
     System pick all Light
     System pick Nth instance (SavedIID+1) -> Light Toggle On
    
  • Another method is using a larger transparent sprite area to select multiple sprites

    https://drive.google.com/file/d/1r4yeFNSmeswsO1xbX0zSpxK7M_djHWfb/view?usp=sharing

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