How do nested Picks work?

0 favourites
  • 6 posts
  • I need help with this code. It finds a Hotkey instance with an associated ID and switches that found hotkey to the current selected one, but...

    The highlighted area is where the problem is. For whatever reason this fails the Pick check, despite debug mode telling me that that particular Hotkey instance exists (at startup, this ID always calculates to 1):

    Is there something I'm doing wrong with these nested Picks? I can't figure it out or continue coding, it's driving me nuts! ( ???)

    Also, no matter whether CURRENT_HOTKEY is +1, -1, or anything other than just the variable itself, it does not pick the object correctly despite the fact there are 10 hotkeys with IDs 1-10.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The first pick makes 'the picklist' where the subs start picking from.

    Loop

    Pick Hotkey with ID = loopindex <-------- the picklist contains now that one Hotkey

    Hotkey Assigned is not -1 <----- picks from previous picked list (containing the hotkey with ID=loopindex), if it exists the new picklist contains a hotkey with ID = loopindex and Assigned =not -1, if it dont exist the new picklist is empty an no matter the action that follow ... they have have no Hotkey to work with

    Lets assume Assigned = not -1, now the picklist contains 1 hotkey with ID = loopindex and Assigned =not -1

    now you set current to the loopindex

    Pick Hotkey with ID = current <------ since current = loopindex, that hotkey is in the previous picked list, it is an unneeded pick, but yeah it works

    Pick Hotkey with ID = current - 1 <-------- the previous picked list is not ever containing that hotkey, it contains only the hotkey with ID = current, since it dont exist in the previous picklist, the new picklist will always be empty and the condition untrue

    So, concluding, the pick hotkey with ID = current is totally not needed, it is picked already.

    To make the pick Hotkey with ID = current - 1 work you first need to make a new picklist that contains that Hotkey.

    Or use a 'pick all' before that condition, or use a function (a function always starts picking from scratch)

  • Ahh I see, so it has already been narrowed down to that single instance, therefore no other picks will work because there is only one in the pick. Each pick would theoretically narrow the list the further down one goes in a chain; I was under the impression every time I use a Pick it starts 100% fresh no matter the code hierarchy.

    Thank you for explaining it step by step. I learned a lot.

    I ended up solving the problem by calling functions to increase/decrease the size.

  • Yesh, that is how it works. Now you know almost everything there is to know.

  • (my post disappeared when editing this for some reason...?)

    Sorry to bump my old thread but I feel insane, I can't get this stupid pick thing to work.

    My old question is fixed but because this relates to picks and I'm still having issues coding additional functionality to my OP I'm just adding to this thread.

    Background:

    In a function that is called on startup, I create all hotkeys in a FOR loop, from 1-10, and number their ID's based on their loopindex. (This works fine)

    Then, I do a function at the end that picks a hotkey based on the ID from the parameter.

    This is the function. It does nothing. It picks nothing. Even with "pick all" nothing goes into its pick list.

    I tried placing this function into startup, and nothing happens either. However, when I place the exact function call on a keyboard press (Q), it works perfectly. so I still must not be understanding how the F pick lists work because my function WORKS, just not WHERE I want it.

    This function all used to be under the startup condition where it worked fine but when I separated it into different functions now shit's going to hell. I can't figure it out. I thought that having a function be called would start from the top of the pick list, but i guess it's some kind of problem having the function be inside of another function that manipulates the object...? But then why wouldn't it work on startup, calling the two separate functions? Why does it only work when I assign it to a keyboard key? RRRGHH.

  • This is a well documented 'gotcha' regarding how C2 creates objects. Newly created objects can't be picked higher than their current sub-event level until the next top-level event. Luckily, in this case, it is still possible to pick by UID specifically. Just pass in the UID, as a parameter, of the newly created Hotkey and do a Pick Hotkey by UID first. It should work from there.

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