ADRIFT Forum


The place to discuss the ADRIFT Interactive Fiction toolkit

Check if objects location is within location group?

This forum is the place to learn about and discuss ADRIFT 5. Feel free to mention any bugs you find here, but please also add these to the Bugs & Enhancements list.

Please also refer to the ADRIFT 5 Wiki for more information.

Check if objects location is within location group?

Postby DazaKiwi » Sun Jul 08, 2018 3:52 am

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.
User avatar
DazaKiwi
 
Posts: 530
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Check if objects location is within location group?

Postby saabie » Sun Jul 08, 2018 6:58 am

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.
saabie
 
Posts: 911
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25

Re: Check if objects location is within location group?

Postby DazaKiwi » Mon Jul 09, 2018 10:21 pm

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.
Attachments
ObjectLocation_v1.taf
Little demo
(15.81 KiB) Downloaded 18 times
User avatar
DazaKiwi
 
Posts: 530
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Check if objects location is within location group?

Postby saabie » Tue Jul 10, 2018 2:33 am

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.
saabie
 
Posts: 911
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25

Re: Check if objects location is within location group?

Postby DazaKiwi » Tue Jul 10, 2018 4:14 am

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?
User avatar
DazaKiwi
 
Posts: 530
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Check if objects location is within location group?

Postby saabie » Tue Jul 10, 2018 6:58 am

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.
saabie
 
Posts: 911
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25

Re: Check if objects location is within location group?

Postby DazaKiwi » Wed Jul 11, 2018 11:18 pm

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.
User avatar
DazaKiwi
 
Posts: 530
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Check if objects location is within location group?

Postby saabie » Thu Jul 12, 2018 12:38 am

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.
saabie
 
Posts: 911
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25


Return to ADRIFT 5.0

Who is online

Users browsing this forum: No registered users and 3 guests