Help needed in basic 4DS Programming

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
exoplanet
Posts: 11
Joined: Thursday 10 November, 2022 - 00:11

Help needed in basic 4DS Programming

Post by exoplanet »

Hello everyone,

I'm currently trying to program some basic methods with 4DS and came to a point where I could use some help.

My goal: A model consisting of a Product-, Source-, Queue-, Server-atom and four Sink-atoms, in which the source has an max. output of 40 products and the server atom should assign icon numbers adepending on the Input of the server. The first ten products which are processed in the server should be assigned with icon number 41, product eleven to 20 with icon number 42, etc.. I used the Trigger on entry of the server for this as shown in the picture below.

At the End the four different products with icon number 41 to 44 should be sent to four different sink-atoms. Icon 41 in one, 42 in two, etc.
For this I tried to write code for the send to strategy of the server-atom but it's not working out.. Does anyone might have a hint or improvement suggestion?

Huge thanks in advance!


best regards

Max
Attachments
Model-Sent to strategy.JPG
Model-Sent to strategy.JPG (26.54 KiB) Viewed 10348 times
Model-Trigger on entry of the server-atom.JPG
Model-Trigger on entry of the server-atom.JPG (31.05 KiB) Viewed 10348 times
Model.JPG
Model.JPG (65.86 KiB) Viewed 10348 times
User avatar
Gabe-Hein Dijkstra
Posts: 16
Joined: Friday 13 May, 2022 - 10:16

Re: Help needed in basic 4DS Programming

Post by Gabe-Hein Dijkstra »

Hi Max,

Welcome back to the forum!

The problem lies in the consecutive if-functions in your SendTo. The results from the previous if-statements are overwritten later on.

From the help:

"Syntax: If(e1, e2 {, e3})

Parameter 1 (e1) is the test statement. If this test statement returns 1 (True) parameter 2 (e2) is executed. If not optional parameter 3 (e3) is executed."

When the optional parameter 3 is not defined, it is seen as zero. Hence, the code

Code: Select all

If(
	Icon(refToAtom) = 41,
	1
)
returns 1 whenever the icon number of the atom refToAtom is equal to 41. Otherwise, this code returns zero.

Furthermore, please look in the help to check what the atom reference "i" means. There is no involved atom on a SendTo, and hence you cannot use "i" there.

Hopefully these tips help you in the right direction!

Kind regards,
Gabe-Hein
exoplanet
Posts: 11
Joined: Thursday 10 November, 2022 - 00:11

Re: Help needed in basic 4DS Programming

Post by exoplanet »

Gabe-Hein Dijkstra wrote: Tuesday 06 December, 2022 - 10:32 Hi Max,

Welcome back to the forum!

The problem lies in the consecutive if-functions in your SendTo. The results from the previous if-statements are overwritten later on.

From the help:

"Syntax: If(e1, e2 {, e3})

Parameter 1 (e1) is the test statement. If this test statement returns 1 (True) parameter 2 (e2) is executed. If not optional parameter 3 (e3) is executed."

When the optional parameter 3 is not defined, it is seen as zero. Hence, the code

Code: Select all

If(
	Icon(refToAtom) = 41,
	1
)
returns 1 whenever the icon number of the atom refToAtom is equal to 41. Otherwise, this code returns zero.

Furthermore, please look in the help to check what the atom reference "i" means. There is no involved atom on a SendTo, and hence you cannot use "i" there.

Hopefully these tips help you in the right direction!

Kind regards,
Gabe-Hein

Hi Gabe-Hein,

as always thanks a lot for replying this fast i really appreciate it.

1. In gerneral I kinda unterstood why the if-functions are being overwritten, but not really why it's being overwritten in the send-to and not in the trigger on entry of the server atom. I tried to orientate myself on the pre-defined send-to logic for the icon number:
if(icon(rank(1,c)) = 1, 1, 2) and understood everything except why the rank(1,c) statemant is implemented. I guess in case the server is processing more than one atom (product) at a time, so the if-statement is always refering to the atom (product) waiting at the first position in the atom on which the logic is defined? Or is this the only possibility to refer to "c"?

2. I already try to get as much info from the help function and also the 4DS-Tutorial (even if it might not be looking like that :D ) and I think I also understood the basic differences between the atom references "i" and "c" but could not really evaluate why it's not adaptable to the send-to when I'm looking at the involed atom which is leaving the current atom "c" and should be sent.


3. Honestly there still might be some questionmarks in my brain and I could use a further hint for a applicable function. Or is there an option in seperating the continuous if-statements from each other in order that the code is not returning a zero?

Thanks again for your time!


best regards

Max
exoplanet
Posts: 11
Joined: Thursday 10 November, 2022 - 00:11

Re: Help needed in basic 4DS Programming

Post by exoplanet »

exoplanet wrote: Tuesday 06 December, 2022 - 21:55
Gabe-Hein Dijkstra wrote: Tuesday 06 December, 2022 - 10:32 Hi Max,

Welcome back to the forum!

The problem lies in the consecutive if-functions in your SendTo. The results from the previous if-statements are overwritten later on.

From the help:

"Syntax: If(e1, e2 {, e3})

Parameter 1 (e1) is the test statement. If this test statement returns 1 (True) parameter 2 (e2) is executed. If not optional parameter 3 (e3) is executed."

When the optional parameter 3 is not defined, it is seen as zero. Hence, the code

Code: Select all

If(
	Icon(refToAtom) = 41,
	1
)
returns 1 whenever the icon number of the atom refToAtom is equal to 41. Otherwise, this code returns zero.

Furthermore, please look in the help to check what the atom reference "i" means. There is no involved atom on a SendTo, and hence you cannot use "i" there.

Hopefully these tips help you in the right direction!

Kind regards,
Gabe-Hein

Hi Gabe-Hein,

as always thanks a lot for replying this fast i really appreciate it.

1. In gerneral I kinda unterstood why the if-functions are being overwritten, but not really why it's being overwritten in the send-to and not in the trigger on entry of the server atom. I tried to orientate myself on the pre-defined send-to logic for the icon number:
if(icon(rank(1,c)) = 1, 1, 2) and understood everything except why the rank(1,c) statemant is implemented. I guess in case the server is processing more than one atom (product) at a time, so the if-statement is always refering to the atom (product) waiting at the first position in the atom on which the logic is defined? Or is this the only possibility to refer to "c"?

2. I already try to get as much info from the help function and also the 4DS-Tutorial (even if it might not be looking like that :D ) and I think I also understood the basic differences between the atom references "i" and "c" but could not really evaluate why it's not adaptable to the send-to when I'm looking at the involed atom which is leaving the current atom "c" and should be sent.


3. Honestly there still might be some questionmarks in my brain and I could use a further hint for a applicable function. Or is there an option in seperating the continuous if-statements from each other in order that the code is not returning a zero?

Thanks again for your time!


best regards

Max
I think I could answer the question respectively my request of point 3. myself.. :D

Nevertheless I would still be interested in point 1. and 2..

Thanks again!
Attachments
Case(WhichIsTrue()) function for send-to.JPG
Case(WhichIsTrue()) function for send-to.JPG (24.25 KiB) Viewed 10329 times
User avatar
Gabe-Hein Dijkstra
Posts: 16
Joined: Friday 13 May, 2022 - 10:16

Re: Help needed in basic 4DS Programming

Post by Gabe-Hein Dijkstra »

Hi Max,

It is always nice to help, so no worries. :D

As mentioned before, "i" cannot be used on the SendTo. Why this is the case has a quite technical answer, but I will try my best to keep it simple.

In Enterprise Dynamics everything revolves around events and event handlers. Event handlers include: OnEntering, OnExiting, OnCreating, OnClick etc. Events always have a current atom "c". This is the atom that is currently executing an event handler. In addition, some event handlers have an involved atom "i". For example, with OnEntering there is an atom being entered (atom "c") and an atom entering (atom "i").

The code that is on the SendTo is not triggered by an atom "i", but only by atom "c". For example, with a server atom, the SendTo is triggered by the server (atom "c") signaling that it is has finished its cycletime. There is no involved atom ("i") in this case.

As a substitute for "i" you can, for example, use "Rank(1, c)" or "First(c)". As you already mention this is a reference to the product waiting at the first position of the server. In case of a server with capacity one, this always refers to the atom that needs to be sent away.

Hopefully this helps!

Best regards,
Gabe-Hein
Post Reply