Jump to content

Looping Programs


Recommended Posts

Hey, I recently created a simple program that basically shunts a loco backwards and forwards and changes points. so basically, the Loco shunts back, onto another track, back and forth a bit, then back to the original track and starting point.

 

I'd

 

like to know, if there is a option to loop a program so it will keep playing, over and over, until i manually stop it. and how to set up, or anything similar?

 

any help appreciated

Link to comment
Share on other sites

@Rikugun_Taii

There is a repeat command that you put at the start of a section of your program that you want to repeat and then an end repeat at the end.

You have to put in a number but I guess you could put in a big number.

Link to comment
Share on other sites

In the middle of December, I reported to Hornby a fault I discovered with the Repeat command, and I am still waiting for a resolution. The problem is that if you have, say, four commands between the Repeat command and the End Repeat command, the first

 

of these four is only actioned during the first pass. When the End Repeat is actioned, control goes to the second command after the Repeat command, not the first.

Ray

Link to comment
Share on other sites

@St1ngr4y

I use a program that contains the repeat command regularly and I have been very pleased with it.

I have just run it now to ensure it executes all commands and it does but my first line after the repeat is just a command to move a loco in

 

a siding up to a buffer, so that I know it is always starting from the same position.

Is it possible that the last program line before the END REPEAT command is too close, time wise to the END REPEAT line and therefore control has not been passed back to

 

your controller by the time the REPEAT is due to start.

Suggestion: Try adding a few seconds to the position of the END REPEAT command.

 

I hope this makes sense. I know what I mean!

 

Link to comment
Share on other sites

RDS said:

@St1ngr4y
I use a program that contains the repeat command regularly and I have been very pleased with it.
I have just run it now to ensure it executes all commands and it does but my first line after the repeat is just a

command to move a loco in a siding up to a buffer, so that I know it is always starting from the same position.
Is it possible that the last program line before the END REPEAT command is too close, time wise to the END REPEAT line and therefore control

has not been passed back to your controller by the time the REPEAT is due to start.
Suggestion: Try adding a few seconds to the position of the END REPEAT command.

I hope this makes sense. I know what I mean!


Hi RDS,
This is

the example program I sent to Hornby:-
0 Program Command Repeat [9] times
2 Program Command Play Sound "One"
4 Program Command Play Sound "Two"
6 Program Command Play Sound "Three"
8 Program Command Play Sound "Four"
10 Program Command End

Repeat

Of course, I used the full hierarchic filename for the sound files and when run, the sounds played are:-

One Two Three Four Two Three Four Two Three Four Two Three Four Two Three Four etc

If you have time, would you mind trying

this to see if you get the same result?
Many thanks
Ray
Link to comment
Share on other sites

@St1ngr4y

Yes of course I will try that for you but in the meantime, I think the reason it fails is for the reason I tried to explain in my post last night.

I am assuming that the first digits represent the seconds.

 

Try replacing 10 with 15.

 

 

Link to comment
Share on other sites

@St1ngr4y

I will look at this again tomorrow but I have done some initial checks and I can repeat your second line skipping problem.

I have been using the sounds from the RailMaster program but I will do it again next time with the clock chiming

 

sounds because it will be easier to see which are being used or missed.

I did try with the birds singing sound and I found if I put that near the end, timing wise, it just continues after the program has finished, although I don't know how long it is meant

 

to play for without using it on it's own.

 

Link to comment
Share on other sites

RDS said:

I have been using the sounds from the RailMaster program but I will do it again next time with the clock chiming sounds because it will be easier to see which are being used or missed.

Did you not use the sounds in

my example program ?
e.g.
C:Program Files (x86)RailmasterSoundsEnglishF_L_One.wav
C:Program Files (x86)RailmasterSoundsEnglishF_L_Two.wav
C:Program Files (x86)RailmasterSoundsEnglishF_L_Three.wav
C:Program Files (x86)RailmasterSoundsEnglishF_L_Four.wav

Ray
Link to comment
Share on other sites

St1ngr4y said:

Did you not use the sounds in my example program ?


Hi Ray
It was not clear in your original program which sounds had to be used.
The result is the same though, whichever sounds are used.

I have

now re-edited the program to use the clock chiming sounds and if the first program command after the repeat (n) times command, is a sound command, it misses repeating the first one every time.

However, I then added a command to switch the lights on

for one of my loco's as the first line after the repeat (n) times and another command just after the end repeat, to switch the lights off again and all repeats (lights and all sounds) work perfectly.
Conclusion: If the first command within the repeat section,

is a sound command, it misses the first repeat but make that first line anything else and the repeat works perfectly. Strange!
Link to comment
Share on other sites

RDS said:

St1ngr4y said:

Did you not use the sounds in my example program ?


Hi Ray
It was not clear in your original program which sounds had to be used.
The result is the same though, whichever sounds are used.

I

have now re-edited the program to use the clock chiming sounds and if the first program command after the repeat (n) times command, is a sound command, it misses repeating the first one every time.

However, I then added a command to switch the lights

on for one of my loco's as the first line after the repeat (n) times and another command just after the end repeat, to switch the lights off again and all repeats (lights and all sounds) work perfectly.
Conclusion: If the first command within the repeat

section, is a sound command, it misses the first repeat but make that first line anything else and the repeat works perfectly. Strange!


Hi RDS,
You are quite correct - it only happens when the first command after the repeat is a Play Sound.

But now I'm going to play Devil's Advocate!! You mention in another thread that you are having trouble with the Chain command. It occurred to me that all kinds of chaos might happen if you chained two programs which overlap in time and one of them contains

a Repeat loop. We are told by Hornby that the chain command operates by performing a runtime merge of the instructions contained in all of the chained programs, using the times in the individual programs. If care isn't taken with the scenario I describe, you

could end up with the Repeat loop 'inheriting' an instruction or two from the other program. Even if this doesn't happen, the repeat loop could interfere with the timings of the second program. Since the repeat loop operates by setting up a sort of ground-hog

period i.e. the time keeps jumping back to that at the start of the loop, the 'other' program would be in trouble if its running time spanned the repeat loop. Consider this;-
Program A
0 Loco 1 Forward to [50]
60 Loco 1 Stop

Program B
0

Repeat [3] times
2 Loco 2 Forward to [10]
12 Loco 2 Stop
20 Loco 2 Reverse to [10]
30 Loco 2 Stop
32 End Repeat

Program C
0 Chain Program A
10 Chain Program B

Program A expects Loco 1 to run for 60 seconds then stop. When

Program C is run the time will be reset from 42 to 12 three times effectively adding 90 seconds to the running time, and causing Loco 1 not to stop until 150 seconds instead of 60.

I gave up thinking of the consequences if both chained programs contained

a repeat loop !!!

Ray
Link to comment
Share on other sites

You should avoid the use of Repeat ... End Repeat loops within programs that you know you want to chain into a master program. This can cause undesired effects as a result of lines of code from one chained program being repeatedly executed within the Repeat

 

... End Repeat loop of another chained program that you had not intended.

 

Generally, avoid using Chain and Repeat ... End Repeat commands in programs you know will be chained into other programs.

 

The Chain command was designed to allow you to

 

create, what we call Programlets (simple programs for perhaps a single scenario on your layout) and then merge them together so that various scenarios all run at the same time.

 

The advantage of this is that you can have a lot of automated activity on

 

your layout without the headache of manipulating one large program. You can therefore decide to chop and change the Programlets as you wish, for example changing a loco, knowing that the master program chaining all of the Programlets will be unaffected.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
  • Create New...