The annoying picking problem (Ashley please clarify it ty)

Get help using Construct 2

Post » Fri Apr 04, 2014 12:52 pm

Just hoped that I had missed something, and it was because you just have to "do this and this" kind of thing :) But guess ill just restructure how I do it.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Fri Apr 04, 2014 3:25 pm

Think I might have found a solution to do it without using waits. However it does requires an extra check every tick. But if it works I think its worth it :D

The Idea is to use an object handler, that can handle all newly created objects.

You can make it with a list or array whatever you prefer. However you still need to organize the way you create objects according to the normal rules.

In my case it uses a list, the idea is that these objects that rely on other objects that might not be created yet during the cycle, are added to this list. And then you apply whatever extensions to them that you want. And its actually quite simple to make.

In my game the handler looks like this:
Image

Which in this case is the Quest_master_object that give me the problem. As its the one that rely on a Quest_step, which is a sub quest that are part of the master quest. To this Quest_step there is a dungeon attached. Which again is used to generate a random Quest description.

To use the object handler all you have to do, is tell it what action you want it to do, in form of a Boolean, and then add the UID to the list. And then hook it up to a function, or whatever you prefer.
Image

And you can just add as many conditions and objects to the object handler as needed. I think the benefit comes when you have to do something several times during one tick. For instant in my case I actually have to repeat it 5 times, but having to wait each time is first of all not something I like, but also seems to create problems, as sometimes the descriptions got mixed, some steps weren't made etc.

Anyway haven't tested it fully, but the initial tests seems to work very well, and now at least this problem is solved :D
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Mon Apr 07, 2014 12:05 am

Nice work. Looks pretty slick.

I was reading up on the thread that explains why picking works this way now, and I'm actually confused.
https://www.scirra.com/forum/viewtopic.php?t=73647&start=0

In the thread, it is explained that the object doesn't exist to same-level events until the next top level event. Then how come pick by UID works on our tests?
ImageImageImage
B
38
S
5
G
4
Posts: 79
Reputation: 5,355

Post » Mon Apr 07, 2014 12:35 am

Nice work. Looks pretty slick.

I was reading up on the thread that explains why picking works this way now, and I'm actually confused.
viewtopic.php?t=73647&start=0

In the thread, it is explained that the object doesn't exist to same-level events until the next top level event. Then how come pick by UID works on our tests?

Agree that it gets confusing, because its logic that you have created the object, so surely it must be there, but it actually ain't as explained by Ashley in that post.

A solution also from that post is:
The workaround is to try to do everything in the same event - nest the other events beneath the creating event if possible, so everything is moved up in to the green area.

Which are the reason that you can create an object and right afterwards set its variables.

Create object
Set Object name = "Whatever"

That also means that you can pick UID of the object if its in a sub level of the create function.

But if you do it like this:

level 1: Create object
--------------Do something
Level 1: Pick Object with UID of the newly created object shouldn't work.

You have to reach a top level. (Now this post is from version r102, so its pretty old, but don't think a lot if any have changed.)

However the common way of dealing with this problem as you most likely know is to throw in a Wait of 0, 0.1 or 0.01 or whatever as it will then go through to the next tick and force it to reach a top level or what to say and then it works. Im not really sure how solid this actually is, it seems to work well with simple stuff, but if it gets a bit complex it seems to not really work well.

For instant if you have an event:

Repeat 10 times
------- Call function("Spawn enemy")

Function Spawn enemy
Create enemy()
Call function ("initialize enemy")

Function Initialize enemy
Call function ("Create enemy weapon")

Function Create enemy weapon
Create Enemy_weapon

Then suddenly things starts to go wrong as I see it.

Because now there are actually two objects that doesn't exist yet, The Enemy and the Weapon that you want it to use. So if you throw in a Wait different places to solve it, It might work. However at the very start we are actually repeating this 10 times, to create 10 enemies which will then create 10 different weapons, so suddenly you might have 20 objects that actually doesn't exist, and then it seems to go wrong. Whether that's completely true im not 100% sure about, but it seems that a function doesn't count as a top level, which I find to be logic if its the case, but I haven't seen anything saying that it ain't which is why im not certain.

As I mentioned in my last post, I had to repeat it 5 times, but I did something similar with 50 objects using a wait, and it looked like it was working fine, however as I went through the objects in the debugger I could see that suddenly some of the objects would have "NaN" in some of the variables. Which didn't make sense as 95-98% of them had no problems and all different possibilities for this variable was used, but for some reason some of them just failed, and my guess it that since I repeated it several times, it might have screwed up with the wait somehow. So the only thing I did, was to move the function call to the Object handler, didn't change any code and none of them had any problems after that, same goes for several other mistakes that was happening. So I moved those as well and now all of them gets initialized correctly, without having to use wait, which I think in itself is a huge benefit.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Mon Apr 07, 2014 5:42 am

Just to add that the "pick by uid" condition is the exception to the rule about picking since r127.
https://www.scirra.com/construct2/releases/r127
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Apr 07, 2014 1:06 pm

Wow, I don't know how I missed that. I read all of the patch motes like a hawk. Thanks R0J0 that answers my question!
ImageImageImage
B
38
S
5
G
4
Posts: 79
Reputation: 5,355

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests