Confused: For Each

1 favourites
  • This is amazing AllanR thanks for taking the time and sharing, I appreciate it!

    The code looks very scary to me on a rough look (I'm such a Noob!) but I will have to look in to it more carefully in order to follow and understand how it works, I hope it's not complex or confusing because I'm not into Copy/Past but actual understand, learn and get better by keep developing a step-by-step.

    I already added to my system many things such as rotate, scale, delete, z-order etc.. but I believe that these are the easy stuff compare to build such impressive selection-system like yours!

    Once again, THANKS! (it works very well)

  • I have another question somehow related to the original issue.

    So far when the mouse cursor is OVER any of the instances, I made it where I press a key it will affect the top layer instance, for example:

    If the mouse cursor is over one of the Rock instances and I Press the "DEL" key it will delete it,

    If I press X it will rotate it, and so on... as long as the cursor is OVER that top-layer instance.

    So far so good, BUT!

    Since I have so many hotkeys, I want to make another way more User-Friendly using a graphic-GUI Menu Pop-UP with all the options as buttons. (I'm not asking about how to make the UI Menu)

    How do I solve this?

    Let's say I put the mouse cursor on one of the instances, and RIGHT-CLICK will bring the POP-UP MENU with all the buttons, once I'll move the mouse cursor to that menu to push a button, C3 won't know which instance to affect because my code is related on the mouse-cursor OVER the top-layer instance.

    I'm a bit confused, because I probably need to code it in a different way but, I don't want to cancel the current cursor-mouse OVER instance, I want to ADD the POP-UP MENU as extra option.

    Can anyone please help me out here? (scratching my head)

    I already see how complicated it may become... File examples are more than welcome as I can explore and learn from it!

    Thanks ahead guys for all the help! :)

  • in the rocks.capx file I made, I added a boolean variable on the object family called "Selected". That is used to know which rocks to drag and drop. you could use that variable to know which objects to modify with your popup menu. that way you could select a bunch and have them all rotate/grow/shrink/etc at the same time... or just click on one to "select" it...

    if you don't want people to have to click to select, then when you right-click over an object, set its UID to a global variable so you know which object to apply any changes to.

  • Thanks AllanR! I'm trying to follow and recreate the part of your "Selected" system that will allow me to select with CTRL either 1 or more instances. (not the part with the touch selection) for now.

    The first problem I ran in to (as a C3 noob) is that my layout starts with no instances on it

    So I couldn't choose a color using the "SetColor" effect.

    I guess I will have to set it on the layout sheet but I'm not sure about how or the order, I will check it out maybe it's simple just like the Disable action, I believe the all code is a bit different because I'm creating the instances by clicking a button first, than the are placed on the center of the layout.

    Also, I'm not using the Touch but the mouse so there are things I'm scratching my head how to do, and I don't know what part to copy what part to skip in order to make it work. (trying to skip the SELECTION SQUARE code but I'm not sure because it's complicated for my level).

    I'm trying to recreate the code but the other part of the selection is a bit confusing me in the code and I'm trying to avoid it as I mention, I want to focus on the CTRL CLICK to select / add 1 or more instances.

    Once I'll do that (if I'll be able to do it), I will try to add the POP-UP menu for selected which sound like a great idea as you describe it so I can control either 1 or more using the same button! (very useful!)

    EDIT:

    I thought it would be simple but so far I got lost really fast with the Touch and rest of the code.

    I'm not even sure how to actually set the specific color "Blue" for example, if the instance isn't created yet... and that's before I got confused with the rest of the code.

  • first of all, there is no harm in having Touch in there. I am used to using it so the same code will work with a mouse, without a mouse, touch screen, tablet, phone, whatever...

    if you don't have any instances on the layout at the start, then you don't have to worry about disabling the SetColor. If there were instances, then by default, they would look like they are selected...

    in the code you posted, you are checking if the mouse is over Rocks, but in the subevent you are switching to All_Objects, then filtering those to only ones already selected. so you aren't adding anything new to the selection.

    you can get rid of the subevent, and just set Rocks.Selected to true, and enable its SetColor.

    if you have SetColor defined at the family level with the color you want, then you don't have to worry about changing it in code - just enable and disable when selecting and unselecting objects. (unless you want different objects types to have a different selected color)...

  • Thanks again AllanR you're awesome, I truly appreciate your kind help!

    After reading your explanations, I tried to follow your instructions and what I showed on the last screenshot was just where I started to try recreate your code and stopped this is why it's not complete and obviously doesn't work.

    So, I got rid of the SetColor on start of event and set it via the Family like your suggested.

    Now when I start the application and create a ROCK (or more) they are all RED (default color, I can always change it later).

    Here is what I got so far after cleaning, but how do I proceed from here to make the CTRL+CLICK to select instance or more? where I got confused was the other set variable / values or something like that.

    I believe I have a looong way before I get to the actual POP-UP menu to control the selected instances but it worth it, I'm learning a lot this way! :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I almost got it...

    I've made a clean file to start fresh just to try to work on the multiple selection + tweak selected only.

    As you can see on the attached file I managed to toggle the selection ON/OFF using CTRL.

    But when trying to drag all at once, this is where I got confused... it works only when I select a specific object the rest won't drag.

    I want to drag all of them no matter which one is selected. (like in your example AllanR)

    C3 File:

    https://srv-file7.gofile.io/download/2ZgNlB/Selection%20-%20001a.c3p

  • WOW!!! that zippy site is TERRIBLE! I tried several times with different browsers and could not get the file. got lots of pop-ups, ads, fake updates, redirected to nasty sites, but no file...

  • Sorry about that, I just upload to whatever google suggested me, I didn't see the option to attach via the forums when replying, I've updated the link above to another free file host.

    If still not working please try this link:

    https://gofile.io/?c=2ZgNlB

  • well, unfortunately, there is no easy way to make it work the way players will expect it to work...

    I tried to use the built-in Drag and Drop behaviour in your sample, but the gymnastics you have to go through to make sure the other selected objects are pinned to the one being dragged doesn't always make sense...

    the problem is that the Drag and Drop behaviour assumes that you will be dragging the object you clicked on as soon as the mouse button goes down, but if you open a folder on your computer and test the subtle nuances of how Drag and Drop works with multiple objects you will see that it can not be determined whether you want to drag or change the selection until after you start moving the mouse or release the mouse button. It goes into a "pending" mode and waits to see what the user will do.

    there are actually two different pending situations - if the CTRL key is down and you click on a selected object it needs to wait to see if you start moving the mouse to drag all the objects, or release the button to unselect the one clicked on. The other situation is if the CTRL key is not down and you click on a selected object - now it has to wait to see if you start moving the mouse to drag all the objects, or release the button to clear the selection and just pick the one clicked on.

    most people never stop to think about rules like that, but if you don't follow them people will notice that it seems broken and not doing what they expect.

    so, I started with your file and basically recreated the example I did earlier - this time without using Touch... There is definitely some complex logic in there but there is no way around it.

    I was going to start adding a pop-up menu, but since I don't have a C3 license yet, I can't edit the All_Objects family. You will need to add a sprite to the family to use as the menu background. You need to do this so that you can isolate the menu functionality from the selection/dragging code. (the Mouse code always picks the top instance in the family, if the pop-up menu is not in the family and happens to be over other objects that are in the family, the code will process the click in ways you didn't want...

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

  • First of all thank you so much AllanR for the detailed explanation and the recreation of the file, I appreciate you're taking the time to help!

    So before I saw your file, I messed around with the code again... trying to make it as simple as possible.

    And I almost got it work but... I got lost when it comes to DeSelect! as you can see (file attached) the code is VERY SIMPLISTIC and I feel that there must be a simple solution to FIX what I'm doing wrong here.

    Basically, I created another object that supposed to be followed by the SELECTED OBJECTS (family) only.

    After I had a look on your code, I realized how complex it must be (very confusing for somebody like myself to be honest, BUT! it works). As you already understand I'm not just trying to Copy/Past code that's why I'm still trying other solutions to different problems I'm having and probably will run in to more of them...

    I'm guessing that what happens is something like you described, there must be a CLASH between the selected and unselected objects which cause the mess.

    I still feel that with this creative yet simplistic way, maybe it can be fixed and I just don't see it like many other issues miss, even when I think "logical" first on paper, I can't see the solutions to the most simple things when I get back to C3 code... there is no doubt, I much more to learn.

    Of course I tried to play with 'Is Selected' because it made sense to me that ONLY the SELECTED objects should follow the 'Core_Selector' Object, but after I tried different ways to 'CLICK' to not just deselect after drop the mouse button, but also get rid of the 'Core_Selector' as it's job is temporary.

    My different tests are not on the code to keep it clean as possible for you to see, but I did try to play with INVISIBLE (enable disable) also dedicated layer and even change it's position and such.

    The goal is to make the 'Core_Selector' invisible at the end (once it will work) for now it's visible so we can see it while playing with the code.

    ANYWAY!

    Maybe if you'll have a look on the file you can see a simple solution in the spirit of what I started?

    Because once again, IT WORKS! but not complete, and I would love to learn if there is a simple way to go with this creative solution I tried so far.

    As I'm very hyped now that it works (almost) with the current 'CODE' I'm still playing with it but still, I have a strong feeling that you'll find a simple solution within 5 seconds and LOL as hard as it gets...

    I hope that the upload file works this time:

    https://gofile.io/?c=xIYNeK

    Current Code:

    Thanks ahead for any help!

  • What you are doing is reverse engineering how Drag and Drop works with multiple objects. Every time you encounter a problem, the solution will get more complex. Eventually you will end up with code that probably looks my example! :) But that's how learning works, and you will fully understand how and why it works, lol.

    so, at this point the only options are to provide reduced functionality, or get more complex...

    the basic problem you are having with deselecting is like I described in the last post - it is IMPOSSIBLE to know what the user is wanting to do when the mouse is first clicked. You either have to guess, or wait until they start to do something. If you try to guess, you will be wrong 50% of the time (and the user will think your game is buggy and not working)... when the mouse button goes down, it could be to unselect the object, or it could be to start dragging the whole group. Since you don't know, you have to save what is happening now (where they clicked, what they clicked on), and then wait to see what happens next, and then act accordingly.

    what your code does right now is basically guess that the user always wants to unselect when they click a selected object (it just toggles its state), but the way C3 event triggers work, the object gets pinned to the Code_Selector at the same time as you are trying to unselect it. In event 4, adding "All_Objects - unpin" fixes that problem by unpinning the object you want to unselect. BUT, that ignores the other 50% of cases where the user wanted to start dragging that object with the rest of the group. You WILL NOT be able to have simple code that works well if it is trying to guess what the user is doing!

  • Thank you AllanR for the detailed explanation, it is true that it's a great way learn at least for me.

    I strongly believe that what I'm trying to do could be a simple task, but whenever I'm trying to look for that ACTION that could just allow me to make ALL the SELECTED OBJECTS to follow once I drag the 'Core_Selector' ...there is no such action to do that exactly, but only the Drag option or a more manually way that I couldn't make work using set position that will make the object to FOLLOW the core... and it failed because I couldn't do it right obviously.

    So, I tried to do that without the 'DRAG n DROP' using set position but once again, I get to the point where I can't find the right ACTION to follow using the mouse movement, What I mean is when I tested it with something like:

    When holding the 'RIGHT' arrow key (while SELECTED OBJECTS = TRUE) - Set the position to SELF.X + 5 pixels works SMOOTH! for Right, Left, Up, Down and rotate... but it wasn't possible to just make these rules work when I want it to follow the mouse position (I tried the mouse cursor x and y as well).

    So it worked also manually (without drag n drop behavior), a bit different but did the job... that what makes me believe that there is a way to do it in a clean way.

    I understand what you explained that it is impossible! but the more I play with it the more I believe there must be a simple way to code it, something that I can actually understand.

    I'll probably have to copy/past your original code for this as it just works, but I can't say that it bothers me that it's not possible for me to accomplish even manually with a more simplistic way.

    Programming is not for everyone, even that my brain is VERY logical, I actually drew the logic of how it should work and it looked SOOO simple on the paper... but once I got to C3 I'm missing the actions that I really want to do probably because I'm not in the C3-Think-Mode or something like that, I'm not THAAAT smart after all hehe.

    Anyway, Thanks for the kind help I truly appreciated it Allan! :)

  • glad to help. over the last few years I have learned a great deal by finding interesting problems in the forums and experimenting with solutions...

    I still say it is not a matter of finding the right actions to make it work, it is understanding that there are ambiguous situations that require further input from the user.

    the key part of my code is where the Mouse_Action is set to Pending. That is where it waits to see if the player moves the mouse more than the minimum threshold, or releases the button.

  • That's very encouraging AllanR! I hope to understand C3 better, but for now I'm on the very basics it also may be my "brain" limit, when things get complex I'm lost... this is one of the reasons I really appreciate GROUPS and comments, it helps me a lot!

    So, I'm thinking to make my software/tool to be MUCH MORE primitive than I originally wanted it to be.

    It will be easier to solve issues for me, but I can already hear the users complain about some VERY BASIC tasks that I will probably get rid of...

    I will probably keep asking how to do specific stuff, but if they're too complex for me to follow I prefer not copy/past but find an alternative solution if possible, if not... oh well, PRIMITIVE-MODE = ON! :D

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