Question about Etoys Custome Events and Triggering Objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about Etoys Custome Events and Triggering Objects

Jeremy L.
This question pertains to Etoys 5.  

I'm trying to set up communication between two objects using event triggers, but cannot seem to understand what I'm doing wrong.

Here is the project:

Here is the description of desired effect:
The playfield tells all Enemy objects (just one in this case) to 'bounceAround'. Then following that, tells all BGTile objects to 'beSolid'. If the Enemy object overlaps any BGTile object with it's variable of 'isSolid' set to True, that BGTile object triggers an event the Enemy object responds to.  The problem is that the trigger isn't seen by the Enemy object as having come from BGTile but from the entire playfield!

I set up a variable within Enemy to figure out why setting Enemy's Bottom to Enemy's Triggering Object's Top would send the Enemy completely off the screen. 

Is this because the originating script that is ticking is the Playfield's script?  If so, how should I set this up to create a situation where sibling objects can find specifically which ones actually collided if the Triggering Object will always be the originating ticking script?

Thanks for any help and I hope this makes sense.  I left the offending scripts open along with the Enemy viewer flap so that the triggering object variable is seen.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Bert Freudenberg
On Mon, 3 Sep 2018 at 17:39, Jeremy Landry <[hidden email]> wrote:
This question pertains to Etoys 5.  

I'm trying to set up communication between two objects using event triggers, but cannot seem to understand what I'm doing wrong.

Here is the project:

Here is the description of desired effect:
The playfield tells all Enemy objects (just one in this case) to 'bounceAround'. Then following that, tells all BGTile objects to 'beSolid'. If the Enemy object overlaps any BGTile object with it's variable of 'isSolid' set to True, that BGTile object triggers an event the Enemy object responds to.  The problem is that the trigger isn't seen by the Enemy object as having come from BGTile but from the entire playfield!

I set up a variable within Enemy to figure out why setting Enemy's Bottom to Enemy's Triggering Object's Top would send the Enemy completely off the screen. 

Is this because the originating script that is ticking is the Playfield's script?  If so, how should I set this up to create a situation where sibling objects can find specifically which ones actually collided if the Triggering Object will always be the originating ticking script?

Thanks for any help and I hope this makes sense.  I left the offending scripts open along with the Enemy viewer flap so that the triggering object variable is seen.

This kind of general object-object interaction is hard in Etoys.

We generally try to design around it. For example, in Pac-Man, the obvious approach would be to move the player, check if it collided with a dot, then delete that dot. This doesn't work because it is not easy to check which dot it collided with. Instead, we have all the dots ticking to check if they collided with the player, and if so delete themselves and increase the global score.

Maybe you can design your game in a similar way?

- Bert -

 

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Bert Freudenberg
On Mon, 3 Sep 2018 at 18:11, Bert Freudenberg <[hidden email]> wrote:

We generally try to design around it. For example, in Pac-Man, the obvious approach would be to move the player, check if it collided with a dot, then delete that dot. This doesn't work because it is not easy to check which dot it collided with. Instead, we have all the dots ticking to check if they collided with the player, and if so delete themselves and increase the global score.

Here is one idea:

image.jpg

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Jeremy L.
What is the intended use for 'triggering object' tile? Is this the object that starts the current object's script then and not one that triggers events?

I think I will use your example, but instead break up the graphic tiles into 4 objects that fit together like puzzle piece so that the graphics do not have to be specific colors (i.e. a box will be 4 smaller boxes and uses pieces of same graphic.  I think that will work the same way if I make 'tops' all sibling objects, all 'lefts' sibling objects and use 'overlaps any top' or 'overlaps any left' etc.  

On Mon, Sep 3, 2018 at 7:09 PM, Bert Freudenberg <[hidden email]> wrote:
On Mon, 3 Sep 2018 at 18:11, Bert Freudenberg <[hidden email]> wrote:

We generally try to design around it. For example, in Pac-Man, the obvious approach would be to move the player, check if it collided with a dot, then delete that dot. This doesn't work because it is not easy to check which dot it collided with. Instead, we have all the dots ticking to check if they collided with the player, and if so delete themselves and increase the global score.

Here is one idea:

image.jpg

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Jeremy L.
In reply to this post by Bert Freudenberg
It turns out using siblings of specific names works fine and they can 'hide' underneath the actual graphical elements.  

Will post a demo project soon, there's quite a bit of options that opened up with this. :)

On Mon, Sep 3, 2018 at 7:09 PM, Bert Freudenberg <[hidden email]> wrote:
On Mon, 3 Sep 2018 at 18:11, Bert Freudenberg <[hidden email]> wrote:

We generally try to design around it. For example, in Pac-Man, the obvious approach would be to move the player, check if it collided with a dot, then delete that dot. This doesn't work because it is not easy to check which dot it collided with. Instead, we have all the dots ticking to check if they collided with the player, and if so delete themselves and increase the global score.

Here is one idea:

image.jpg

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Bert Freudenberg
In reply to this post by Jeremy L.
On Mon, 3 Sep 2018 at 19:38, Jeremy Landry <[hidden email]> wrote:
What is the intended use for 'triggering object' tile?

I don't know. Never used that tile (it's hidden unless eToyFriendly is disabled).

Reading the code it indeed is intended to find the object that triggered that event / script (meaning the object mentioned in the tellAllSiblings tile).

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Jeremy L.
Here's a book of experiments with various ways of implementing 'OVERLAPS ANY (OBJECT)' along with commentary for each experiment. Maybe someone will find it useful. Overall, at least on my slow machine, page 2 seems to perform the fastest. I explain how each of the 7 versions is set up as the idea evolves across the pages.


I think in the end, having something very specific in mind with regards to motion is probably far more useful than creating 'general behaviors', at least where realtime behavior and many moving objects is concerned. As well, the things I was moving about are a little large compared to what I intend to move since there's a 'pixel limit' per frame which is hardware dependent as well as dependent on whether the screen is being scaled or not. I ran my experiments with no screen scaling at all.

If anyone has any further ideas on ways to cut screen update time or further narrow the amount of 'observations' that happen during a single update of all objects on screen, etc. let me know and I will try them out and maybe add them to this book/project for others to learn from and use for their own stuff.

On Mon, Sep 3, 2018 at 10:54 PM, Bert Freudenberg <[hidden email]> wrote:
On Mon, 3 Sep 2018 at 19:38, Jeremy Landry <[hidden email]> wrote:
What is the intended use for 'triggering object' tile?

I don't know. Never used that tile (it's hidden unless eToyFriendly is disabled).

Reading the code it indeed is intended to find the object that triggered that event / script (meaning the object mentioned in the tellAllSiblings tile).

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Jeremy L.
I figured out why special events weren't working the way I had them set up. In order for the events to be scheduled properly, so to speak, they have to occur individually and be taken care of individually.  So instead of 'Tell All Contents (SCRIPT)', I used a Do (Number of Objects) Times/PlayerAtCursor Do (then event is triggered and handled for a single pair of objects)/Cursor IncreaseBy1. This all happens each tick so it appears as if it's simultaneous. It's, so far, fastest for dealing with collisions, I will post another project soon with demos/examples.  

Also, my copy of Etoys5 starts with 'Custom User Events' checked inthe preferences.  I don't ever make changes to etoys friendly options...I'm not sure what is going on there...

On Tue, Sep 4, 2018 at 12:12 AM, Jeremy Landry <[hidden email]> wrote:
Here's a book of experiments with various ways of implementing 'OVERLAPS ANY (OBJECT)' along with commentary for each experiment. Maybe someone will find it useful. Overall, at least on my slow machine, page 2 seems to perform the fastest. I explain how each of the 7 versions is set up as the idea evolves across the pages.


I think in the end, having something very specific in mind with regards to motion is probably far more useful than creating 'general behaviors', at least where realtime behavior and many moving objects is concerned. As well, the things I was moving about are a little large compared to what I intend to move since there's a 'pixel limit' per frame which is hardware dependent as well as dependent on whether the screen is being scaled or not. I ran my experiments with no screen scaling at all.

If anyone has any further ideas on ways to cut screen update time or further narrow the amount of 'observations' that happen during a single update of all objects on screen, etc. let me know and I will try them out and maybe add them to this book/project for others to learn from and use for their own stuff.

On Mon, Sep 3, 2018 at 10:54 PM, Bert Freudenberg <[hidden email]> wrote:
On Mon, 3 Sep 2018 at 19:38, Jeremy Landry <[hidden email]> wrote:
What is the intended use for 'triggering object' tile?

I don't know. Never used that tile (it's hidden unless eToyFriendly is disabled).

Reading the code it indeed is intended to find the object that triggered that event / script (meaning the object mentioned in the tellAllSiblings tile).

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Jeremy L.
So after thinking a bit, I decided to take a different route to accomplish this, though the ending demo is a lot different (I plan on going further with this, so expect this demo to get bigger until it's something that's less demo and more 'it's just a fun game' or something to that extent).

At any rate, I was thinking about how Etoys graphics and 'overlaps any' works and thought about what I'm really after; I don't want to find out AFTER something happens that two objects are overlapping.  Plus when detecting whether things overlap, I believe Squeak goes into some maths to determine areas that overlap etc, which again aren't what I'm interested in; I'm interested in obstructing movement of objects and knowing which objects are being 'touched' when obstructing other moving things.

So I went back to the drawing board and didn't use 'overlaps any' at all.  Instead, I decided to think about 'what are the likely ways to eliminate checking anything at all if I can help it?' So for instance if something is moving to the right, then I don't need to check things behind it at all and whether it might touch them.  So from there I began writing some scripts to that do their best to check only things that absolutely will lead to a collision; at any point if any of these checks fail, the rest of the checks aren't performed so that the process can quickly move on to the next object for inspection of whether the moving object has to be worried about it or not.

Included is a demo.  It explains maybe in a bit more detail what this can do. By using this method of checking for touching objects, I can also detect which side another object was approached from as well. In the demo, the blocks change color depending on whether they were touched vertically or horizontally by the 'Hero' object with a simple script (all of the 'walls' are siblings of the object Thing and so editing Thing will send all of the other walls that functionality too).  

Again, I think it performs rather speedy, even my my old 2008 ultra portable 1.4 Ghz with virtually no video accelleration at all, I'm getting high frame rates even with checking 18 objects vs. the other try I uploaded which has many fewer objects and ends up checking a lot more about what is happening in the playfield and interactions.  

Hopefully this is useful to someone and/or ends up becoming something possibly embedded into the Etoys scripting tiles at some point, though I cannot realy think of a universal way to put this sort of thing in there where it's of any use :p


Next I will add clones of the 'Hero' with scripted automated movements to recreate the tests I already posted and I suspect they will operate much smoother and more accurately to boot.  

On Tue, Sep 4, 2018 at 10:55 AM, Jeremy Landry <[hidden email]> wrote:
I figured out why special events weren't working the way I had them set up. In order for the events to be scheduled properly, so to speak, they have to occur individually and be taken care of individually.  So instead of 'Tell All Contents (SCRIPT)', I used a Do (Number of Objects) Times/PlayerAtCursor Do (then event is triggered and handled for a single pair of objects)/Cursor IncreaseBy1. This all happens each tick so it appears as if it's simultaneous. It's, so far, fastest for dealing with collisions, I will post another project soon with demos/examples.  

Also, my copy of Etoys5 starts with 'Custom User Events' checked inthe preferences.  I don't ever make changes to etoys friendly options...I'm not sure what is going on there...

On Tue, Sep 4, 2018 at 12:12 AM, Jeremy Landry <[hidden email]> wrote:
Here's a book of experiments with various ways of implementing 'OVERLAPS ANY (OBJECT)' along with commentary for each experiment. Maybe someone will find it useful. Overall, at least on my slow machine, page 2 seems to perform the fastest. I explain how each of the 7 versions is set up as the idea evolves across the pages.


I think in the end, having something very specific in mind with regards to motion is probably far more useful than creating 'general behaviors', at least where realtime behavior and many moving objects is concerned. As well, the things I was moving about are a little large compared to what I intend to move since there's a 'pixel limit' per frame which is hardware dependent as well as dependent on whether the screen is being scaled or not. I ran my experiments with no screen scaling at all.

If anyone has any further ideas on ways to cut screen update time or further narrow the amount of 'observations' that happen during a single update of all objects on screen, etc. let me know and I will try them out and maybe add them to this book/project for others to learn from and use for their own stuff.

On Mon, Sep 3, 2018 at 10:54 PM, Bert Freudenberg <[hidden email]> wrote:
On Mon, 3 Sep 2018 at 19:38, Jeremy Landry <[hidden email]> wrote:
What is the intended use for 'triggering object' tile?

I don't know. Never used that tile (it's hidden unless eToyFriendly is disabled).

Reading the code it indeed is intended to find the object that triggered that event / script (meaning the object mentioned in the tellAllSiblings tile).

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners





_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Question about Etoys Custome Events and Triggering Objects

Jeremy L.

And here we go.  

There's a flap that has a writeup of what is happening, but basically, I took the last version, made a copy of the main player, removed controls and set up an 'auto movement' script that utilizes the collision detection. Then I modified the playfield's script to 'tell all contents HANDLE PATROL'.  Nothing is pre-scripted to move any specific way, so you can move all of the objects around and they'll react to walls, you can change their speed and what direction(s) they're moving in, etc.  Obviously, the larger you make them, the slower the update to the playfield will be since there's a pixel economy to worry about.  However, it shouldn't be especially concerning on a newer computer.  It is for the computer I'm working with which is why I made things relatively small. I suppose the next version will demo making special objects, collectables, etc. Presumably, I could remake the pacman example since in this way, no matter what the 'player/hero' bumps into, you can grab information about that object since it learns what it's element number is and then you can have the playfield set it's cursor directly to the object to send a message to it specifically.  

I might try that, or something similar.  It will be interesting to see how it handles a lot of similar objects in that way. Also, I'll probably start adding graphics and demo how to layer onto these rectangles graphics so that you can animate them without having to copy all of the scripts to a sketch object.

This has been rather fun, and it's rewarding to finally get something of this nature running relatively nice in Etoys.  I've been wanting to use it for a while now for simple, retro-style action games and have made small tests here and there regarding things like using a Book as a world-map (i.e. touching the edges of a page with your hero turns to specific pages for multi-screen worlds) etc.  One day I'll bring all of these things together coherently...hopefully.

In the meantime, enjoy this demo.


On Sat, Sep 8, 2018 at 9:42 PM, Jeremy Landry <[hidden email]> wrote:
So after thinking a bit, I decided to take a different route to accomplish this, though the ending demo is a lot different (I plan on going further with this, so expect this demo to get bigger until it's something that's less demo and more 'it's just a fun game' or something to that extent).

At any rate, I was thinking about how Etoys graphics and 'overlaps any' works and thought about what I'm really after; I don't want to find out AFTER something happens that two objects are overlapping.  Plus when detecting whether things overlap, I believe Squeak goes into some maths to determine areas that overlap etc, which again aren't what I'm interested in; I'm interested in obstructing movement of objects and knowing which objects are being 'touched' when obstructing other moving things.

So I went back to the drawing board and didn't use 'overlaps any' at all.  Instead, I decided to think about 'what are the likely ways to eliminate checking anything at all if I can help it?' So for instance if something is moving to the right, then I don't need to check things behind it at all and whether it might touch them.  So from there I began writing some scripts to that do their best to check only things that absolutely will lead to a collision; at any point if any of these checks fail, the rest of the checks aren't performed so that the process can quickly move on to the next object for inspection of whether the moving object has to be worried about it or not.

Included is a demo.  It explains maybe in a bit more detail what this can do. By using this method of checking for touching objects, I can also detect which side another object was approached from as well. In the demo, the blocks change color depending on whether they were touched vertically or horizontally by the 'Hero' object with a simple script (all of the 'walls' are siblings of the object Thing and so editing Thing will send all of the other walls that functionality too).  

Again, I think it performs rather speedy, even my my old 2008 ultra portable 1.4 Ghz with virtually no video accelleration at all, I'm getting high frame rates even with checking 18 objects vs. the other try I uploaded which has many fewer objects and ends up checking a lot more about what is happening in the playfield and interactions.  

Hopefully this is useful to someone and/or ends up becoming something possibly embedded into the Etoys scripting tiles at some point, though I cannot realy think of a universal way to put this sort of thing in there where it's of any use :p


Next I will add clones of the 'Hero' with scripted automated movements to recreate the tests I already posted and I suspect they will operate much smoother and more accurately to boot.  

On Tue, Sep 4, 2018 at 10:55 AM, Jeremy Landry <[hidden email]> wrote:
I figured out why special events weren't working the way I had them set up. In order for the events to be scheduled properly, so to speak, they have to occur individually and be taken care of individually.  So instead of 'Tell All Contents (SCRIPT)', I used a Do (Number of Objects) Times/PlayerAtCursor Do (then event is triggered and handled for a single pair of objects)/Cursor IncreaseBy1. This all happens each tick so it appears as if it's simultaneous. It's, so far, fastest for dealing with collisions, I will post another project soon with demos/examples.  

Also, my copy of Etoys5 starts with 'Custom User Events' checked inthe preferences.  I don't ever make changes to etoys friendly options...I'm not sure what is going on there...

On Tue, Sep 4, 2018 at 12:12 AM, Jeremy Landry <[hidden email]> wrote:
Here's a book of experiments with various ways of implementing 'OVERLAPS ANY (OBJECT)' along with commentary for each experiment. Maybe someone will find it useful. Overall, at least on my slow machine, page 2 seems to perform the fastest. I explain how each of the 7 versions is set up as the idea evolves across the pages.


I think in the end, having something very specific in mind with regards to motion is probably far more useful than creating 'general behaviors', at least where realtime behavior and many moving objects is concerned. As well, the things I was moving about are a little large compared to what I intend to move since there's a 'pixel limit' per frame which is hardware dependent as well as dependent on whether the screen is being scaled or not. I ran my experiments with no screen scaling at all.

If anyone has any further ideas on ways to cut screen update time or further narrow the amount of 'observations' that happen during a single update of all objects on screen, etc. let me know and I will try them out and maybe add them to this book/project for others to learn from and use for their own stuff.

On Mon, Sep 3, 2018 at 10:54 PM, Bert Freudenberg <[hidden email]> wrote:
On Mon, 3 Sep 2018 at 19:38, Jeremy Landry <[hidden email]> wrote:
What is the intended use for 'triggering object' tile?

I don't know. Never used that tile (it's hidden unless eToyFriendly is disabled).

Reading the code it indeed is intended to find the object that triggered that event / script (meaning the object mentioned in the tellAllSiblings tile).

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners






_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners