Hi together,
I am new to this list. So perhaps I should introduce myself. I am 25 year old german student studying congitive neuroscience in Utrecht/Netherlands. I want to use squeak /etoys mainly for exploring and visualizing some ideas in a quick way. Right now I want to build a prototype for an experiment and think that this is a good project to learn a bit more about squeak. I want to program a sequence of objects appearing on different positions on the screen one after the other and later in a random order. A very dirty way to do so is just script doing something like. object1 show. script wait for 1000ms. object1 hide object2 show script wait for 1000ms. I know that this is a very basic question but couldn't find the answer, as I don't know what it is I am looking for. thanks a lot martin _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Nov 29, 2006, at 19:17 , Martin Bleichner wrote:
> Hi together, > > I am new to this list. So perhaps I should introduce myself. I am > 25 year old german student studying congitive neuroscience in > Utrecht/Netherlands. I want to use squeak /etoys mainly for > exploring and visualizing some ideas in a quick way. > > Right now I want to build a prototype for an experiment and think > that this is a good project to learn a bit more about squeak. > > I want to program a sequence of objects appearing on different > positions on the screen one after the other and later in a random > order. > A very dirty way to do so is just script doing something like. > object1 show. > script wait for 1000ms. > object1 hide > object2 show > script wait for 1000ms. > > I know that this is a very basic question but couldn't find the > answer, as I don't know what it is I am looking for. Waiting inside a script is not supported in this version of etoys. What you can do instead is this: script ticking once a second, for an object with a variable named i * increase i by 1 * Test i = 1 Yes: obj1 show * Test i = 2 Yes: obj1 hide, obj2 show * Test i = 3 Yes: set i to 0 - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Bert,
that works, thanks. But the more objects I have the more complicated and unhandy it gets. Can I do it if I don't use the etoys script? martin _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Martin Bleichner-2
Martin Bleichner wrote:
> Hi together, > > I am new to this list. So perhaps I should introduce myself. I am 25 > year old german student studying congitive neuroscience in > Utrecht/Netherlands. I want to use squeak /etoys mainly for exploring > and visualizing some ideas in a quick way. > > Right now I want to build a prototype for an experiment and think that > this is a good project to learn a bit more about squeak. > > I want to program a sequence of objects appearing on different positions > on the screen one after the other and later in a random order. > A very dirty way to do so is just script doing something like. > object1 show. > script wait for 1000ms. > object1 hide > object2 show > script wait for 1000ms. > > I know that this is a very basic question but couldn't find the answer, > as I don't know what it is I am looking for. Because of the structure of Etoys, entire scripts are done all the way through (or not at all). A useful idiom (even in Etoys) for this kind of event-driven behavior might be the idea of a "state machine". Note that in Etoys you can "clone" an object that has scripts; all the clones of an object (its "siblings") will share the same scripts but have their own copies of variables (and of course their own position, appearance, etc.). So if you have a number of objects whose behavior is similar this can be a powerful way to save work (and to have a single place to change the behavior of all the "sibllng" objects). The attached image is an example of a very simple state machine that provides the kinds of delays that would work in your application (provided you write your program correctly, of course!). The bottom two scripts (turnRed and turnGreen) would be user-specific and would be different in your application; the upper ones are generic state machine infrastructure. You'd change the name of the state in "initial" to the first state you wanted to run. The state machine shown changes the color of the ellipse from red to green and back, staying at a particular color for 2 ticks (you can change the tick rate of the "stateMachine" script to change the resolution of "delayForTicks:"). This structure provides the ability to change states (note that the current state script will be invoked every tick) and to delay between state transitions. The trick is this: each of these state scripts only get run once per cycle. They set the delay timer to delay the execution of the *next* state, then do their thing. See if you can use this idea for your needs, and tell us what you come up with! Enjoy, -- Ned Konz [hidden email] http://bike-nomad.com EtoysStateMachine.png (58K) Download Attachment |
I suppose I should add to my prior state machine email that:
* You can move the delayForTicks: lines down to the bottom of the turnRed and turnGreen scripts; they will make more sense here (as they really affect the delay after the script runs). * The stateTest object has the following variables: - delay, a Number - currentState, a ScriptName * the stateMachine script is set to fire once per tick, and you can change the tick rate to whatever you want. If you change the tick rate to something other than 1 second, you might want to add a scaling factor to the delayForTicks: script, and rename it as delayForSeconds: or delayForMilliseconds: instead. For instance, if you change the stateMachine script to tick at 10/second (I think the default is 8/second) you might do this for delayForSeconds: delayForSeconds: {Number} stateTest's delay <- Number * 10 So now you can say stateTest delayForSeconds: 0.3 and have it work as expected. BTW: to change the tick rate, you hold your mouse down for at least a second on the little clock face on the script editor. You don't want to change the "fires per tick"!. -- Ned Konz [hidden email] http://bike-nomad.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Ned Konz
On Monday December 04, 2006, Ned Konz wrote:
> The attached image is an example of a very simple state machine that > provides the kinds of delays that would work in your application > (provided you write your program correctly, of course!). Hi, I tried setting up things as pictured in the attached image, but my ellipse won't change colour. If I open up a viewer for it, I can see the colour assigned to "StateTest's color" changing, but on the ellipse itself nothing seems to be happening. In order to write the scripts as shown, I created two stateTest variables, one called "currentState", which is assigned a script, and "delay", which is assigned a number. What else do I need to do (or undo) to get the ellipse to change colour? (It also seemed odd to me that "stateTest's color" doesn't appear in the category "color & border". To get at it, I had to search on "color". Why is that?) Thanks, Randy _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Randy Goldenberg wrote:
> On Monday December 04, 2006, Ned Konz wrote: > >> The attached image is an example of a very simple state machine that >> provides the kinds of delays that would work in your application >> (provided you write your program correctly, of course!). > > Hi, > > I tried setting up things as pictured in the attached > image, but my ellipse won't change colour. If I open up a > viewer for it, I can see the colour assigned to > "StateTest's color" changing, but on the ellipse itself > nothing seems to be happening. > Is it possible that you have more than one object cloned? Try doing a shift-click on the World and see if there are more than one stateTest objects. Clicking on the '!' button on the turnRed or turnGreen scripts should change the color of the ellipse. > In order to write the scripts as shown, I created two > stateTest variables, one called "currentState", which is > assigned a script, and "delay", which is assigned a > number. What else do I need to do (or undo) to get the > ellipse to change colour? > > (It also seemed odd to me that "stateTest's color" doesn't > appear in the category "color & border". To get at it, I > had to search on "color". Why is that?) > > Thanks, > > Randy > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > -- Ned Konz [hidden email] http://bike-nomad.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Wednesday December 06, 2006, Ned Konz wrote:
> Is it possible that you have more than one object cloned? > > Try doing a shift-click on the World and see if there are more than one > stateTest objects. Using "inspect" and "explore", I didn't see any cloned objects. In the screenshot below, the star is red, but its viewer reports it as blue. If I run a script to change the colour to green, the box in the viewer changes to green, but the star remains red. http://ws.cs.ubc.ca/~randyg/redStar.pdf I'm using Squeakland 3.8-05, latest update: #552, Current Change Set: Unnamed1. Operating system is Darwin 7.9.0 Darwin Kernel Version 7.9.0; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC Power Macintosh powerpc. Thanks, Randy _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Randy Goldenberg wrote:
> On Wednesday December 06, 2006, Ned Konz wrote: > >> Is it possible that you have more than one object cloned? >> >> Try doing a shift-click on the World and see if there are more than one >> stateTest objects. > > Using "inspect" and "explore", I didn't see any cloned > objects. > > In the screenshot below, the star is red, but its viewer > reports it as blue. If I run a script to change the > colour to green, the box in the viewer changes to green, > but the star remains red. > Could you save the project with the state machine somewhere on the 'net so I could look at it? -- Ned Konz [hidden email] http://bike-nomad.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Ned,
thanks a lot for your example I really learned a lot, conceptually as well as on the code level. On the metalevel I learned how much you can learn if you really have a close look at someone else code. I basically use your idea now, I use more different colors. I expanded it by some if-tests, this allows me more complex transitions. martin _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Ned Konz
On Thursday December 07, 2006, Ned Konz wrote:
> Could you save the project with the state machine > somewhere on the 'net so I could look at it? Thanks very much for all your work on this. http://ws.cs.ubc.ca/~randyg/stateTest.001.pr Cheers, Randy _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Randy Goldenberg wrote:
> On Thursday December 07, 2006, Ned Konz wrote: > >> Could you save the project with the state machine >> somewhere on the 'net so I could look at it? > > Thanks very much for all your work on this. > > http://ws.cs.ubc.ca/~randyg/stateTest.001.pr The problem is that the stateTest object is not something with a useful "color" property. It is a SketchMorph, whose colors come from the user. I used a TextEllipse (on the Connectors page); you could use a Rectangle, Ellipse, Polygon, etc. and it would work. These have an actual "color" property that does something. -- Ned Konz [hidden email] http://bike-nomad.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Monday December 11, 2006, Ned Konz wrote:
> The problem is that the stateTest object is not something > with a useful "color" property. It is a SketchMorph, whose > colors come from the user. I used a TextEllipse (on the > Connectors page); you could use a Rectangle, Ellipse, > Polygon, etc. and it would work. These have an actual > "color" property that does something. Thanks. It wouldn't have occurred to me that an ellipse drawn by the user has different properties than one dragged out from a flap. Cheers, Randy _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Ned Konz
Hi,
I have an object for which I've created some variables and scripts. I would like to add those variables and scripts to another, different object (original object was a SketchMorph, new object is an Ellipse dragged out from the "Supplies" flap). Does etoys offer a quick way of doing that? TIA, Randy _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Dec 12, 2006, at 13:55 , Randy Goldenberg wrote:
> Hi, > > I have an object for which I've created some variables and > scripts. I would like to add those variables and scripts > to another, different object (original object was a > SketchMorph, new object is an Ellipse dragged out from the > "Supplies" flap). Does etoys offer a quick way of > doing that? Yes. You are actually scripting a separate object, called a "player". A player can wear different "customes", which is the object you see on screen. So just make your scripted object wear a different custome (there is a tile for that). - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Randy Goldenberg
On Dec 12, 2006, at 13:55 , Randy Goldenberg wrote:
> Hi, > > I have an object for which I've created some variables and > scripts. I would like to add those variables and scripts > to another, different object (original object was a > SketchMorph, new object is an Ellipse dragged out from the > "Supplies" flap). Does etoys offer a quick way of > doing that? Yes. You are actually scripting a separate object, called a "player". A player can wear different "customes", which is the object you see on screen. So just make your scripted object wear a different custome (there is a tile for that). - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Saturday December 16, 2006, Bert Freudenberg wrote:
> Yes. You are actually scripting a separate object, called a "player". > A player can wear different "customes", which is the object you see > on screen. So just make your scripted object wear a different custome > (there is a tile for that). Is that the "look like" tile? I tried using that to make the SketchMorph object "look like" the Ellipse. The SketchMorph did then take on the appearance of the Ellipse, but the scripts that only work if the scripted object *is* an Ellipse didn't work. (I tried it the other way around too (Ellipse look like SketchMorph), just to make sure I hadn't got things backwards, but the scripts still didn't run.) Am I following your suggestion correctly? I also tried copying and pasting the scripts from the SketchMorph into the Ellipse, but that didn't work out either. I did manage to toggle from tile to text and do the cut and paste operation, but when I tried to then revert back to tiles it seemed that the changes I had made would be discarded. Also, what are "morphs" and "players"? I see them mentioned in pop up menus, but don't know what the words mean in the context of eToys. Thanks, Randy _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |