change density for a limited period only

About advanced scenes, and the Thyme scripting language used in Algodoo.

change density for a limited period only

Postby MyMan » Mon Sep 30, 2013 12:52 pm

Hey,
is it possible to change something like the density just for a limited period? :roll:

e.g.

onHitByLaser = (e)=>{density = 0.005}
but after 5 seconds the density should return to 2.0

MyMan
MyMan
 
Posts: 4
Joined: Mon Sep 16, 2013 6:59 pm

Re: change density for a limited period only

Postby mold999 » Mon Sep 30, 2013 10:23 pm

Yes, it is possible. Is it ok if it uses scene.my.* variables, or not?
Phundementalism?

Ain't nobody got
thyme fo dat.
User avatar
mold999
 
Posts: 225
Joined: Sun Jan 02, 2011 1:35 am
Location: [176436, 3763234]

Re: change density for a limited period only

Postby MyMan » Tue Oct 01, 2013 5:49 pm

Yes
it is ok
But then you have to tell me every little step.
I have no experience with own variables
MyMan
 
Posts: 4
Joined: Mon Sep 16, 2013 6:59 pm

Re: change density for a limited period only

Postby mold999 » Wed Oct 02, 2013 12:04 am

Okay, I'll try to explain:

  • Open the console by pressing the "~" button.
  • Type into the console: scene.my.densityChange = 2
  • Open the script menu of the object where you want to change the density.
  • Remove the "2.0" from the density value inside the script menu, and type: {scene.my.density}
  • Change the controllerAcc of the object to 0.
  • In the onHitByLaser value, type:

    (e)=>{
    scene.my.densityChange != 2 ? {
    sim.time - controllerAcc >= 1 ? {
    scene.my.density = 2
    } : {}
    } : {
    controllerAcc = sim.time
    }
    }

And there you go. Whenever you want to change the density of that object, change the value of scene.my.densityChange. After 1 second, the density will return to 2.

The red "1" inside the code is the number of seconds it takes to change the density back to 2.
Phundementalism?

Ain't nobody got
thyme fo dat.
User avatar
mold999
 
Posts: 225
Joined: Sun Jan 02, 2011 1:35 am
Location: [176436, 3763234]

Re: change density for a limited period only

Postby MrGlinzz » Wed Oct 23, 2013 1:31 pm

If you don't want to use scene.my variables, try this:

On the box you want to change the density change these two pieces of code..

Code: Select all
onHitByLaser := (e)=>{
        density = 1;
        e.this.controllerAcc = sim.time
    }


And also

Code: Select all
update := (e)=>{
        sim.time - controllerAcc >= 2 ? {
            density = 2
        } : {}
    }
MrGlinzz
 
Posts: 13
Joined: Tue Mar 19, 2013 11:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests