Converting blocks to text

I created the program in blocks, it works well, but when I convert it to text, the program stops working.
The text that is obtained during conversion:

vexcode_brain_precision = 0
Shag = 0
ShagNext = 0
PosX = 0
PosN = 0
PosY = 0
Coordinat = [[0 for y in range(8)] for x in range(2)]

def when_started1():
global Shag, ShagNext, PosX, PosN, PosY, Coordinat, vexcode_brain_precision
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.set_turn_velocity(100, PERCENT)
Shag = 1
while True:
PosX = location.position(X, MM)
PosY = location.position(Y, MM)
Coordinat[Shag - 1][1 - 1] = PosX
Coordinat[Shag - 1][2 - 1] = PosY
brain.print(Coordinat[Shag - 1][1 - 1], precision=vexcode_brain_precision)
brain.print(“,”)
brain.print(Coordinat[Shag - 1][2 - 1], precision=vexcode_brain_precision)
brain.print(“,”)
brain.new_line()
if distance.get_distance(MM) > 260:
drivetrain.drive_for(FORWARD, 250, MM)
drivetrain.turn_for(RIGHT, 90, DEGREES)
else:
drivetrain.turn_for(LEFT, 90, DEGREES)
Shag = Shag + 1
wait(5, MSEC)
drivetrain.drive(FORWARD)

vr_thread(when_started1())

Error in line “Coordinat[Shag - 1][1 - 1] = PosX”
Option “Coordinat[Shag][0] = PosX” doesn’t help
Please tell me how to write correctly

Can you fix that to have proper indentation? It is impossible to tell whats going on

2 Likes

I gotcha:

vexcode_brain_precision = 0
Shag = 0
ShagNext = 0
PosX = 0
PosN = 0
PosY = 0
Coordinat = [[0 for y in range(8)] for x in range(2)]

def when_started1():
     global Shag, ShagNext, PosX, PosN, 
     PosY, Coordinat, 
     vexcode_brain_precision
     drivetrain.set_drive_velocity(100, 
     PERCENT)
     drivetrain.set_turn_velocity(100, 
     PERCENT)
     Shag = 1
     while True:
          PosX = location.position(X, MM)
          PosY = location.position(Y, MM)
          Coordinat[Shag - 1][1 - 1] = PosX
          Coordinat[Shag - 1][2 - 1] = PosY
          brain.print(Coordinat[Shag - 1][1 - 1], 
          precision=vexcode_brain_precision)
          brain.print(",")
          brain.print(Coordinat[Shag - 1][2 - 1], 
          precision=vexcode_brain_precision)
          brain.print(",")
          brain.new_line()
          if distance.get_distance(MM) > 260:
               drivetrain.drive_for(FORWARD, 250, MM)
               drivetrain.turn_for(RIGHT, 90, DEGREES)
          else:
               drivetrain.turn_for(LEFT, 90, DEGREES)
               Shag = Shag + 1
               wait(5, MSEC)
               drivetrain.drive(FORWARD)

vr_thread(when_started1())
1 Like

“Give a man a fish, he gets food for a day. Teach a man to fish, he gets food for the rest of his life”
@Naum When on forums, properly format code using
[code]
Your code here
[/code]

7 Likes

I’m sorry but I didn’t understand

Would you be able to post your block program? Save it to your device then attach to a forum post. Then we can follow the whole process through.

1 Like

I gotta a better one:

“Give a man a fish, you feed him for a day, don’t teach a man to fish and you feed yourself. He’s a grown man. Fishing’s not that hard.” - Ron Swanson

Sorry for the off-topic post.

2 Likes

Give a man a program, he’s frustrated for a day. Teach a man to program, [marked as duplicate]"

5 Likes

I think you meant this for @Naum

1 Like

not sure why the blocks project works, but this is backwards for the indexing you have.

Coordinat = [[0 for y in range(8)] for x in range(2)]

should be

Coordinat = [[0 for y in range(2)] for x in range(8)]
2 Likes

Thanks to all who responded. I’m newbie. The purpose of the program is to write the coordinates of the robot’s movement into the cells of the array Coordinat. I wanted to use a variable Shag to change the cells of the array. But it looks like the variable doesn’t change and everything is written to the first cell. Now the code looks like this

vexcode_brain_precision = 0
Shag = 0
ShagNext = 0
PosX = 0
PosN = 0
PosY = 0
Coordinat = [[0 for y in range(100)] for x in range(2)]

def when_started1():
    global Shag, ShagNext, PosX, PosN, PosY, Coordinat, vexcode_brain_precision
    drivetrain.set_drive_velocity(100, PERCENT)
    drivetrain.set_turn_velocity(100, PERCENT)
    
    while True:
          PosX = location.position(X, MM)
          PosY = location.position(Y, MM)
          
          if distance.get_distance(MM) > 250:
               drivetrain.drive_for(FORWARD, 250, MM)
               Coordinat[Shag][0] = PosX
               Coordinat[Shag][1] = PosY
               brain.print(Shag)
               brain.print(",")
               brain.print(Coordinat[Shag][0], precision=vexcode_brain_precision)
               brain.print(",")
               brain.print(Coordinat[Shag][1], precision=vexcode_brain_precision)
               brain.print(",")
               brain.new_line()
               drivetrain.turn_for(RIGHT, 90, DEGREES)
          else:
               drivetrain.turn_for(LEFT, 90, DEGREES)
                      
               drivetrain.drive(FORWARD)

vr_thread(when_started1())
1 Like