Dead Source

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Immo
Posts: 4
Joined: Thursday 27 November, 2014 - 16:00

Dead Source

Post by Immo »

I added a SOURCE, a CONVEYOR and a SINK to a new model.
After that I declared a global variable in the init-statement of the SOURCE as follows: Dim([rr],vbvalue,2).
Furthermore I added to the (on)reset-statement rr:=2

After this change the source doesn't produce products anymore. Everything seems to be blocked. Even a new model containing these three elements but without the declaration of a variable is blocked.

What do I do wrong?

Background:
I wanted to use variable rr as an index to address the lines in an Excel sheet. After resetting of the model rr has again set to 1.
Attachments
dead_source1.mod
(7.01 KiB) Downloaded 322 times
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Dead Source

Post by HarryBunnik »

Hello Immo,

The problem you have is caused by the code you've placed on the Reset of your source.

Code: Select all

rr:=2
By placing this code there, you've overruled the original code from the source that is now skipped. And as a result, the entire source is no longer working.

If you try the following code on the OnReset it will work again. The code "Inherit" makes sure that first the original code is executed and only after that your own code.

Code: Select all

Do(
  Inherit,
  rr:=2
)
Another solution might be to use an "Initialize" atom where you can reset values like these again. This ensures that you have all your values that need to be reset at one place in your model.

I hope this helps,

Cheers,

Harry
User avatar
Nienke Valkhoff
Posts: 20
Joined: Tuesday 11 January, 2011 - 09:23

Re: Dead Source

Post by Nienke Valkhoff »

Hi Immo,

If you need to write data for each product to a new row in your sheet then you might not even need your own global variable. You can just use

Code: Select all

Input(c)
when you write code from an Entry trigger or

Code: Select all

Output(c)
when you write your code on an exit trigger to address a new row in the sheet. These 4DScript words return the current number of products that have entered or exited the current atom.


Another option to easily write data to Excel is to use the Data Recorder atom. You can place this atom in the product flow. Each time a product passes and it fulfills a condition data is written to its table or to an Excel sheet. You only have to define the variables that need to be written and setup the connection with the Excel sheet. The atom will make sure that each new entry is written to a next row in your sheet.

Regards,

Nienke
Post Reply