ADRIFT Forum


The place to discuss the ADRIFT Interactive Fiction toolkit

Randomly choosing enemies on the fly..not working correctly

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.

Randomly choosing enemies on the fly..not working correctly

Postby DazaKiwi » Mon Mar 25, 2019 12:56 am

I was wondering if someone could tell me why my Selection method 2 (by default) in my demo is a 50/50 success rather than 100%. Read on for explanation.

I created a demo to find the best method to move npcs on the fly based on location/group and number of them needed, which is stored in location property. So in this demo only monkeys are in play. Im sure they are up to no good.

I created two methods of doing this;

Selection type 1; In simple terms moves NPCs from a group according to the location property number of how many NPCs are needed. It always would move 2-5 Monkeys from top of the group list in same order. So no variety. Which is fine if you have generic type of NPCs like guards.

Selection Type 2; Using ID character numbers for the Monkeys and randomly pick them, using a rand range based on specific group size. However i found sometimes it was missing 1-2 or 3 characters when there should be 5 NPCs, then returning to that same location there are 5 NPCs, so it seems to be a bit of a hit and miss (for Selection 2 method) and i don't know why it is doing this. I am using a loop method, which unfortunately has a slight delay when the player moves to a new location, but i do not know of a more efficient method.

Is there a better way to achieve the same thing? And why does the number of Monkeys moved doesn't always match the required number (which is also displayed at each location)?
Attachments
Move_Guards_to_Loc_demo_v2.taf
Just the monkeys
(17.86 KiB) Downloaded 160 times
User avatar
DazaKiwi
 
Posts: 609
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Randomly choosing enemies on the fly..not working correc

Postby saabie » Mon Mar 25, 2019 4:21 am

At first glance it looks like you compare each monkey ID with a different random number each time.
You probably need to store the random number in a number variable first and then loop over the monkeys comparing ID to that variable.
I will have a closer look when I have time.
saabie
 
Posts: 958
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25

Re: Randomly choosing enemies on the fly..not working correc

Postby DazaKiwi » Mon Mar 25, 2019 10:12 pm

Ok i have created a new variable RandomNumber and in the task as first instruction that calls the loop task that matches Monkey ID to Random number. In action of the loop task it sets a new random number to RandomNumber for next loop cycle. However this method is not working properly. Always short of 1 or 2, sometimes 3 short. Note: currently the max number of Monkeys that can to be moved is 5.

So i made some changes; move picked monkey out of the main group that gets ID matched against. And this group gets refilled again when player moves. It is an improvement but when its 5 Monkeys (This is in Loc 7) needed it NEVER moves 5 Monkeys it managed 4 once and most of the time its below 4. So i increased the loop rate to 7 and now it does move 5 Monkeys sometimes.

So perhaps the chief problem is the same random number is getting picked a couple of times and thus the matching task fails or at least matches to the same monkey it did before, so even if the monkey has been moved out of the group or not, still wont make a difference. I don't think urand will help since the RandomNumber is created each loop.

I need to be able to store the picked number and make that part of the restrictions.? not an easy thing to implement.

There might be a better way to do this so that the correct randomly picked monkeys are moved every time?
User avatar
DazaKiwi
 
Posts: 609
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Randomly choosing enemies on the fly..not working correc

Postby saabie » Tue Mar 26, 2019 1:57 am

I think I have it working now. I split the daz5PickRandom task into two and modified the loop in Daz5SwitchGate that calls them.
Each time the first one is called by the loop it chooses a new %RandomNumber% (using urand instead of rand to minimize repeats) and then calls the second with the filtered monkey group.
The second task now only has to find the monkey with that ID and move it. It also checks that it does not try to move the same monkey twice.

The main problem was that it was picking the monkeyID completely randomly at each check so it rarely found a match (making it slow) but it was also more likely to try to move the same
monkey twice and had no check for that, so it decremented the counter twice for one monkey and hence thought it had moved more monkeys than it had.
Move_Guards_to_Loc_demo_v2s.taf
(17.92 KiB) Downloaded 13 times
saabie
 
Posts: 958
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25

Re: Randomly choosing enemies on the fly..not working correc

Postby DazaKiwi » Tue Mar 26, 2019 10:39 pm

Thank you Saabie for the solution. It works as intended, great. I didn't think to have a restriction of referenced character must not be at same loc as player. Its obvious now. I did try urand but my method was flawed.

Just so i understand completely, why is it important to have the random number stored in variable before running the param match ID task? why did my method fail with having it urand in restriction itself?

Thanks.
User avatar
DazaKiwi
 
Posts: 609
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Randomly choosing enemies on the fly..not working correc

Postby saabie » Tue Mar 26, 2019 11:26 pm

This is to force it to evaluate the function before calling the task that loops over the monkeys looking for an ID match.

If you pass the urand expression as a parameter, or have it in the restriction, then it is evaluated separately each time.
So instead of searching for a monkey with a particular ID, it uses a different ID number for each test so it will often fail to find a match.
This made it do more loops (slow) and sometimes it reached the end of the LOOP count without matching enough monkeys.

This is a completely separate cause of the "not enough monkeys" problem. Not checking if the same monkey is matched twice was the other cause.
saabie
 
Posts: 958
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25

Re: Randomly choosing enemies on the fly..not working correc

Postby DazaKiwi » Wed Mar 27, 2019 6:09 am

Thanks for the explanation, that makes sense now. Cheers :)
User avatar
DazaKiwi
 
Posts: 609
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Randomly choosing enemies on the fly..not working correc

Postby DazaKiwi » Wed May 08, 2019 11:36 am

Just a follow up question with built in loops by default it starts at 0, so if you need 5 loops does it need to be set thus 0 to 4? or 0 to 5?
User avatar
DazaKiwi
 
Posts: 609
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Randomly choosing enemies on the fly..not working correc

Postby saabie » Wed May 08, 2019 1:37 pm

0 to 4
= 0, 1, 2, 3, 4
saabie
 
Posts: 958
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25

Re: Randomly choosing enemies on the fly..not working correc

Postby DazaKiwi » Wed May 08, 2019 10:09 pm

Ok thanks for clearing that up, that is what i thought.
User avatar
DazaKiwi
 
Posts: 609
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16


Return to ADRIFT 5.0

Who is online

Users browsing this forum: No registered users and 1 guest