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

#1 2011-10-18 09:25:08

csn
New Scratcher
Registered: 2011-10-17
Posts: 27

call doWaitUntil in Squeak

I want to build a block, that is waiting until a specific rotation direction is reached. The aim is do simulate a NXT-Bot. I try to build all the motion commands enchanting has. Just two blocks are left. It is the "rotate L/R to 90 ° and wait" and "rotate L/R 90° and wait". I saw that the other "wait"-blocks are time-blocks or special blocks. I can't solve the problem with time-blocks and I'm to much of a beginner to try coding a special block.

But I saw the doWaitUntil - method which belongs to the "wait until" block. If I could call this method form within squeak the problem should be solved.

The method doWaitUntil is defined in ScratchExecution Engine | ScratchProcess | private-special forms.

I'd like to use it within a method in Scratch-Objects | ScratchSpriteMorph . The name is accepted so I think the method is known in this class. Furthermore the method is called in ScriptableScratchMorph from within the class section because the wait until block is calling it. So, it really should be known in Scratch-Objects | ScratchSpriteMorph.

But I can't figure out how it is called correctly. The argument must be a block which can be evaluated to True or False I assume.

Perhaps somebody can help me.

Offline

 

#2 2011-10-18 21:15:06

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

Re: call doWaitUntil in Squeak

Why bother with that method?  Use whileFalse.  Example:

Code:

 [t1 > t2] whileFalse

This is typically used with commands, but can be used like I did above.  For example, for my "freeze scratch" block, I used

Code:

0=0 whileTrue

which causes an infinite loop, freezing Scratch.

Offline

 

#3 2011-10-19 03:43:54

csn
New Scratcher
Registered: 2011-10-17
Posts: 27

Re: call doWaitUntil in Squeak

whileTrue and whileFalse have two disadvantages.
You mentionde the first one: Scratch is frozen while looping or waiting. You can't move the sprite or click the menues.
The second is that the sprite is not redrawn in the meantime. In my simulation you should see the bot moving but with whileTrue the bot jumps form the start to the endposition.

Within the loop I can get the sprite redrawn by "self say: 'hello'. " or "World displayWorldSafely. " but the loop is executed faster than the if it would be a with doWaitUntil. So the bots speed varies and that shoudn't happen.

So in the end I just hope to get doWaitUntil working.

csn

Offline

 

#4 2011-10-19 04:37:46

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: call doWaitUntil in Squeak

Greenatic wrote:

(...)for my "freeze scratch" block, I used

Code:

0=0 whileTrue

which causes an infinite loop, freezing Scratch.

There's an easier way:

Code:

freeze
self freeze

Just keeps calling itself  wink .


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5 2011-10-19 10:45:36

pbromberg
New Scratcher
Registered: 2011-10-19
Posts: 1

Re: call doWaitUntil in Squeak

Here is a good site with programming articles:  http://www.eggheadcafe.com

Offline

 

#6 2011-10-19 10:58:50

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: call doWaitUntil in Squeak

pbromberg wrote:

Here is a good site with programming articles:  http://www.eggheadcafe.com

although that appears to be for .NET devs.


http://i.imgur.com/zeIZW.png

Offline

 

#7 2011-10-19 15:32:03

csn
New Scratcher
Registered: 2011-10-17
Posts: 27

Re: call doWaitUntil in Squeak

I have searched a while for solution. And I have an idea that perhaps could get me to success. But as you see I'm a new scratcher and I hope I my thoughts are not to foolish.

I looked at the "broadcast and wait" block and the "doWaitUntil"-Block. They have the same structure. Something with stackFrames and pushing commands on it. This is only possible in the Sratch-Execution Engine I assume.

Perhaps it is possible to build a method there, that does the trick. But therefore I must evaluate and manipulate variables that are defined in ScriptableScratchMorph. It would be very easy if I could write the variablenames directly in a method in Scratch-Execution Engine but as I got it right that would lead to another variable. Variables of ScriptableSpriteMorph are only known in runtime by the Scratch-Execution engine. At runtime they are evaluated by the engine.
In "broadcast and wait" there is a command that gives back all the procedures that are started by the broadcastevent (I hope I understood that in the right way).
Perhaps it is also possible to get a list of the variables that are involved in running procedures or connected to active sprites or however you call it. I could search for the names and manipulate their value? Something like this could be possible. But certainly if it is possible than it is too ambitious for me without any advice.


In addition I've found the command to evaluate special blocks in Scratch-Execution Engine | ScratchProcess | private-evaluation | evaluateSpecialForm:
self perform: stackFrame expression selector.
Could I use this in a method in ScriptableScratchMorph?

Tons of questions.
cns

Offline

 

#8 2011-10-21 15:42:55

csn
New Scratcher
Registered: 2011-10-17
Posts: 27

Re: call doWaitUntil in Squeak

Have another try:

The basic construction is: The simulated bots movement is controlled by a step - method.
The scratch -blocks just set some variables like speed, rotateMotorTo, ... .
It works well just the "rotate and wait" -block is difficult. The scratch-block starts a method where the variable rotateTo is set. Rotation is controlled by the step method. After successful rotation a variable is set back to 0. When I want to wait with "whileTrue" for this event in the original scratchmethod "rotateAndWait" this won't work. The step-method isn't executed further because the "rotateAndWait"-method is in a loop. Threads don't seem to switch if the current thread is in a loop. (That makes sense.)

If the step-method and the normal execution of a Scriptstack are two different processes, one could perhaps suspend the process with the scratchblock "rotate and wait" from within this method and resume it when rotation is done from within the step-method.
Does anyone know how to suspend the current process and how to resume it later from within another process?

(I tried it with self Processor activProcess suspend, but this did not work. If you call say: Processor activProcess. the sprite says something with "Nil". Strange.)

Offline

 

Board footer