Compare variables of X Objects within Line of Sight?

Get help using Construct 2

Post » Thu Dec 15, 2016 10:30 pm

I have a Family that has rules.
The Family roams around freely and they select goals depending on instance variables.

I am using Line of Sight and don't have much experience with it.

If one NPC sees two or more enemies at once. (like a herd).
How do I have it select the lower level or the weakest one?

I know I would use conditions to compare variables, but I am not sure how to check the variable of the objects within the Line of Sight.

Is there an option for that and I am just missing it?
B
62
S
35
G
13
Posts: 230
Reputation: 12,402

Post » Thu Dec 15, 2016 11:20 pm

Im not sure that its optimised for multiple detections at the same time, but if it can you would need to use something like pick by comparison or evaluate.
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Fri Dec 16, 2016 12:07 am

I'm not sure how I didn't know about those. :ugeek:
I will have to read up on those.

I'm not fully ready to implement it just yet.
If it doesn't work I will be back at a later time, but it seems like it would work.

I didn't expect a reply so fast.
Thank you. :mrgreen:
B
62
S
35
G
13
Posts: 230
Reputation: 12,402

Post » Fri Dec 16, 2016 4:04 am

https://www.scirra.com/manual/124/system-conditions

I looked at it and I still have the same issue.
I am not knowing how to look for the lowest variable value from the family objects.

Do this:

Compare
6,7,3,8
Select 3.

Not This

Check for 1.
6,7,3,8
Check for 2.
6,7,3,8
Check for 3.
6,7,3,8
Select 3.

To get the value I need, I have to divide two variables.
The max hp the objects has/ the current amount of hp.
200/100 is 0.5
The results range from 0.0001 to 1000.

I would like this to only have to calculate when an object is targeted.
Having it calculate every X seconds causes a lot of useless calculations.

I think the only way to do this without setting up to many variables is by using an Array.
I can use the objects UID to track in an Array and do the math required as needed.
This will only return one value at a time, but I can set that value to a single instance variable.
This is better than creating X amount of variables in case X amount of objects are in Line of Sight.

I am hoping there is a more simple solution then this.


The question still remains, how do I select the lowest variable without checking every single possible value.
B
62
S
35
G
13
Posts: 230
Reputation: 12,402

Post » Fri Dec 16, 2016 4:34 am

I actually came up with a solution.
I would have to make a new instance variable for selected targets UID and two for target values.

When a target enters the Line of Sight of the targeting object it will calculate what is needed and set the targets UID and current targets value to the instance variables.

If there is another target it will Calculate that as well.
If the new calculated target value is lower than the current one then it will be replaced and the UID will be replaced as well.

If the targeting object looses the target or the the target is destroyed then the three variables will be reset.


I'm still hoping for a more simple solution though...
B
62
S
35
G
13
Posts: 230
Reputation: 12,402

Post » Fri Dec 16, 2016 8:55 pm

Probally the same as you did allready.

https://www.dropbox.com/s/fclzlu1looy70 ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Dec 18, 2016 9:38 pm

I only have 1 family. The objects in the family goes after other objects in the same family. Will that cause any issues? I don't think it would but am not 100% sure.
Should I have 2 duplicate families?


Yours is actually cleaner. Mine was a mess from trying to figure it out.

Thanks for taking the time and helping.
B
62
S
35
G
13
Posts: 230
Reputation: 12,402

Post » Sun Dec 18, 2016 11:35 pm

Yuck, they eat each other. Yes, i think you need 2 family's with the same items as members.
Not that i tested that, but it should work the same as this version:

https://www.dropbox.com/s/mr26jocqkvdop ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Dec 19, 2016 12:36 am

I see you marked out the Else statement. I had trouble figuring out why the Line of Sight range was being ignored. I marked it out on the first example.

I feel I have to explain a small bit. It is more of an hierarchy. Higher rank will go after lower rank. It is similar to a food chain.

Thanks again. I think 2 families would make more sense. I don't really see a problem with only using 1 though, but am not 100% sure. If anything it will be easier to work with, calling two things by one thing when they are two things can get confusing.
B
62
S
35
G
13
Posts: 230
Reputation: 12,402

Post » Mon Dec 19, 2016 11:43 am

The else was just to (in this example) keep them eating, even when there is no food in sight.
I think you going to have troubles with picking a UID starting from previous pickings coming from an overlap between 2 familys. Thats why i anticipated with a distance check version. And yes, only 1 family wil (i think) not work at all.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: Huemerson, ultrafop and 13 guests