1

I am having trouble with this snippet of code:

    set rect(1) [list 0 0 $x1 $y1]
    set rect(2) [list $x1 0 $x2 $y1]
    set rect(3) [list $x2 0 $x3 $y1]
    set rect(4) [list 0 $y1 $x1 $y2]
    set rect(5) [list $x1 $y1 $x2 $y2]
    set rect(6) [list $x2 $y1 $x3 $y2]
    set rect(7) [list 0 $y2 $x1 $y3]
    set rect(8) [list $x1 $y2 $x2 $y3]
    set rect(9) [list $x2 $y2 $x3 $y3]

    #iterate thru squares, x for 1, o for 2
    for {set i 1} {$i < 10} {incr i} {
        if {$squares(s$i) == 1} {
            drawX $rect($i) #This part is troubling
        } elseif {$squares(s$i) == 2} {
            .whole.board create oval $rect($i)
        }
    }

proc drawX {x1 y1 x2 y2} {
    .whole.board create line $x1 $y1 $x2 $y2 -width 3 -fill red
    .whole.board create line $x2 $y1 $x1 $y2 -width 3 -fill red
}

Basically, I am getting the error wrong # args: should be "drawX x1 y1 x2 y2. I don't understand whether my function arguments are incorrect or if I am passing the parameter in incorrectly.

2
  • Is this a different question from stackoverflow.com/questions/29887255/… -- I really can't tell Commented Apr 27, 2015 at 10:17
  • Yes. In that question, I am asking about the nature of several variables I found in someone else's code. In this one, I am passing parameters in incorrectly. Commented Apr 27, 2015 at 22:19

1 Answer 1

2

You do not use the correct number of arguments.

drawX $rect($i)

This is a function call with just one argument. If you want to expand those arguments, you need to use the expand operator on it (8.5+).

drawX {*}$rect($i)

In older versions that can be done with some eval magic.

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

2 Comments

So would I be passing in a list as one parameter if there wasn't an expansion operator?
@Renren29 Yes, exactly that. However, the $canvas create line operation (and all the other item constructors) can take the coordinates as a single list too; having them separate is forced by your procedure. Which might be a sensible thing, to be honest…

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.