How do I set a variable as the number of object into LoS?

Get help using Construct 2

Post » Sat Jul 19, 2014 9:47 pm

I have the object Fire, witch has the internal variable Isolation

I want to make isolation = the number of stones the fire is surrounded by

So i created a line of sight for the fire, but i don't know how to proceed :?

Any idea?
B
63
S
22
G
4
Posts: 357
Reputation: 6,503

Post » Sun Jul 20, 2014 1:51 am

Easy way is to create an invisible object that pins to the Fire (make it the size you want for the detection radius) and then have Isolation as the number of stones being touched/overlapped by the invisible object. If it's any more complex than this then we'll need some more details on what the stones are..
B
45
S
15
G
73
Posts: 2,007
Reputation: 43,396

Post » Sun Jul 20, 2014 2:09 am

plinkie wrote:Easy way is to create an invisible object that pins to the Fire (make it the size you want for the detection radius) and then have Isolation as the number of stones being touched/overlapped by the invisible object. If it's any more complex than this then we'll need some more details on what the stones are..


Is that easy, i've already tried creating the invisible pinned object, but im stuck in the " have Isolation as the number of stones being touched/overlapped by the invisible object" part :oops:
B
63
S
22
G
4
Posts: 357
Reputation: 6,503

Post » Sun Jul 20, 2014 3:09 am

(event) Pinned object "On Collision With" Stones
(condition) For Each Stone > (action) Add 1 to Isolation

To check if it's working correctly, create a text object and set text to (""&Isolation).
This will display the Isolation variable so you can ensure it is calculating the correct number of stones.
B
45
S
15
G
73
Posts: 2,007
Reputation: 43,396

Post » Sun Jul 20, 2014 3:22 am

It is working! but with some adjustments

Condition:
"Every 1 second" (to make it less CPU heavy)
Pinned objects "is overlapping stone"
For each Stone
Fire "pick nearest to pinned object"

Event:
Fire -> add 1 to isolation


in order to make it dynamic, i've added another event right after "every 1 second" (but before the isolation +1 addition): Fire -> set Isolation to 0

The isolation every 1 sec is:

reset to 0
added +1 for each stone nearby

so for example, if there are 2 stones nearby, the result is always 2, and if i add another stone, after 1 sec it's 3. If i remove all stones or move the fire away, it's 0!

Now, every event involving the isolation variables must trigger 0.01 seconds after the "every 1 second" trigger, in order to let the game correctly calculate the isolation after the 0 reset.

It works like a charm!
B
63
S
22
G
4
Posts: 357
Reputation: 6,503

Post » Sun Jul 20, 2014 3:38 am

You actually could get rid of the "For each stone" and just go with "Set Isolation = Stone.PickedCount"
This will return the actual number of instances which are overlapped by the pinned object.

Btw, if you have a license you can use the container to get rid of the condition "Fire pick nearest pinned object" and directly referenced the "radius" object you use for detection.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,317
Reputation: 87,483

Post » Sun Jul 20, 2014 4:01 am

Kyatric wrote:You actually could get rid of the "For each stone" and just go with "Set Isolation = Stone.PickedCount"
This will return the actual number of instances which are overlapped by the pinned object.

Btw, if you have a license you can use the container to get rid of the condition "Fire pick nearest pinned object" and directly referenced the "radius" object you use for detection.


Awesome suggestions!
B
63
S
22
G
4
Posts: 357
Reputation: 6,503


Return to How do I....?

Who is online

Users browsing this forum: leandrogenske, R0J0hound and 13 guests