Browse Search Popular Register Upload Rules User list Login:
Search:
object_takes_color

Image:
screenshot of the scene

Author: DrBalk

Group: Collaborations

Filesize: 6.1 kB

Date added: 2016-10-16

Rating: 5

Downloads: 137

Views: 168

Comments: 6

Ratings: 1

Times favored: 0

Made with: Algodoo v2.1.0

Tags:

Scene tag

A laser is fixed to a green object G.
It can hit a red object R and then by script
the color of G will become that of R.

I dont know yet how to move the functions
into onSpawn of the laser, because if i use 200 or more
of these lasers, the simulation will become really slow.
I thought if it is inside of onSpawn then the basic object
will be accessible much quicker, as the adress of it
will not change, so this has to be done just once at the
beginning of the scene.

Maybe someone can help?:s
Last edited at 2016/10/16 12:44:56 by DrBalk
Please log in to rate this scene
edit
Try 200 lasers with no code in them. If the simulation is too slow then there is not much you can do. Otherwise, the following might help:

onLaserHit := (e)=>{
(scene.entityByGeomID((readable(entity)).geom)).co­lor = e.geom.color
};
maxRays := 1;

I couldn't figure out how to get a box entity variable on spawning and then reliably clone the lasers.
Last edited at 2016/10/16 14:30:10 by s_noonan
Thank you, s_noonan
indeed the maxRays reduction to 1 is a big help, i set also maxCuts=1.

My idea was: I think the GeomID of the object G, where the laser
is attached to, does not change while the whole simulation runs.
I thought that the
(scene.entityByGeomID((readable(entity)).geom))
g­ives a kind of storage-adress of G, where to find and adress
the properties
of its child-objects or child-variables like color or any other
variable or function of the object G.

Now, if i use the laser, and the laser hits 60 times per second,
and every time the same storage-adress is calculated, that would
be a waste of time in my eyes.

Maybe it would work if i add an own "click on me"-start-object
which will do then the same job as the onSpawn,
you know what i mean?

An other way out would be to check the properties of the laserHit
only every second.

Why i worry a bit about speed is: at home i have a good computer,
but at school the kids use older ones.
Your trick with maxRays allready gave some extraspeed, for which
i thank you _o_
My idea was: I think the GeomID of the object G, where the laser
is attached to, does not change while the whole simulation runs.

I agree.

I thought that the
(scene.entityByGeomID((readable(entity)).geom)­)
gives a kind of storage-adress of G, where to find and adress
the properties
of its child-objects or child-variables like color or any other
variable or function of the object G.

I think that (scene.entityByGeomID((readable(entity)).geom)) returns the object G.

Now, if i use the laser, and the laser hits 60 times per second,
and every time the same storage-adress is calculated, that would
be a waste of time in my eyes.

I agree.

Maybe it would work if i add an own "click on me"-start-object
which will do then the same job as the onSpawn,
you know what i mean?

Yes. You can do the following:

in update:
entity._g := scene.entityByGeomID((readable(entity)).geom);
upd­ate = (e)=>{}

in onLaserHit
_g.color = e.geom.color

but it won't help you much.


An other way out would be to check the properties of the laserHit
only every second.

That might work.
Here is an idea:

_boxColor := [0.0, 0.5, 0.0, 1.0];
_colorfound := [0.0, 0.5, 0.0, 1.0]

In onLaserHit:

_colorfound = e.geom.color;
_boxColor != _colorfound ? {
_boxColor = _colorfound;
(scene.entityByGeomID((readable(entity)).geom)).co­lor = _colorfound;
}:{}
Thank you again, s_noonan, this idea would really work nicely
if the check of colors would not have to be done very often.
Yet, it is use to pass a local variable from one object ot another
and this can happen often, to be precise i will show you a first
applicaton of the use of local variables, where FRA32 taught me a lot of,
thanks to him;)


It is:
http://www.algodoo.com/algobox/details.php?id=144119
Last edited at 2016/10/18 19:13:53 by DrBalk
My idea above was to set the box color only if the object that the laser hits has a different color than the box. Why waste time setting a object property to the same value it had to begin with? My initial thought was that setting an object property [for example, (scene.entityByGeomID((readable(entity)).geom)).co­­lor = _colorfound] is more resource intensive than getting an object property [for example, _colorfound = e.geom.color]. Even if setting and getting object properties used the same amount of resources, setting an object property only when you need to should cut the task about 50% for scenes where properties change much slower than the laser hit rate (like in your connect4 scene). Also, your idea to check the properties of the laserHit only every second is a good one and that idea alone may be sufficient.