question

ana.pc2 avatar image
0 Likes"
ana.pc2 asked Braydn T commented

Check if all members in group are busy

Hello!


I was wondering how to check the status of all members in a group, so I can send the item to a different port if all are busy. For example:


Object item = param(1);
Object current = ownerobject(c);

/**Conditional Port*/

treenode stations = Model.find("Tools/Groups/SB_Group");

if (stations.stats.state().value == STATE_BUSY)
{
    return 2;
}
else
{
    return 1;

}


Thanks for the help!

FlexSim 20.1.1
flexsim 20.1.1send to portstatus
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

ana.pc2 avatar image ana.pc2 commented ·

I think this is working (?):

treenode stations = Model.find("Tools/Groups/SB_Group");

if (stations.as(Object).stats.state().value == STATE_BUSY)
{
    return 2;
}
else
{ ...


But then I get the following error:

time: 73.664834 exception: FlexScript exception: Could not access state variable on object SB_Group (profile: NULL) at ...

0 Likes 0 ·

1 Answer

·
Steven Hamoen avatar image
0 Likes"
Steven Hamoen answered Braydn T commented

@Ana PC2 Please check out the group class. To go through every member of a group you can use an index. So in your case

for(int 1 = 1; i <= Group("SB_Group").length; i++)

{

Object station = Group("SB_Group")[i];

etc...

}

· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

ana.pc2 avatar image ana.pc2 commented ·

Hi @steven.hamoen!

Thanks for your help, but I need to know if all at the same time are busy, then I will send to port 2. If any of all the stations are idle, I want to send to port 1.

I thought about doing a counter, if that station is busy, add 1, once I checked all stations, if that number == lenght of stations on that group, then send to port 2.. but it doesn't work properly...

I leave the code here:

Variant counter = 0;

for(int i = 1; i <= Group("SB_Group").length; i++)
{
    Object station = Group("SB_Group")[i];
    if (station.stats.state().value == STATE_BUSY)
    {
        counter += 1;
    }
}
if (counter == Group("SB_Group").length)
{
    return 2;
}
else
{ ...


Thanks!

0 Likes 0 ·
Braydn T avatar image Braydn T ana.pc2 commented ·

@Ana PC2 That looks like it would work to me. What does not work?

0 Likes 0 ·
Steven Hamoen avatar image Steven Hamoen commented ·

Hi @Ana PC2 Code looks ok. But you say it doesn't work properly. What exactly doesn't it do? And have you tried stepping through the code with the debugger? That way you can see what happens exactly.

0 Likes 0 ·
ana.pc2 avatar image ana.pc2 commented ·

Hi @steven.hamoen and @Braydn T, so it looks like the problem was in:

(station.stats.state().value == STATE_BUSY)

But I changed it to: .subnodes.length > 0 and now it is working... It is a combiner, not a processor, should it matter?

That step now sends things correctly, but then on the next process which I am doing something similar, the simulation stops, and I get:

FlexScript exception: Invalid down cast. Object is not an instance of the target type. at MODEL:/Entrada_B>variables/sendtoport

"Entrada_B" is a Source.... I am trying to fix it but I don't really understand what the issue is... any ideas??

Thanks again!!

0 Likes 0 ·
Braydn T avatar image Braydn T ana.pc2 commented ·
I don't think a source has a busy state. Only generating and blocked.
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.