Hello,
Im on this page now: http://squeak.preeminent.org/tut2007/html/017.html I do not understand one thing. Where do I put the initialize "script" When I put it on the initializeActiveSegments then initialize get not found. Or must I make a seperate protocol named ActiveSegments for it. If I made a initialize on the initiialize protocol. ActiveSegments stays nill. Roelof |
Hi Roelof 2014-04-01 14:52 GMT+02:00 Roelof Wobben <[hidden email]>: Hello, What do you mean with "script", the method?
The protocols are only used for grouping/organizing methods, it does not make a difference on how the methods are found or executed. In that tutorial, both methods are in the protocol initialize-release. If I made a initialize on the initiialize protocol. ActiveSegments stays nill. the initialize method is called "automatically" for every Object/Cell when it is created with "new" "Cell new" -> creates a new Cell and calls initialize. |
In reply to this post by Roelof
On 1 avr. 2014, at 14:52, Roelof Wobben <[hidden email]> wrote: > Hello, Hello, > Im on this page now: http://squeak.preeminent.org/tut2007/html/017.html > > I do not understand one thing. > > Where do I put the initialize "script" #initialize is not a script, it's a method. When an object is instantiated (for ex with: MyObject new) #initialize is automatically sent to it. This is the place to put your newly created object in a correct initial state. In your class, you just define a protocol named for example "initialization" where you put all the initialization-related methods. Note that protocols have no meaning, i.e. they don't change how your objects behave, they're just here to help you classify the methods of a class by concerns. So the tutorial tell you to create two methods: #initialize that is automatically called after an object has been instantiated and #initializeActiveSegments where you put some other initialization logic, that's all. > When I put it on the initializeActiveSegments then initialize get not found. Sorry, I don't understand. > Or must I make a seperate protocol named ActiveSegments for it. No use the same protocol "initialization" or "initialize-release" or whatever. > If I made a initialize on the initiialize protocol. ActiveSegments stays nill. > > Roelof > > |
Camille Teruel schreef op 1-4-2014 15:08:
> On 1 avr. 2014, at 14:52, Roelof Wobben <[hidden email]> wrote: > >> Hello, > Hello, > >> Im on this page now: http://squeak.preeminent.org/tut2007/html/017.html >> >> I do not understand one thing. >> >> Where do I put the initialize "script" > #initialize is not a script, it's a method. When an object is instantiated (for ex with: MyObject new) #initialize is automatically sent to it. > This is the place to put your newly created object in a correct initial state. > In your class, you just define a protocol named for example "initialization" where you put all the initialization-related methods. > Note that protocols have no meaning, i.e. they don't change how your objects behave, they're just here to help you classify > the methods of a class by concerns. > So the tutorial tell you to create two methods: #initialize that is automatically called after an object has been instantiated and #initializeActiveSegments where you > put some other initialization logic, that's all. > >> When I put it on the initializeActiveSegments then initialize get not found. > Sorry, I don't understand. > >> Or must I make a seperate protocol named ActiveSegments for it. > No use the same protocol "initialization" or "initialize-release" or whatever. > Oke, I changed it so I have this : Laser-Game-Model with as classes: - BlankCell - Grid - MirrorCell -TargetCell BlankCell has the following protocols: - initializing-release - testing Initializing - release contains the following methods: - initialize - initializeActiveSegments testing contains the following methods: isOn isOff but when I run the test-runner I see this : MessageNotUnderstood : BlankCell >> activeSegments. Roelof |
On 1 avr. 2014, at 16:21, Roelof Wobben <[hidden email]> wrote:
This error means "instances of BlankCell does not understand the message #activeSegments" that's all, this part of your program is not implemented yet.
|
Camille Teruel schreef op 1-4-2014
16:34:
Im not agree with you according to the tutorial on this page : http://squeak.preeminent.org/tut2007/html/019.html there is a error with isOn and isOff. #activeSegments schould be implemented by now. Roelof |
In reply to this post by Roelof
2014-04-01 16:21 GMT+02:00 Roelof Wobben <[hidden email]>: Camille Teruel schreef op 1-4-2014 15:08: Then you missed the last step on http://squeak.preeminent.org/tut2007/html/016.html Select "create instance var accessors" from the second popup menu. |
Nicolai Hess schreef op 1-4-2014 16:44:
I also did. See this : Object subclass: #BlankCell instanceVariableNames: 'activeSegments' classVariableNames: '' category: 'Laser-Game-Model' Roelof |
In reply to this post by Roelof
On 1 avr. 2014, at 16:39, Roelof Wobben <[hidden email]> wrote:
There is no way to be agree or not with that, MessageNotUnderstood is an error thrown when a message is ..., well, ... not understood. So no method named activeSegments is defined in BlankCell hierarchy, it's as simple as that.
|
In reply to this post by Roelof
Roelof Wobben wrote:
> Camille Teruel schreef op 1-4-2014 15:08: >> On 1 avr. 2014, at 14:52, Roelof Wobben <[hidden email]> wrote: >> >>> Hello, >> Hello, >> >>> Im on this page now: http://squeak.preeminent.org/tut2007/html/017.html >>> >>> I do not understand one thing. >>> >>> Where do I put the initialize "script" >> #initialize is not a script, it's a method. When an object is >> instantiated (for ex with: MyObject new) #initialize is automatically >> sent to it. >> This is the place to put your newly created object in a correct >> initial state. >> In your class, you just define a protocol named for example >> "initialization" where you put all the initialization-related methods. >> Note that protocols have no meaning, i.e. they don't change how your >> objects behave, they're just here to help you classify >> the methods of a class by concerns. >> So the tutorial tell you to create two methods: #initialize that is >> automatically called after an object has been instantiated and >> #initializeActiveSegments where you >> put some other initialization logic, that's all. >> >>> When I put it on the initializeActiveSegments then initialize get >>> not found. >> Sorry, I don't understand. >> >>> Or must I make a seperate protocol named ActiveSegments for it. >> No use the same protocol "initialization" or "initialize-release" or >> whatever. >> > > Oke, > > I changed it so I have this : > > Laser-Game-Model > with as classes: > - BlankCell > - Grid > - MirrorCell > -TargetCell > > > BlankCell has the following protocols: > - initializing-release > - testing > > Initializing - release contains the following methods: > - initialize > - initializeActiveSegments > > testing contains the following methods: > isOn > isOff > > but when I run the test-runner I see this : MessageNotUnderstood : > BlankCell >> activeSegments. > > Roelof when I went through this tutorial when I was quite new to Smalltalk, which is paying attention to whether you are defining methods on the instance-side or the class-side, as indicated by which of the <instance> or <class> button is highlighted. Now for BlankCell, if you select protocol --all-- do you see a method #activeSegments ? The lack of that method is the cause of the MessageNotUnderstood. Looking at the previous page it says "Add an instance variable "activeSegments" and "We will use Squeak's built-in tools to create accessors for this new instance variable" I would say something went wrong there. Consider the last snapshot of page 16. cheers -ben |
In reply to this post by Roelof
On 1 avr. 2014, at 16:50, Roelof Wobben <[hidden email]> wrote:
This message just serve as a class definition, it basically says "I want a class named BlankCell, subclass of Object, with one instance variable named activeSegments, in the category Laser-Game-Model". But, it says nothing about BlankCell methods. So as Nicolai pointed out, you forgot to do the last step of page 16. It will create two methods for accessing the instance variable activeSegments: First an accessor method: BlankCell>>activeSegments ^ activeSegments And a mutator (you should rename the argument to better convey the intent) BlankCell>>activeSegments: anObject activeSegments := anObject
|
In reply to this post by Roelof
Roelof Wobben wrote:
This only creates the instance variable. I'm not clear whether are saying you performed the step shown in the second last snapshot on page 16 or not - but the evidence of the MNU would seem it didn't happen. Now I'm going to extrapolate a lot a check whether you are thinking of 'activeSegments' in #initializeActiveSegments as a reference to the instance variable. However it is not a reference to the variable (even if the name is the same) but actually a send of the #activeSegments message to 'self'. Doing it like this rather than accessing the variable directly has the advantage of focusing access to the variable through a single point, which helps observability of variable access. Also, in a "live" environment like Smalltalk, when you have instances of class X in a running system, and you add an instance variable to X, all existing classes contain 'nil' for that added variable and _everywhere_ you directly access that variable in your code would need to be wrapped in a conditional.message like #ifNil: cheers -ben |
In reply to this post by camille teruel
Camille Teruel wrote:
>And a mutator (you should rename the argument to better convey the intent) In general maybe, but not for the tutorial. cheers -ben |
Ben Coman schreef op 1-4-2014 17:13:
Camille Teruel wrote: Oke, I see what went wrong. I did try to make this work on Pharo and appereantly it worked otherwise. I will download squezee 3.9 and try again. Roelof |
Hello, Roelof!
Stef is partly right. I had implemented Laser Game but on Squeak, not Pharo. If you have any questions, ask me and I will try to help you.
Mark |
Mark Rizun schreef op 1-4-2014 18:12:
> Hello, Roelof! > > Stef is partly right. I had implemented Laser Game but on Squeak, not > Pharo. > If you have any questions, ask me and I will try to help you. > > Mark First question : I had a working test. I saved it to my hard disk. Closed Pharo . re open it and the test is failing. Roelof |
Roelof Wobben wrote:
> Mark Rizun schreef op 1-4-2014 18:12: >> Hello, Roelof! >> >> Stef is partly right. I had implemented Laser Game but on Squeak, not >> Pharo. >> If you have any questions, ask me and I will try to help you. >> >> Mark > > First question : > > I had a working test. I saved it to my hard disk. > Closed Pharo . re open it and the test is failing. > > Roelof > > > I've never observed that happening. You would need to present more specific context for your problem. * What is the error * What is the method source and line that it is failing on * What are the values of the instance variables This is generally described in the following article. http://www.catb.org/esr/faqs/smart-questions.html cheers -ben |
Free forum by Nabble | Edit this page |