Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+10 votes
to move-planets
  ask planets [
    facexyz random-xcor random-ycor random-zcor
    fd 2]

currently this is my code I have, so I want my turtles to move different directions, but once they are set facing a certain way I only want them to move that way but not sure how to do this.

asked in CSC 150 January201920 by (8 points)
+1

Good question!

4 Answers

+6 votes

I would create a global variable called something like "orient-planets" and set it to be 0 in your setup method.

globals [ orient-planet ]

to setup
let orient-planets 0
end

Then in this part of your code you can make an if statement to check if this number is 0.

if orient-planets = 0 [ ]

Inside of the brackets you would then just have to set orient-planets to be a number other than 0, and they will only change their direction one time.

to move-planets

ask planets [

if orient-planets = 0 [
      facexyz random-xcor random-ycor random-zcor
      set orient-planets 1
     ]
fd 2
]
answered by (918 points)
+2

Thanks !

+5 votes

Using if statements would work in this case!

answered by (8 points)
+5 votes

I think you should categorize them somehow with if statements as kashav said and set different directions for each.

answered by (8 points)
+1 vote

I think you should add set heading

answered by (8 points)
...