How do nested Picks work?

Just started using Construct 2? Post your questions here

Post » Sat Mar 18, 2017 10:29 pm

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...

Image

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):
Image

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.
Last edited by mimiha on Sat Mar 18, 2017 11:19 pm, edited 1 time in total.
B
17
S
3
G
1
Posts: 13
Reputation: 1,370

Post » Sat Mar 18, 2017 11:18 pm

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)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Mar 19, 2017 6:43 pm

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.

Image
B
17
S
3
G
1
Posts: 13
Reputation: 1,370

Post » Sun Mar 19, 2017 9:16 pm

Yesh, that is how it works. Now you know almost everything there is to know.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jun 28, 2017 4:45 am

(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.
Image

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

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.
B
17
S
3
G
1
Posts: 13
Reputation: 1,370

Post » Wed Jun 28, 2017 5:46 am

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.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704


Return to Beginner's Questions

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests