Delay component when variable used and variable value is 0

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Delay component when variable used and variable value is 0

Post by Mark »

Hi,

I seem to have found a problem when a Delay component is used and when the delay is a variable and the variable value is 0. The Delay either lasts too long or an enless loop is created (I'm not sure which).

The quick fix is a check to make sure the variable is not zero, however, as the delay is a user input variable and no delay is a realistic option to choose it would make for cleaner coding if a variable holding a value of 0 could be used?

Or is there a likely bug in my code?

Thanks,

Mark
Go with the Flow.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello Mark

You could have the delay in a desicion branch and only call the delay if the variable is greater then 0

Eg

if var1 > 0

Yes delay for var1

No carry on with program.

I think if you pass a value of 0 it will instantly rollover and give the maximum possible delay eg. 65536 seconds or milliseconds.

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

If you are concerned about this, there is a permanent fix you can apply. The FCD files define how these delays work - have a look at the DelayCmdS and DelayCmdMs entries in the "Code" section.

At the moment these are as follows:

Code: Select all

DelayCmdS="delay_s(%o);\n"
DelayCmdMs="delay_ms(%o);\n"
Altering them to this would fix this issue:

Code: Select all

DelayCmdS="if (%o > 0) delay_s(%o);\n"
DelayCmdMs="if (%o > 0) delay_ms(%o);\n"
Do you think I should make this change in all FCD files in the next release?

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Post by Mark »

Steve,

Thanks for that.

I agree that a change in the next release will be a good move. Not only is the benefit of having a 'delay' of 0 greater than having 65536 (when 65535 is available) but the novice may be mystified by the concept of rollover and 65536.

regards,

Mark
Go with the Flow.

Post Reply