Say doesn't work during instance intialise method

Report bugs. Post bug workarounds or fixes

Moderator: MSandro

Post Reply
SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Say doesn't work during instance intialise method

Post by SimpleSi » Sep 4th, '17, 07:37

I was trying to use a say block for debugging an initialise method for an instance but it doesn't work

I understand that this could be that the instance isn't fully created until after the intialise method returns

if this is the way it has to be - OK - but any suggestions for a workaround? (apart from developer mode debugging)

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Say doesn't work during instance intialise method

Post by JohnM » Sep 11th, '17, 14:17

I understand that this could be that the instance isn't fully created until after the intialise method returns
Yep, that's exactly right. The initialize method get's run before the instance is added to the stage, so it can't do "say" and many other blocks that need the instance to be in the stage. You also can't start an "animate" (forever) loop in the instance method.

The solution to both of these things is to send a message to the newly created instance like this:
scriptImage4.png
scriptImage4.png (8.66 KiB) Viewed 3208 times
The newly created instance is sent the message "start" after it has been added to the stage. Any "when I receive 'start'" hat blocks are started, and they can do anything a normal instance can do, including using the "say" block, starting "animate" loops, etc.

This is the equivalent to the "when I start as a clone" mechanism.

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: Say doesn't work during instance intialise method

Post by SimpleSi » Sep 11th, '17, 16:27

Ta for info

Post Reply