This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-09-17 08:34:38

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Can anyone fix my submorph headache?

OK, I know that a submorph can use its owner's methods by using:

Code:

(self ownerThatIsA: Morph) #method

But now I need a morph to access a submorph's methods, and I don't know how to do that.  Can anyone please help?

Offline

 

#2 2011-09-17 10:12:18

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Can anyone fix my submorph headache?

Code:

(morph findA: Submorph) #method

This will find the first submorph of morph (in its submorphs list) that is of type Submorph, if it exists.
Be sure to test if the result of findA: isn't nil, otherwise you'll have an error.

Offline

 

#3 2011-09-17 10:16:31

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Can anyone fix my submorph headache?

Baderous wrote:

Code:

(morph findA: Submorph) #method

This will find the first submorph of morph (in its submorphs list) that is of type Submorph, if it exists.
Be sure to test if the result of findA: isn't nil, otherwise you'll have an error.

Does that apply to ownerThatIsA: too?  Because I've used that before without checking for nil and it worked fine...

Offline

 

#4 2011-09-17 10:34:55

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Can anyone fix my submorph headache?

Read it in the method's comment:

ownerThatIsA: aClass
    "Answer this the first morph in the owner chain of the given class, or nil if there isn't one."

Offline

 

#5 2011-09-17 10:42:04

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Can anyone fix my submorph headache?

Baderous wrote:

Read it in the method's comment:

ownerThatIsA: aClass
    "Answer this the first morph in the owner chain of the given class, or nil if there isn't one."

Yeah, this is starting to give me an idea to fix one of my blocks...   smile   I'll test the fix as soon as I can, and make the blocks I need this method for.  Thanks once again, Baderous!   big_smile

Offline

 

Board footer