Question

I am making a program in squeak smalltalk and while making it I realized that I didn't know how to use these pieces of code using an array for the x, y values:

pen:= Pen new.         "to create the pen object first"   
pen place: 200@200
pen down
pen goto: 100@100

Ok now to the point, I have an Array with 2 values one for the pen X and one for the pen Y positions now I write:

pen place: (myArray at:1) @ (myArray at:2)

But it didn't like the @ so I thought that it was because I needed:

pen place: ((myArray at:1)asInteger) @ ((myArray at:2)asInteger)

Also, it didn't like the "asInteger", so I replaced "asInteger" with "asSymbol" which it was positive that was not right and as I thought it didn't work either. The same thing happened when I tried:

pen goto:

My question is, how would you use the positions of myArray to make use of "place:" or "goto:"?

Was it helpful?

Solution

I tried this out in a workspace and it seemed to work ok:

pen := Pen new.
pen place: 200@200.
pen down.
pen goto: 100@100.
xArray := Array with:300 with: 350 with: 425.
yArray := Array with: 500 with: 450 with: 375.
1 to: 3 do: [ :index | pen goto: (xArray at: index)@(yArray at: index)].

Does the above code work for you?

CHEERS!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top