Confused: For Each

1 favourites
  • I'm trying to convert all my individual Instances events to one general Family for more efficiency and less events.

    For example I have an event that whenever the Mouse Cursor is over instance it will Flash (using the Flash Behavior).

    When I tried to convert it to a Family to affect other objects instances I found out that... there is no Flash Behavior for Families.

    So I made a simple Function to make the Flash-Effect, but again.. with or without "For Each" I can't get this to work right.

    Can somebody explain? or if it's confusing (for noobs like myself) add an example file or screenshot?

    Thanks ahead!

    Work in Progress so far:

  • I'm trying to convert all my individual Instances events to one general Family for more efficiency and less events.

    For example I have an event that whenever the Mouse Cursor is over instance it will Flash (using the Flash Behavior).

    When I tried to convert it to a Family to affect other objects instances I found out that... there is no Flash Behavior for Families.

    So I made a simple Function to make the Flash-Effect, but again.. with or without "For Each" I can't get this to work right.

    Can somebody explain? or if it's confusing (for noobs like myself) add an example file or screenshot?

    Thanks ahead!

    Work in Progress so far:

    The Function "FLASH ME" doesn't know which object you want to flash. Try adding a number parameter to the function called UID which passes through the UID of the object you would like to flash, and then add a "Pick by UID" condition to the function to pick the family object with the UID that has been passed through

  • Thanks for the reply kidswithcrowns

    To be honest I have no idea how to do what you suggested, your explanation make sense to me because it should know on which instance of the family the cursor is over.

    But to be honest I have no idea how to do that, I never used pick UID or the new functions, can you please share an example or screenshot of how I should solve this?

    Also, I don't know how to let that function know which UID to pick because I keep creating new instances on a click of a button (they are not appearing without me creating them). so it's confusing for me to follow logically, beside the code part.

    Thanks ahead!

    This is the mess I did, obviously there are lots of guesses and I'm not even close, just sharing:

  • I made a simple example that works PERFECT (without families or functions) just to show the issue and what I'm trying to solve inside the file using comments.

    Hopefully somebody can help me solve this before my code will become HUGE with ZILLION of events that does the same thing for each (that's the key "FOR EACH" I know... but can't solve it yet).

    Maybe using 'Families' and 'For Each' maybe 'functions' I have no clue, but there must be a SIMPLE way that won't confuse my simple brain.

    Maybe AllanR can you save the day? ;)

    C3 File Attached - Please have a Look, Thanks ahead!

  • OK, the Flash issue is that you can't add the behavior if any of the family members already have it. So, remove it from the other objects and then you can add it to the family.

    that makes having one set of events for the family very easy to do...

    although the rotate doesn't seem to work, and the trigger once condition doesn't work when you have many overlapping objects of the same type (as you move the mouse from one to another - if it is never not over that type, then the trigger once condition doesn't reset).

  • ok, the rotate issue was because the buttons still had focus and were intercepting the keyboard, so when a button is pressed, I added a set Unfocus action to fix that.

    and I added a global variable to track which instance the mouse is over. now it works the way you would expect - it doesn't use trigger once.

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

  • WOW! You did save the day AllanR! Thank you so much!

    I still need to explore and understand how the all UID works, because it says Created_Object.UID without a specific number so I'm not sure how C3 knows which UID is the picked one... (never used UID before, it's NEW to me). I'm guessing that C3 will look at the Top Instance it picked (from the main event) and it will GIVE it the UID? if so... I'm close to understand it? I'm not sure hehe

    I will now try to replicate this type of code to my actual software (it is already getting HUGE) compare to the current clean example I shared, I hope it will work and I won't do a mess.

    OFF TOPIC:

    Do you think it is possible to apply that UNDO/REDO system we discussed on my other thread to this clean example so I can see how it looks and hopefully will be able to understand it?

    Thanks for everything! I'll start make these changes (can't wait to see it work!)

  • I will be playing with the undo/redo later...

    the UID is the unique identifier number that every object gets assigned when it is created, or just added to a layout. when you have multiple objects of the same type, it comes in handy to tell them apart. You can also give objects instance variables and use that to keep track of them, or their X and Y position, etc... but UID is the definitive way to make sure you have the right instance. - you will see it a lot in the undo/redo code...

  • Alon Here is an example of how you would do it with UID and functions ufile.io/sj12iisk

    If you use Object.UID it will give you the UID of whatever object is currently 'picked'. In this case it's whatever object your cursor is over

  • Thanks for the explanation and example files guys!

    I still didn't have a chance to replicate the code to my actual project, but will do that soon it looks so efficient I'm very happy about this way and can't wait to test it.

    I did understood what UID means, but like I said on my last post, I didn't understand exactly how C3 will know which UID to pick? will it pick the one that the mouse cursor is over based on the top event: "Pick Top instance" ? or it's picking it's UID (the actual object number) from a different way?

    It's not critical because everything works, but as you already know me AllanR I love learning rather than just copy/past, this is why I'm asking how it's actually picking the number of the object, based on what?

    I will check the flashing example kidswithcrowns with the functions and family as well, looks interesting and efficient way for me to learn how things are working, thank you for taking the time both of you are amazing!

    Anyway, I'll make sure to try replicate Allan's version to my project asap, before things will get even more complex... I'll probably going to have more ISSUES hopefully you guys won't get tired of my stupid questions to come.

    Sorry about my bad English and big Thanks! :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • here is a start on the Undo/redo...

    at the moment it can only undo the Create actions and the Drag/Drop actions. the undo list is not limited at this point, so you could do (and undo) thousands of actions.

    if you do a bunch of actions, then undo half of them, then start doing new actions, the redo list is truncated at that point since any potential redo's don't make sense anymore...

    any other types of actions you want to be able to undo will each require their own section in the log action function and the undo/redo events...

    for the rotate action, you just want to log the start and end angle, not every 0.35 degree change - it would take forever to undo!

    and the Z-order change will have to get the object back into the original place - I have to think a bit about that one, and I am out of time today...

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

  • WOW!!! for a work-in-progress UNDO/REDO system it works very well!

    Not that I know how it works or understanding.. but maybe for the best way for the Angle Rotation solution is simple as to "store" (or however it works) once you DROP the key / unpress since it's a HOLD action.

    So from the start press to once you unpressed, I'm not sure if it can work but.. just thought about it.

    In my project, I have tiny angle rotation like this one, and also a one that snap 45 degrees every click (when you hold SHIFT + X / Z) but on this one I wanted to keep it as clean and simple as possible for making the rest of the code-magic you put so I can find it.

    Feel free to update on this whenever you get the time, I'm still going to replicate the first part before I'll look into the UNDO/REDO just to make sure everything works before I move on.

    Dear AllanR thanks a lot for your time and afford and most of all your kind help and patience!

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