Answered by:
Small Basics Turtle Storage
Question

Hello,
I am doing a Learning Task that involves me making a Turtle Program run 3 or more routes around my school, I've done an 'If And Then' Statement and added a bookmark for later, and when I return to that bookmark, it does a loop from the bookmark to the Goto Statement and then goes back in a continuous loop.
Here is the current code.
'Opening the Western Port Secondary School grounds map'
GraphicsWindow.Show()
GraphicsWindow.Title = "Western Port Secondary College Map with Turtle"
GraphicsWindow.Width = 700
GraphicsWindow.Height = 500
image1 = "file:///C:/Users/CORY/Pictures/School%20Pictures/WPSC_Map.JPG"
GraphicsWindow.DrawResizedImage(image1, 0, 0, 660, 441)
'Setting a starting point for Turtle'
Turtle.Show()
Turtle.X = 152
Turtle.Y = 123
'Setting Variables for Turtle's start point for when he finishes a route'
'Also getting other variables ready for later on'
a = Turtle.X
b = Turtle.Y
'Getting Turtle started'
'The first route, my mostly used route to go to the STEM center'
GraphicsWindow.PenColor = "Lime"
Turtle.Speed = 10
Turtle.Turn(125.6)
Turtle.Move(113)
Turtle.Turn(35.6)
Turtle.Move(10)
Turtle.TurnRight()
Turtle.Move(5)
Turtle.TurnLeft()
Turtle.Move(3)
Turtle.Turn(60)
Turtle.Move(63)
Turtle.Angle = 180
Turtle.Move(5)
Turtle.TurnLeft()
Turtle.Move(60)
'Creating the variables for the end point for Turtle to move to'
FinalX = Turtle.X
FinalY = Turtle.Y
'This is the start of the final path for the end point, using Branching and conditions to store it for later'
i = 1
Finish:
If (Turtle.X = FinalX)And(Turtle.Y = FinalY) Then
Turtle.Angle = 153
Turtle.Move(68)
Turtle.Angle = 180
Turtle.Move(34)
Turtle.TurnLeft()
Turtle.Move(5)
Turtle.PenUp()
Turtle.Speed = 9
Turtle.MoveTo(a, b)
Turtle.Speed = 5
Turtle.Angle = 0
EndIf
'Beginning my second path'
Turtle.PenDown()
GraphicsWindow.PenColor = "DarkBlue"
Turtle.Turn(166)
Turtle.Move(93)
Turtle.Turn(40)
Turtle.Move(50)
Turtle.Turn(36)
Turtle.Move(73)
Turtle.TurnRight()
Turtle.Move(10)
Turtle.MoveTo(FinalX, FinalY)
Goto Finish
'This code was for test'
'Turtle.PenUp()
'Turtle.MoveTo(FinalX, FinalY)
'Turtle.MoveTo(a, b)
'Turtle.Speed = 10
'This code is to hide the turtle so I can see where the line ends'
Turtle.Hide()I'm currently trying to figure out how to do a For and a While statement.
Thank you

I'd like to know how to store a code for later use
'Creating the variables for the end point for Turtle to move to'
FinalX = Turtle.X
FinalY = Turtle.Y
'This is the start of the final path for the end point, using Branching and conditions to store it for later'
i = 1
Finish:
If (Turtle.X = FinalX)And(Turtle.Y = FinalY) Then
Turtle.Angle = 153
Turtle.Move(68)
Turtle.Angle = 180
Turtle.Move(34)
Turtle.TurnLeft()
Turtle.Move(5)
Turtle.PenUp()
Turtle.Speed = 9
Turtle.MoveTo(a, b)
Turtle.Speed = 5
Turtle.Angle = 0
EndIf
 Edited by Cory Ponyeim Wednesday, August 7, 2019 4:25 AM New question
Answers

Perhaps you want to put that bit if code in a subroutine that you can call one or more times?
 Marked as answer by Cory Ponyeim Thursday, August 8, 2019 1:25 AM
All replies



So I think the problem starts from the;
'Creating the variables for the end point for Turtle to move to'
FinalX = Turtle.X
FinalY = Turtle.YOr something like that...
I just want to this bit to be stored for later on;
'This is the start of the final path for the end point, using Branching and conditions to store it for later'
i = 1
Finish:
If (Turtle.X = FinalX)And(Turtle.Y = FinalY) Then
Turtle.Angle = 153
Turtle.Move(68)
Turtle.Angle = 180
Turtle.Move(34)
Turtle.TurnLeft()
Turtle.Move(5)
Turtle.PenUp()
Turtle.Speed = 9
Turtle.MoveTo(a, b)
Turtle.Speed = 5
Turtle.Angle = 0
EndIf 

Hi Cory, I modified your program to show four points A, B, C, D. Now your program goes A  B (green root)  C (red root), A  D (blue root)  B  C (red root), A  D (blue root)  B  C (red root) ...
While A = (a, b), B = (FinalX, FinalY), C = end of red root, D = last point to B of blue root.
Which root do you want to go?
'Opening the Western Port Secondary School grounds map' GraphicsWindow.Show() GraphicsWindow.Title = "Western Port Secondary College Map with Turtle" GraphicsWindow.Width = 700 GraphicsWindow.Height = 500 image1 = "file:///C:/Users/CORY/Pictures/School%20Pictures/WPSC_Map.JPG" GraphicsWindow.DrawResizedImage(image1, 0, 0, 660, 441) 'Setting a starting point for Turtle' Turtle.Show() Turtle.X = 152 Turtle.Y = 123 'Setting Variables for Turtle's start point for when he finishes a route' 'Also getting other variables ready for later on' a = Turtle.X b = Turtle.Y GraphicsWindow.BrushColor = "Black" GraphicsWindow.DrawText(a, b, "A") 'Getting Turtle started' 'The first route, my mostly used route to go to the STEM center' GraphicsWindow.PenColor = "Lime" Turtle.Speed = 10 Turtle.Turn(125.6) Turtle.Move(113) Turtle.Turn(35.6) Turtle.Move(10) Turtle.TurnRight() Turtle.Move(5) Turtle.TurnLeft() Turtle.Move(3) Turtle.Turn(60) Turtle.Move(63) Turtle.Angle = 180 Turtle.Move(5) Turtle.TurnLeft() Turtle.Move(60) 'Creating the variables for the end point for Turtle to move to' FinalX = Turtle.X FinalY = Turtle.Y GraphicsWindow.DrawText(FinalX, FinalY, "B") 'This is the start of the final path for the end point, using Branching and conditions to store it for later' i = 1 Finish: If (Turtle.X = FinalX)And(Turtle.Y = FinalY) Then GraphicsWindow.PenColor = "Red" Turtle.Angle = 153 Turtle.Move(68) Turtle.Angle = 180 Turtle.Move(34) Turtle.TurnLeft() Turtle.Move(5) Turtle.PenUp() Turtle.Speed = 9 GraphicsWindow.DrawText(Turtle.X, Turtle.Y, "C") Turtle.MoveTo(a, b) Turtle.Speed = 5 Turtle.Angle = 0 EndIf 'Beginning my second path' Turtle.PenDown() GraphicsWindow.PenColor = "DarkBlue" Turtle.Turn(166) Turtle.Move(93) Turtle.Turn(40) Turtle.Move(50) Turtle.Turn(36) Turtle.Move(73) Turtle.TurnRight() Turtle.Move(10) GraphicsWindow.DrawText(Turtle.X, Turtle.Y, "D") Turtle.MoveTo(FinalX, FinalY) Goto Finish 'This code was for test' 'Turtle.PenUp() 'Turtle.MoveTo(FinalX, FinalY) 'Turtle.MoveTo(a, b) 'Turtle.Speed = 10 'This code is to hide the turtle so I can see where the line ends' Turtle.Hide()
Nonki Takahashi
 Edited by Nonki TakahashiModerator Friday, August 2, 2019 12:50 PM while
 Proposed as answer by Ed Price  MSFTMicrosoft employee, Owner Monday, August 5, 2019 8:00 PM

Here's a teeny turtle exploring the world. We'll have to take care, that it stays on land, it's not a sea turtle.
 Proposed as answer by Ed Price  MSFTMicrosoft employee, Owner Monday, August 5, 2019 8:00 PM



Perhaps you want to put that bit if code in a subroutine that you can call one or more times?
 Marked as answer by Cory Ponyeim Thursday, August 8, 2019 1:25 AM
