2

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:"?

happy coder
  • 1,517
  • 1
  • 14
  • 29
  • It seems that the problem is in the contents of the array. Can you inspect `myArray` and tell us what its contents are? – Andrés Fortier Feb 07 '13 at 15:05
  • Maybe you want to check out Athens project: http://rmod.lille.inria.fr/archives/events/2012PharoConf/Slides/2012-PharoConf-Athens.pdf – Uko Feb 07 '13 at 15:07
  • thank you both.@ Andres I inspected myArray and found that is was nil so I looked in to it and found the problem. @Uko I might try out athens some time – oriProgrammer Feb 07 '13 at 15:42
  • Style comment: use `myArray first` rather than `myArray at: 1`. Similarly an `Array` understands the `#second` message. – Frank Shearar Feb 08 '13 at 13:14
  • Thanks you. that makes it look cleaner! myArray is only 2 elements long so could I do [code]myArray last[/code] instead of [code] myArray second[/code]? – oriProgrammer Feb 09 '13 at 06:13

1 Answers1

2

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!

happy coder
  • 1,517
  • 1
  • 14
  • 29
  • This works! thanks. my problem was in a different method I had put a test that didn't need to be there and a I had a typo that made the Array to not set and there for it became nil. – oriProgrammer Feb 07 '13 at 15:38