Object Variables?
14 posts • Page 1 of 1
Object Variables?
I've heard of these "object variables" or something of the sort, but I can't quite understand how they work.
I copied a box (Lets call it box1), and pasted it into the console with the variable name, "scene.my.box".
I then went to another box (Lets call it box2), and tried to set the text to the position of box1. I tried:
Text = {"" + scene.my.box.pos}
Text = {"" + (scene.my.box).pos}
And also
Text = {"" + readable(scene.my.box).pos}
I don't have a good idea of how readable works, but I tried it anyway. I don't even know what readable is used for.
Is there any way I can inform box2 of box1's properties?
Thanks,
~~mold999
I copied a box (Lets call it box1), and pasted it into the console with the variable name, "scene.my.box".
I then went to another box (Lets call it box2), and tried to set the text to the position of box1. I tried:
Text = {"" + scene.my.box.pos}
Text = {"" + (scene.my.box).pos}
And also
Text = {"" + readable(scene.my.box).pos}
I don't have a good idea of how readable works, but I tried it anyway. I don't even know what readable is used for.
Is there any way I can inform box2 of box1's properties?
Thanks,
~~mold999
Phundementalism?
Ain't nobody got thyme fo dat.
Ain't nobody got thyme fo dat.
-

mold999 - Posts: 225
- Joined: Sun Jan 02, 2011 1:35 am
- Location: [176436, 3763234]
Re: Object Variables?
copy-paste will not work.
You need to create object like that: scene.my.box = scene.addbox({...}).
or
You can assign object via e.geom/e.this/e.other in onLaserHit/onHitBylaser/onCollide event:
onCollide = (e) => {scene.my.box = e.other}
after that you can read/modify object using scene.my.box
scene.my.box.color = [1,1,1,1]
etc.

You need to create object like that: scene.my.box = scene.addbox({...}).
or
You can assign object via e.geom/e.this/e.other in onLaserHit/onHitBylaser/onCollide event:
onCollide = (e) => {scene.my.box = e.other}
after that you can read/modify object using scene.my.box
scene.my.box.color = [1,1,1,1]
etc.
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Object Variables?
Ok, I made my box like this:
scene.my.box = scene.addbox({size := [1, 1]; color := [1, 0, 0, 1]; pos := [-2, 1]})
And it made a red box on the screen. Now, is there any way to edit the box's properties? I made a circle, and in the onCollide, typed this:
onCollide = (e)=>{scene.my.box.color = [1, 1, 1, 1]}
But nothing happens to the box.
--mold999
scene.my.box = scene.addbox({size := [1, 1]; color := [1, 0, 0, 1]; pos := [-2, 1]})
And it made a red box on the screen. Now, is there any way to edit the box's properties? I made a circle, and in the onCollide, typed this:
onCollide = (e)=>{scene.my.box.color = [1, 1, 1, 1]}
But nothing happens to the box.
--mold999
Phundementalism?
Ain't nobody got thyme fo dat.
Ain't nobody got thyme fo dat.
-

mold999 - Posts: 225
- Joined: Sun Jan 02, 2011 1:35 am
- Location: [176436, 3763234]
Re: Object Variables?
That works perfectly. I've just did exactly what you said to check. 
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Object Variables?
I tried it too, and it works as expected. Are you still having trouble with it, mold999?
-

Xray - Posts: 501
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Object Variables?
No, I got it.
I made a syntax mistake.
I made a syntax mistake.
Phundementalism?
Ain't nobody got thyme fo dat.
Ain't nobody got thyme fo dat.
-

mold999 - Posts: 225
- Joined: Sun Jan 02, 2011 1:35 am
- Location: [176436, 3763234]
Re: Object Variables?
Hi all there,
I have tried to follow this thread. It works for me to, but just once. When I undo and runs again the effect with the changing color is not there. Is there an explanation why? (I have version 2.0.1)
.... some test done .... continue my story.....
I guess that the restart of simulation, also includes my creation of the box and my retrieved reference, which then could explain way it doesn't work the second time, but the box itself doesn't disappear which seems a little bit strange. (I just upgraded to 2.1.0 b4, but it behaves the same way ). So does someone have an explanation?
I have tried to follow this thread. It works for me to, but just once. When I undo and runs again the effect with the changing color is not there. Is there an explanation why? (I have version 2.0.1)
.... some test done .... continue my story.....
I guess that the restart of simulation, also includes my creation of the box and my retrieved reference, which then could explain way it doesn't work the second time, but the box itself doesn't disappear which seems a little bit strange. (I just upgraded to 2.1.0 b4, but it behaves the same way ). So does someone have an explanation?
- ulfwil
- Posts: 4
- Joined: Wed Mar 06, 2013 12:08 am
Re: Object Variables?
ulfwil -- I confirmed your observation. I believe what's happening is when you UNDO, the function "scene.my.box" that was created in the console was also UNDO'd as if it never happened. So, after you undo the scene, and are now technically back to the point before you created the function scene.my.box, you need to re-enter it into the console. After doing that, the collide worked as expected. Now, I don't know whether or not it's supposed to work that way, so maybe Kilinich or one of the other Algodoo experts can comment about that.
-

Xray - Posts: 501
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Object Variables?
My real problem for the moment, I have for some time an idea I want to test. But the scripting "language" is not clear to me. Nothing like what I'm used to, and the tutorials doesn't give me much (maybe I am too old
)
Anyway, this is what I want to achieve:
I want a circle (eventually whith a connected thruster), that is affected by a force depending of its velocity and direction. i.e. simulating an electron in a magnetic field, so the force will depend on direction and speed. And then I want a lots of electrons at the same time having this behaviour.
Anyone any ideas?
Anyway, this is what I want to achieve:
I want a circle (eventually whith a connected thruster), that is affected by a force depending of its velocity and direction. i.e. simulating an electron in a magnetic field, so the force will depend on direction and speed. And then I want a lots of electrons at the same time having this behaviour.
Anyone any ideas?
- ulfwil
- Posts: 4
- Joined: Wed Mar 06, 2013 12:08 am
Re: Object Variables?
ulfwil wrote:I want a circle (eventually whith a connected thruster), that is affected by a force depending of its velocity and direction. i.e. simulating an electron in a magnetic field, so the force will depend on direction and speed. And then I want a lots of electrons at the same time having this behaviour.
Anyone any ideas?
Well, I don't understand what you want to do, could you explain it a little better? But I can try to help you.
First, you can get the velocity's direction (angle) using the inverse tangent of the tangent.
For example:
- Code: Select all
math.atan(tan)
The tangent in this case is vel(1)/vel(0)
So:
- Code: Select all
math.atan(vel(1)/vel(0))
However it will give you only -pi/2 to pi/2 values - the angle is not accurate when x vel is negative.
You need to put an If:
- Code: Select all
math.atan(vel(1)/vel(0)) - (vel(0) < 0 ? math.pi : 0)
But the thruster does not have vel value. You'll need to access using Scene.entityByGeomID:
- Code: Select all
me := (readable(entity));
v := (Scene.entityByGeomID(me.geom)).vel;
math.atan(v(1) / v(0)) - (v(0) < 0 ? math.pi : 0)
The first 2 lines access the geom that is glued to the thruster.
And to get the velocity's vector:
- Code: Select all
math.vec.len(vel)
"vel" is used only when the object has this value on script menu.
Scene example:
I hope helped you.
Sry for any misspelling
-

carl00s01 - Posts: 24
- Joined: Fri Nov 26, 2010 7:03 pm
- Location: Brazil
Re: Object Variables?
Many thanks for this.
The clue were the following code for the force property for the thruster:
As far as I understand so will th eforce get the value of the last setting in the rutine, in this case math.vec.len(v). Right?
Seems to work and I will go further from here before I reach my goal. But during that time thanks alot.
The clue were the following code for the force property for the thruster:
- Code: Select all
{
me := Scene.entityByGeomID((readable(entity)).geom);
v := me.vel;
a := math.atan(v(1) / v(0)) - (v(0) < 0 ? math.pi : 0);
rotation = a - math.pi;
math.vec.len(v)
};
As far as I understand so will th eforce get the value of the last setting in the rutine, in this case math.vec.len(v). Right?
Seems to work and I will go further from here before I reach my goal. But during that time thanks alot.
- ulfwil
- Posts: 4
- Joined: Wed Mar 06, 2013 12:08 am
Re: Object Variables?
Yes. You're right.
-

carl00s01 - Posts: 24
- Joined: Fri Nov 26, 2010 7:03 pm
- Location: Brazil
Re: Object Variables?
Hi again,
Now do I have another question. Is there a way to set the restitution for each collide? What I want is a plane or wall that depending on the hitting object speed change the collisions restitution. A fast object will have a less value and a slow object a value of 1.0. Is it possible to use the onCollide routine to change the property or will the new value been set after the hit is already calculated? And what happens if there are two collisions "at the same time" in such case.
Now do I have another question. Is there a way to set the restitution for each collide? What I want is a plane or wall that depending on the hitting object speed change the collisions restitution. A fast object will have a less value and a slow object a value of 1.0. Is it possible to use the onCollide routine to change the property or will the new value been set after the hit is already calculated? And what happens if there are two collisions "at the same time" in such case.
- ulfwil
- Posts: 4
- Joined: Wed Mar 06, 2013 12:08 am
Re: Object Variables?
In real-time physics, it's best to say that 'on-collide' is actually done AFTER the collision.
In the new beta in the announcement section, it is possible to run a calculation per step, or in the current stable release, place your calculation inside '{}' in the restitution section and it should use the result of the formula for the value.
In the new beta in the announcement section, it is possible to run a calculation per step, or in the current stable release, place your calculation inside '{}' in the restitution section and it should use the result of the formula for the value.
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
14 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests




