I have a very simple problem. I have a converter, and I want to set it up so that it alternates between sending entities between its two successors, i.e, first entity -> successor 1, second entity -> successor 2, third entity -> successor 1, so on.
I feel as though there should be a very easy built in way to do this, however I can't seem to find it. I attempted to use a method to do this. This is my code:
var i := 1
if i mod 2 = 1
?.ExitForNextEnteringMU := 3
i := i + 1
?.ExitForNextEnteringMU := 0
i := i + 1
My code is not working for some reason, the entity's are passing through, but they are not alternating, only exiting through side 3. A solution to my code would be appreciated, but I'd prefer a more direct way of accomplishing this alternating behaviour if it exists.
Solved! Go to Solution.
I do not really store the previous exit to my knowledge. Not really sure how to call that. I actually just realized the issue with my code. That issue being: I was using a local variable that was being reset to 1 every time the method was called. I have corrected that issue by using a global variable instead, and now my code works.
However, I would like this to be more robust so that I can use it in multiple places simultaneously. As it stands I would have to create a separate method and global variable for each instance that I want to use it, so that they don't interfere with each other.
Is there a better way to accomplish what I am trying to do than my current method?
Well, it can be quite simple.
Normally you would create a new class, say MyConverter, derived from the Converter class. For MyConverter you create a user-defined attribute of type method and set it is the Strategy-control. Regarding the next exit, you can just read the current value of ExitForNextEnteringMU and use that for your decision.
Now that you have implemented the desired behavior in your own class MyConverter, you can just create as many instances of those as you like. They will all work independently, albeit according to your strategy.
Ok question regarding that: I have a converter set up as you mentioned. And I have it so that it determines the exit for the next entity based on the current state of ExitForNextEnteringMU.
How do I give it an initial value for ExitForNextEnteringMU? Initially, it had a first line for that, which I left in, however it defaulted to that every time. I took out that line, and now entity's won't enter the converter. I'm assuming this is because there is no initial value, but I don't know how to set that without it taking over every time?
I believe my suggestion contains a slight omission: it is reset to -1 on every cycle.
So you should create another user-defined attribute to store and read the target exit.
Just like the method, create an attribute of type integer and name it "PreviousTarget" or whatever.
I think something like this:
(entranceNo: integer) is do if ?.PreviousTarget=1 then ?.PreviousTarget:=3; else ?.PreviousTarget:=1; end; ?.ExitForNextEnteringMU:=?.PreviousTarget; end;
Ok, I'm sorry I just ran into another issue. Is there a way to Identify where the converters successors are?
My issue is the first converter that I was wanting to use this on has the exits: 0 and 3, however the other coverter that I would like to use it on has the exits: 1 and 3. Is there a way to identify the available exits and have it alternate between those?