Line of Sight - What am I missing ??

0 favourites
  • 4 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Hello All,

    I made this simple test using Line of Sight, I want it to affect on each one of the instances of the enemy.

    The LineOfSight Range = 64, Cone of view 360 so it will be easy to test.

    I added a visual way to TEST this: Frame 0 = Eye is Closed, Frame 1 = Eye is Open.

    What am I missing on the "FOR EACH" code ?

    I think I don't use the "FOR EACH" the right way, but.. I thought it should be as simple as I did.

    Can you please EXPLAIN what I am I doing wrong on the code and how to fix it using "FOR EACH" ?

    EDIT:

    I guess even after reading about 'FOR' and 'FOR EACH' loops, I still don't get it... (I'm still new to this)

    Yes, it WORKS with 'FOR' loop, but it made more sense for me that "FOR EACH" will work because of EACH instance of the enemy, but I'm now more confused than ever.

    Also, it works without ANY of the loops, just the two conditions. so if I understand correctly most actions works by default "per instance" or "for each one of the instances" but I'm still very confused and would love to understand based on this example if possible about 'FOR' and 'FOR EACH' please?

    I'll appreciate if someone will be kind enough to explain this to me based on THIS example I post above (with the GIF). Thanks ahead!

  • Dont't use "For each", instead always compare to a instance variable, that meets your condition.

    It's a normal misconception ('gotcha'), that "For Each " picks all that meet an condition. It doesn't.

    This is explained in the manual.

    Have a look at this post, it has the answer for you.

    https://www.construct.net/forum/construct-2/how-do-i-18/how-do-i-get-all-objects-to-st-137546#forumPost949518

    See below post for example.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To make life easier, I have a screenshot of the said events.

    Line of sight is set to >Range 100

    And the c3p file

    https://www.sizzle-games.com/los.c3p

  • Thanks for the help sizcoz I appreciate it!

    As I mentioned above, I made it work with 2 lines without 'FOR' or 'FOR EACH' loops, and the documents didn't help me with their text examples because I'm more visual anyway that's why I hoped that someone to explain when I'll use 'FOR EACH' and when 'FOR'.

    Also, when I use 'FOR' loop what is the index start and end means? still didn't understand it exactly, I mean... number of instances? or number of times it will run the loop? I'm not sure exactly but a would love to finally understand when I should use 'FOR' and 'FOR EACH' because I feel like I'm missing a really powerful and useful way to code when skipping them.

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