Is there any way to emulate a FOR..NEXT loop ?

I'm working on a space sector generator based on the rules from Stars Without Number. The process I'm trying to follow is to roll for each hex on the map and generate a star system. In other programming languages I'd use nested FOR..NEXT loops, one to count the columns across and one to count each hex in a column. Something like...

FOR X = 1 TO 8
  FOR Y = 1 TO 10
    (check for system at hex X,Y and generate if needed)
  NEXT Y
NEXT X

I have the following which works as far as it goes, but what I really need is a way to reference the column and row number, X and Y in the example above, so I can pass them to the StarSystem table to display it as the system's co-ordinates. Is there any way to do this within IPP? I was hoping the {rep} built-in variable might work, but that only seems to work for the top-level table, not any sub-table calls.

Prompt: Sector Width (1-99) {} 8
Prompt: Sector Length (1-99) {} 10
Set: pBreak=<br>- - - - - - - - - - - - - - - - - - - - <br>
Set: sBreak=<br>--------------------------------------------------------------------------------<br>
Set: cBreak=<br>oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo<br>

Table: NewSector
MaxReps: 1
[@{{$prompt1}} Columns >> implode {cBreak}]

Table: Columns
[@{{$prompt2}} IsThereASystem >> implode {sBreak}]

Table: IsThereASystem
Type: Weighted
2: [@StarSystem]
4: Empty 

Table: StarSystem
etc...

Comments

  • Try something like:

    MaxReps: 1
    Set: x=0
    Set: y=0
    Set: SizeX=50
    Set: SizeY=50
    
    table: go
    [@{SizeX} x]\n
    
    table: x
    {x==x+1}{y==0}[@{SizeY} y]
    
    table: y
    {y==y+1}xy is {$x}, {$y}\n
    

Leave a Comment