![]() Instead, just put the command outside the brackets create-turtles 10Īs a last tip: I see you are using n-of 1 a few times. You are creating 10 turtles and giving each one of them the command to change the color of 5 random turtles to white, so that command is carried out 10 times. The problem is in this piece of code: create-turtles 10 I noticed that the number of white and red turtles doesn't seem to be as intended. Then you set t3 to 0 within the color change procedure (I moved both that and the change to recently-changed? outside of the ifelse command blocks since it happens regardless of which option is chosen) ask n-of 1 turtles with Īnd then finally count up in the change-after procedure to change-afterĪnother problem I spotted with your code is in the setup procedure. Instead, you should make it a turtles variable turtles-own They are not meant to be used over multiple ticks. The problem is that local variables cease to exist as soon as the procedure they are in ends. In the change-after procedure, you are creating a local variable called t3 with the value 0 and increasing its value with 1. If you still want to use if statements, you can include the stop primitive to immediately exit the enclosing procedure once you have changed a color: ask n-of 1 turtles with [ I suggest you just stick with the ifelse here. The problem here is that the two if statements are completed after eachother so the initially white turtle that is changed to red will change back to white again. Then you check if it is red and ask it to become white. You check if it is white and if it is, you ask it to become red. In the scenario with the two if statements, you first pick out a turtle that has not recently been changed. Also now it can change color again and when it does it is once again marked as "recently changed" and the whole process repeats. color: use of() from NetLogoR to access turtles colors.
0 Comments
Leave a Reply. |