Page 1 of 1

Check if objects location is within location group?

PostPosted: Sun Jul 08, 2018 3:52 am
by DazaKiwi
Is there a way to write an restriction expression that checks if an object's location is within a specific location group? So basically the first task runs through an object group and sends an object to another task as per # param method, i then want to check if that objects location is inside a location group. Then add that object into another group I'm wanting to output list of ships detected in a sector/locations. Maybe my brain is a little fried today and there is a simple solution I overlooked lol.

I started out originally using the location group Sector Locations, if any object is present, but i want to narrow it down to objects i can reference and move to another group. I don't think i can use 'any object and any object with property Object is a Ship'.

Basically this is a problem of using two types of groups in a restriction for specific singling out objects.

Re: Check if objects location is within location group?

PostPosted: Sun Jul 08, 2018 6:58 am
by saabie
If you pass both the group of objects and group of locations as parameters to the same executed task then I think it will run once for each combination of an object and a location. Then you just need a restriction to check that %object% is in that %location%. This will only pass for each object that is in one of the locations in the location group.

Re: Check if objects location is within location group?

PostPosted: Mon Jul 09, 2018 10:21 pm
by DazaKiwi
saabie wrote:If you pass both the group of objects and group of locations as parameters to the same executed task then I think it will run once for each combination of an object and a location. Then you just need a restriction to check that %object% is in that %location%. This will only pass for each object that is in one of the locations in the location group.


Thanks for your reply Saabie. I just whipped up a demo to start from scratch again and i clicked i was missing a custom property for the locations, as i dont think you can param a group in all by itself and be useful.

Anyway this demo can be of use to those who want to see params in action.

Re: Check if objects location is within location group?

PostPosted: Tue Jul 10, 2018 2:33 am
by saabie
If you check the debugger you will see that the task runs 4 times for each object.
ADRIFT automatically removes duplicated outputs, but if you run any actions it could be a problem.
You need the restriction [Referenced Object][must][be at location][Referenced Location] to prevent this.

Re: Check if objects location is within location group?

PostPosted: Tue Jul 10, 2018 4:14 am
by DazaKiwi
saabie wrote:If you check the debugger you will see that the task runs 4 times for each object.
ADRIFT automatically removes duplicated outputs, but if you run any actions it could be a problem.
You need the restriction [Referenced Object][must][be at location][Referenced Location] to prevent this.


Thanks saabie for pointing that out. I added that line in and the debugger appears to be the same for the previous version? the goal was to check each unique item to each location, so i would get 4 checks per object anyway wouldn't I? i am not trying to argue in anyway here, just trying to understand :) I think you mean if runner had not omitted the duplicates i would of had the output repeat 4 times per item? and adding that line would have prevented it if runner did not omit duplicate output?

Re: Check if objects location is within location group?

PostPosted: Tue Jul 10, 2018 6:58 am
by saabie
With the new restriction in you should have something like this: (I removed the other two restrictions as they were not doing anything)
adrift Code: Select all
Attempting to execute task Start Demo...
Checking reference free task Start Demo
Passed Restrictions
Executing Actions...
Executing task 'List Unique Objects'.
First Reference: a unique Item 1, a unique Item 2, a unique Item 3, a unique Item 4(no output)
Second Reference: , , , (no output)
Attempting to execute task List Unique Objects...
Checking double reference task # a unique Item 1 Loc 1
Referenced Object must be at Referenced Location: Failed
Failed Restrictions
(no output)
First Reference: a unique Item 1(no output)
Second Reference: (no output)
Checking double reference task # a unique Item 1 Loc 2
Referenced Object must be at Referenced Location: Passed
Passed Restrictions
Executing Actions...
<font color="orange">Item:</font> Unique Item 1 <font color="orange">Loc:</font> Loc 2
 

Item 1 Loc 1 fails the restriction and does nothing, so the task only runs once per object (4 times total).
Without this restriction it would have passed and would have run 16 times.
If the task message used %location%.name instead of %object%.Location.Name then you would have seen all 16 messages as they would all be different then.
If you were using an action to increment a counter to count the number of objects in that sector then the original case would have incorrectly counted 16 instead of 4.

Re: Check if objects location is within location group?

PostPosted: Wed Jul 11, 2018 11:18 pm
by DazaKiwi
Thanks saabie for the info, i will keep that in mind in future. So the rule of the thumb here is to be more specific with restrictions, which means it matches more efficiently? or rather narrow scope rather than wider scope.

Re: Check if objects location is within location group?

PostPosted: Thu Jul 12, 2018 12:38 am
by saabie
The task is called for every combination of parameters you pass to it.
It is up to you to filter it with restrictions to select the ones you want.
In this case you wanted only the tasks where the object parameter is in the location being passed as the location parameter, so you need a restriction that only passes if that is true.