Skip to content

Commit dae4905

Browse files
committed
updated api ref with @CarlRoberts changes
1 parent f008da8 commit dae4905

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

docs/API-Reference.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,61 +3588,65 @@ If you want to place a torch so it faces _away_ from the drone:
35883588

35893589
### Drone.times() Method
35903590

3591-
The times() method makes building multiple copies of buildings
3591+
The `times()` method makes building multiple copies of buildings
35923592
easy. It's possible to create rows or grids of buildings without
35933593
resorting to `for` or `while` loops.
35943594

35953595
#### Parameters
35963596

35973597
* numTimes : The number of times you want to repeat the preceding statements.
35983598

3599+
#### Limitation
3600+
3601+
For now, don't use `times()` inside a Drone method implementation – only use it at the in-game prompt as a short-hand workaround for loops.
3602+
35993603
#### Example
36003604

3601-
Say you want to do the same thing over and over. You have a couple of options...
3605+
Say you want to do the same thing over and over. You have a couple of options:
36023606

3603-
* You can use a for loop...
3607+
* You can use a `for` loop …
36043608

3605-
d = new Drone(); for ( var i =0;i < 4; i++) { d.cottage().right(8); }
3609+
d = new Drone(); for ( var i = 0; i < 4; i++ ) { d.cottage().right(8); }
36063610

36073611
While this will fit on the in-game prompt, it's awkward. You need to
3608-
declare a new Drone object first, then write a for loop to create the
3609-
4 cottages. It's also error prone, even the `for` loop is too much
3612+
declare a new Drone object first, then write a `for` loop to create the
3613+
4 cottages. It's also error prone &ndash; even the `for` loop is too much
36103614
syntax for what should really be simple.
36113615

3612-
* You can use a while loop...
3616+
* You can use a `while` loop &hellip;
36133617

3614-
d = new Drone(); var i=4; while (i--) { d.cottage().right(8); }
3618+
d = new Drone(); var i=4; while (i--) { d.cottage().right(8); }
36153619

3616-
... which is slightly shorter but still too much syntax. Each of the
3620+
&hellip; which is slightly shorter but still too much syntax. Each of the
36173621
above statements is fine for creating a 1-dimensional array of
36183622
structures. But what if you want to create a 2-dimensional or
36193623
3-dimensional array of structures? Enter the `times()` method.
36203624

36213625
The `times()` method lets you repeat commands in a chain any number of
36223626
times. So to create 4 cottages in a row you would use the following
3623-
statement...
3627+
statement:
36243628

36253629
cottage().right(8).times(4);
36263630

3627-
...which will build a cottage, then move right 8 blocks, then do it
3631+
&hellip; which will build a cottage, then move right 8 blocks, then do it
36283632
again 4 times over so that at the end you will have 4 cottages in a
3629-
row. What's more the `times()` method can be called more than once in
3633+
row. What's more, the `times()` method can be called more than once in
36303634
a chain. So if you wanted to create a *grid* of 20 houses ( 4 x 5 ),
3631-
you would do so using the following statement...
3635+
you would do so using the following statement:
36323636

36333637
cottage().right(8).times(4).fwd(8).left(32).times(5);
36343638

3635-
... breaking it down...
3639+
&hellip; breaking it down &hellip;
36363640

36373641
1. The first 3 calls in the chain ( `cottage()`, `right(8)`, `times(4)` ) build a single row of 4 cottages.
36383642

3639-
2. The last 3 calls in the chain ( `fwd(8)`, `left(32)`, `times(5)` ) move the drone forward 8 then left 32 blocks (4 x 8) to return to the original x coordinate, then everything in the chain is repeated again 5 times so that in the end, we have a grid of 20 cottages, 4 x 5. Normally this would require a nested loop but the `times()` method does away with the need for loops when repeating builds.
3643+
2. The last 3 calls in the chain ( `fwd(8)`, `left(32)`, `times(5)` ) move the drone forward 8 then left 32 blocks (4 x 8) to return to the original X coordinate, then everything in the chain is repeated again 5 times so that in the end, we have a grid of 20 cottages, 4 x 5. Normally this would require a nested loop but the `times()` method does away with the need for loops when repeating builds.
36403644

3641-
Another example: This statement creates a row of trees 2 by 3 ...
3645+
Another example: This statement creates a row of trees 2 by 3:
36423646

36433647
oak().right(10).times(2).left(20).fwd(10).times(3)
36443648

3645-
... You can see the results below.
3649+
&hellip; You can see the results below.
36463650

36473651
![times example 1](img/times-trees.png)
36483652

0 commit comments

Comments
 (0)