Writing the code

3 posts / 0 new
Last post
Paxo Parrot
Writing the code

Do I just write the code for one lap, and the computer then repeats that code over and over until it receives a stop command, or do I have to write the script for each of the 23 laps separately?

Geoff Riley
Geoff Riley's picture
It's your choice: I have been

It's your choice: I have been working on writing a couple of different methods to use on different laps. If you do the same thing on every lap, and the method that you have chosen has problems on the day, then you're going to have problems on every single lap. On the other hand if you select two different methods, but find that one has problems and the other doesn't, then you're only going to have problems on half the laps.

I've been trying out a few variations on a theme and will put in a number depending upon how well I find they do after I finish testing on the simulator.

I must get the image uploaded before the next test runs; I just couldn't get sorted out for the first tests. :(

Hope that helps.

Geoff

piborg
piborg's picture
Race code

As Geoff says, it is completely up to you :)

The basic example Race.py looks like this:

### Enable logging ###
StartDetailedLoging()
StartUserLog()

### Wait for the lights ###
WaitForGo()

### Racing for 23 laps ###
while LapCount() < 23:
	# Wait until we reach the first corner
	WaitForWaypoint(2)
	# Wait until we reach the start / finish line
	WaitForWaypoint(1)

### Wait for a few seconds ###
WaitForSeconds(4)

### Disable logging ###
EndDetailedLog()
EndUserLog()

### End of the race ###
FinishRace()

Anything between the while LapCount() < 23: line and before the WaitForWaypoint(1) line will be run once per lap.

For example:

while LapCount() < 23:
	print 'I have done ' + LapCount() + ' laps'
	# Wait until we reach the first corner
	WaitForWaypoint(2)
	# Wait until we reach the start / finish line
	WaitForWaypoint(1)

will print the number of laps completed at the start of each new lap.

Alternatively you can replace the while loop entirely.
You can use WaitForWaypoint(1) to wait until the next lap, for example:

print 'Lap 1'
WaitForWaypoint(1) # Start line at the end of lap 1
print 'Lap 2''
WaitForWaypoint(1) # Start line at the end of lap 2
print 'Lap 3'
WaitForWaypoint(1) # Start line at the end of lap 3
print 'Lap 4'
WaitForWaypoint(1) # Start line at the end of lap 4

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Syntax highlight code surrounded by the <pre class="brush: lang">...</pre> tags, where lang is one of the following language brushes: bash, cpp, perl, python.
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Comment Images
Files must be less than 10 MB.
Allowed file types: png gif jpg jpeg.
Comment Attachments
Files must be less than 10 MB.
Allowed file types: txt pdf nfo doc docx rtf jpg png gif bmp zip tar gz csv xls.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.