2

I keep getting the error There is already a global variable called “DOTTED-LINE-VISIBLE” but when I change the name it gives me the same error but with the new name. How to fix it? The global variable is related to a switch named dotted-line-visible in the interface.

Here is the code I have so far:

; Define a global variable to control the visibility of the dotted line 
globals [dotted-line-visible]
; Drawing the yellow dotted line if the switch is on (part of setup function)
if dotted-line-visible [draw-vertical-dotted-line boundary]
; Procedure to draw a vertical yellow dotted line
to draw-vertical-dotted-line [boundary]
    create-turtles 1 [
        hide-turtle
        set color yellow
        set size 0.5
        setxy boundary min-pycor
        set heading 0
        while [ycor < max-pycor] [
            pen-down
            forward 0.5
            pen-up
            forward 0.5
        ]
    ]
end

I created a switch called “dotted-line-visible” that I'd like to use to toggle on and off this dotted line in the middle of my NetLogo screen.

1 Answer 1

3

When you create a switch or other widget on the Interface, NetLogo uses that to define a global variable with the same name. Therefore, when you define the variable as a global in your code, it is a redundant definition. Thus the error you are getting.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.