How do I LOS using OR?

0 favourites
  • 12 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Does Line of Sight Behavior not work with OR blocks?

    because it doesn't seem to work in this small test...

    drive.google.com/open

    Why I tested this in the first place is that it's not working at all in a larger project. Although in this small test it works for 1 of the sprites. In my other test it won't work for any of them if there are more than 1 in an OR block.

    Tagged:

  • Edited >>>> Explained better on the next post

  • thanks tarek2 I do use families but not in this case since these happen to be two somewhat unrelated object types. but I am now considering putting them into a family just for this.

    I still don't entirely understand why it's not working for the second object type. It sounds like you are saying an 'OR' isn't actually an 'OR'....which would be puzzling.

    Or are you saying the ELSE doesn't work properly with an 'OR'?

    All I want is to detect one of them so that the sprite is showing that it detects something. I don't care what how many it detects: object1 or object2 or 5 of object3. I just want it to signal it "sees" something when one of those type of sprites passes through it's los.

    so this made it work

    IF LOS of sprite1 THEN detected = true;
    ELSE IF LOS of sprite2 THEN detected = true;
    ELSE detected = false;
    

    but it seems bad form to do that rather than just make 1 complex IF condition with an OR.

  • jobel

    Is a complicated issue: Sorry I didn't have time to make a proper explanation yesterday with examples

    There is an issue with the Picking when you use "Or" blocks but its a construct design, there where many topics about this specific issue

    So basically using "OR" blocks like that you need to know that the Picking applies just to the Top Event object and any objects that you reference after on the "OR" blocks event they don't get Picked, hence the "Else" will only reference the Top Event Object checking if that is true or not ignoring any other objects that you referenced on the "OR" Blocks

    So basically if the top event condition which refers to just one object

    it's false then "Else" will be automatically true regardless that any of the "OR" blocks condition is true

    I made an example so you can visualize better:

    Active only the Group >>> "OR Blocks (Not Woking)"

    As you can see on the Top Event is the Yellow object so this means unless the Yellow object is on line of sight then the detector it will not turn Green.

    But if you drag any of the (blue & Black) Objects regardless if they are on LOS or no it will not detect them.

    Last thing the "Else" is between the Yellow object only, if the yellow object is on LOS then Else is false and if Yellow object is not on LOS then the "Else" will be true, regardless if the (blue or black) objects where in "LOS"

    =======================

    Another Example:

    If you move the black object to the Top of the Event then that object is the one that will become referenced not the Yellow, so the same thing happens as I explained above, unless the black object is on LOS the detector it will not turn Green and the Else is referencing to the Black object only

    ====================

    If you still like to use the "OR" blocks you need to do it with subevents:

    Check Group: >>>> "OR Blocks (Working)" to see how its done

    =================

    or you can use Families which is the easiest:

    Check Group: "Families (Working)"

    ====================

    CAPX: https://www.dropbox.com/s/8rbfpglliae29s0/problem%20with%20%28or%29.capx?dl=0

    I hope I explained with confusing you more

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I didn't really get what the issue was before, but I think I got it from tarek2s example. Picking is preserved across an event block, so that you can filter down from a large set of objects using multiple conditions. I believe the LOS is filtered out on the first condition if it cannot see the target instance. Hence on the following conditions you are checking 0 LOS instances against 1 target instance.

    So the solution is either check against all targets in one condition ( so families ) or use separate blocks for each target ( else if ).

  • tarek2 thanks for the explanation of OR, that makes a lot more sense now. I mean, its not ideal, but at least I understand what is happening. I guess I am thinking too programmatically.

    looking at the Doc it says:

    but it never states the picking only happens on the top event, yikes! that's sort of a huge thing to leave out of the doc!

    also combining that with an ELSE ended up being my problem, since an ELSE is just a "did the last event run?". I'm applying programmer logic to Construct events which is probably my main issue.

    Nepeo basically I was trying to check if an object had LOS to a number of possible other objects. If so it would "light up" as having detected something. I was trying to only write a single ACTION for the detector to light up by using ORs and then an ELSE if none of them were seen to make sure the detector was "off". I know how to do it now (Family or ELSE IF chain). but someone should probably update the doc on ORs though!

    Thanks all....

  • for some reason this thread isn't showing my 2nd reply. But when you reply and look below the REPLY area where you type, my comment is there...but when you refresh it isn't! at least not for me.

  • Actually the doc appears to be saying what I did, so the documentation is correct about this behaviour. Picking IS happening on all conditions, but the effect is cumulative. If you start with 10 instances and the first condition picks 5 then the next condition can only pick from those 5, if that condition picks 0 instances then any following conditions have no instances to pick from and hence are all false.

    In the example you gave each condition is picking from 2 sets of instances, the observer and the targets. Because the observer is used in each condition if any are false the following conditions has 0 instances of the observer to pick from, but because the targets are unique to each condition they have the full set. So it's nothing to do with "else", just how "OR" behaves.

    I admit this behaviour feels a little weird to me, I would have assumed that picking wouldn't work like this in OR blocks, but I'm not familiar with the history of this. There might even be a good reason it works like this that I'm not aware of, but the design of the event system predates me joining Scirra by quite a few years.

    About the reply the website sometimes has caching issues with posts, so they don't show up for awhile or until the thread is updated again. Typically editing the post is enough to make it appear.

  • Nepeo

    Because the observer is used in each condition if any are false the following conditions has 0 instances of the observer to pick from, but because the targets are unique to each condition they have the full set. So it's nothing to do with "else", just how "OR" behaves.

    but I think what tarek2 is saying is that it's always the top condition that picks. everything after the OR will not get picked if that first condition is false but NOT the other way around.

    IF Observer HAS LOS to Object1 OR Observer HAS LOS to Object2
    

    case 1: there's 0 Object1 and 0 Object2 (works as expected)

    case 1: there's 1 Object1 and 0 Object2 (works as expected)

    case 2: there's 0 Object1 and 1 Object2 (disregards second condition)

    Bottom line: an OR can't be used in a picking situation. Which means ORs are limited to Triggers and global/local variables.

  • > Because the observer is used in each condition if any are false the following conditions has 0 instances of the observer to pick from, but because the targets are unique to each condition they have the full set. So it's nothing to do with "else", just how "OR" behaves.

    >

    but I think what tarek2 is saying is that it's always the top condition that picks. everything after the OR will not get picked if that first condition is false but NOT the other way around.

    > IF Observer HAS LOS to Object1 OR Observer HAS LOS to Object2
    

    case 1: there's 0 Object1 and 0 Object2 (works as expected)

    case 1: there's 1 Object1 and 0 Object2 (works as expected)

    case 2: there's 0 Object1 and 1 Object2 (disregards second condition)

    Bottom line: an OR can't be used in a picking situation. Which means ORs are limited to Triggers and global/local variables.

    jobel

    Yes, indeed that's what I was trying to say, at least this is how I understand it

    Is like saying the Top event is true? Then everything true

    Else Top event is not true? Then everything False, Ignoring any "Or" block that can be true in between the Top Event and the Else

    The Problem is nothing to do with else, I was just trying to say that the else is somehow connected just with the Top Event, as jobel wanted to check if none of the objects is on line of sight then the else is not gonna work as it's restricted from the top event if its false only, its then when is gonna Run the else ignoring all the other objects that are on line of sight from the "OR" Conditions.

    I have to admit that is a very complicated issue and that I don't understand the full logic of why is working that way as the whole purpose of the "OR" is invalid on this Picking situation.

  • This is the reason why I added a suggestion to see a list of current picked instances in the debugger. If you set a break point/pause, then step through every condition one at a time, it would be SO USEFUL to see a list of how each condition is picking what instances.

    That way we as creators have some visibility to how the event system is picking instances, especially with these corner case quirks of C3.

    Give the suggestion a few votes if you like it.

    https://construct3.ideas.aha.io/ideas/C3-I-585

  • Fib that's a great idea... I voted..

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