Dynamic properties

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

Dynamic properties

Postby Kilinich » Sun Dec 27, 2009 9:45 pm

During creation of my xmas scene I've stuck on spawn objects with dynamic color.
I've trying many ways but still get an error message and solid color instead of brighting one.
Today I've solve this case and I think this will help you to make more visual stunning stuff :mrgreen:

To spawn an object from console you can just type:
Code: Select all
scene.addLaserPen{pos := app.mousepos; color := {[.5+sin(sim.time*10)/2,0,0,1]}}

and this will works strange sometimes - only last laser will by dynamic, but if you try to do it in onCollide or onLaserHit you will fail completely :thumbdown: (it's kinda bug I think).
so the solution is to set color outside of spawning:
Code: Select all
(scene.addLaserPen{pos := app.mousepos}).color = {[.5+sin(sim.time*10)/2,0,0,1]}

that's all. :idea:
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Dynamic properties

Postby KarateBrot » Sun Dec 27, 2009 10:07 pm

WOW THAT'S AWESOME!
It's a (moderate) solution for the annoying thing that only let you make dynamic things for the newest spawned object.
Okay, it's not perfect but it's better than nothing :thumbup:
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Dynamic properties

Postby Versieon » Mon Dec 28, 2009 6:52 pm

Is there a way to incorporate a non updating variable into the color script that is based on the spawned object? That would make a huge difference.

I tryed using a pre defined controllerAcc value but it dosn't seem to register, it instead bases it (in real time) off the controllerAcc of the spawner.

Code: Select all
(scene.addCircle({ pos := app.mousepos; controllerAcc := sim.time })).color ={[(sim.time - e.this.controllerAcc), 0, 0, 1]}
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: Dynamic properties

Postby KarateBrot » Tue Dec 29, 2009 2:49 am

try it with OnCollide or OnLaserHit. it works for me.

btw. there's a little mistake. don't type "e.this." otherwise your code won't work in any way.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Dynamic properties

Postby Versieon » Tue Dec 29, 2009 2:54 am

Oh, I mean with the dynamic color, not just normal color changing.

That code seems to work with and without e.this, they both still depend on the controllerAcc of the spawner, not the individual circle.
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: Dynamic properties

Postby KarateBrot » Tue Dec 29, 2009 3:14 am

no it doesn't change the color if e.this. is in front of it. e.this/other only works in OnCollide. but in color there's nothing to call e. which results in an error.

but now i got your problem. it only changes the color if you press enter in the "color =" line (and if e.this. is removed). hmm i don't know a solution :?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Dynamic properties

Postby RA2lover » Tue Dec 29, 2009 5:08 pm

that will revolutionize scripts the same way as RaRaMalum did with the simple yet effective Oncollide := Oncollide ...
Jrv wrote:
TC42 wrote:Quite honestly, I didn't think anyone on 4chan has that good a use of grammar, spelling, usage, mechanics, ect.
But I've never been there, so I may be wrong.


GTFO newfgt
User avatar
RA2lover
 
Posts: 607
Joined: Mon Aug 31, 2009 8:43 pm
Location: Brazil

Re: Dynamic properties

Postby KarateBrot » Tue Dec 29, 2009 5:13 pm

yeah but there are a few problems if you want to make things with variables like versieon did above. it's a pity it doesn't work right. would be really cool if this can be fixed anyhow, too. :D
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Dynamic properties

Postby Rideg » Tue May 25, 2010 4:35 pm

I can't get this to work

Here's what I've got
Code: Select all
(Scene.addCircle({
                        controllerAcc := sim.time;
                        refractiveIndex := {((controllerAcc + 5) - sim.time) / 5};
                        drawBorder := false;
                        drawCake := false;
                        density := {refractiveIndex >= 0 ? {+inf} : {0.0}};
                        collideSet := 0;
                        materialVelocity := 0.0;
                        zDepth := +inf;
                        pos := e.pos;
                        radius := 768.0
                    })).color = {[1.0, 1.0, 1.0, ((controllerAcc + 5) - sim.time) / 5]};
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Dynamic properties

Postby Kilinich » Wed May 26, 2010 3:56 pm

As you can see - my method only works with 1 dynamic property.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Dynamic properties

Postby Rideg » Wed May 26, 2010 4:59 pm

Well thanks anyway..
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Dynamic properties

Postby REMqb » Wed May 26, 2010 5:54 pm

I have a way to solve these problems :) :
  • Store the object into a variable
    Code: Select all
    object = Scene.addCircle({
            radius := 0.05;
            pos := e.pos;
            color := [1.0, 1.0, 0.0, 1.0];
            drawcake := false;
            drawborder := false
        });
  • Affect custom variables to the object
    Code: Select all
        object.spawnTime := Sim.time;
        object.lifeTime := 5;
        object.fadeStart = object.spawnTime + object.lifeTime;
        object.fadeTime = 1;
  • Affect dynamic variables to the object
    Code: Select all
        object.airFrictionMult = {(Sim.time == 0) ? {NaN} : {1.0}};
        object.color = {[1, 1, 0, (object.fadeStart - Sim.time) / object.fadeTime]};
        object.density = {
            (Sim.time - object.spawnTime < object.lifeTime) ? {} : {
                object.airFrictionMult = 1.0;
                object.color = [0.0, 0.0, 0.0, 0.0];
                object.density = 0.0
            };
            2.0
        }
  • You're done ;)

:!: I use this part of the script because if you save and reopen a scene with dynamics objects, the "object" variable won't exists anymore, then this will delete all dynamics objects :
Code: Select all
    object.airFrictionMult = {(Sim.time == 0) ? {NaN} : {1.0}};


:!: This part of the script is very important when you delete dynamic object because if you don't reset dynamic variables, the script will keep running and after spawning a few more objects algodoo will run very slowly :
Code: Select all
            object.airFrictionMult = 1.0;
            object.color = [0.0, 0.0, 0.0, 0.0];
            object.density = 0.0


Here is the complete example :
Code: Select all
(e)=>{
    object = Scene.addCircle({
        radius := 0.05;
        pos := e.pos;
        color := [1.0, 1.0, 0.0, 1.0];
        drawcake := false;
        drawborder := false
    });
    object.spawnTime := Sim.time;
    object.lifeTime := 5;
    object.fadeStart = object.spawnTime + object.lifeTime;
    object.fadeTime = 1;
    object.airFrictionMult = {(Sim.time == 0) ? {NaN} : {1.0}};
    object.color = {[1, 1, 0, (object.fadeStart - Sim.time) / object.fadeTime]};
    object.density = {
        (Sim.time - object.spawnTime < object.lifeTime) ? {} : {
            object.airFrictionMult = 1.0;
            object.color = [0.0, 0.0, 0.0, 0.0];
            object.density = 0.0
        };
        2.0
    }
}

(you can put this script in the onLaserHit var of a laser to see it working)
REMqb
 
Posts: 15
Joined: Wed Dec 30, 2009 7:51 pm
Location: France

Re: Dynamic properties

Postby Versieon » Thu May 27, 2010 1:33 am

I want to be the first to congratulate you on your awesomeness for figuring this out!!!
:clap:

EDIT
Ive tested this out, and this shows that Algodoo has a definite memory leak or something like that. The % of simulation time went down to less than 10% in less than a minute. Hope this can be fixed also.
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: Dynamic properties

Postby KarateBrot » Thu May 27, 2010 3:24 am

Yeah that's awesome. now after looking at it it's so obvious... but yeah the hard part is to get the idea. great work dude :thumbup:
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Dynamic properties

Postby Dakta » Thu May 27, 2010 9:53 pm

You, sir, are the "winshit", as the young say.
.. ,__,_____
. / __.==--" - - - - - - - - ""
./#(-'
.`-' From http://www.ascii-art.de/. Modded by me to work in Arial. Image
a Mammoth wrote:be boring and interesting.

Mystery wrote:If you were jailbreaker you shouldn't have when't up the 3.1.3
I didn't know you could go up 3.1.3! Thanks Mystery person!
User avatar
Dakta
 
Posts: 417
Joined: Sat Sep 12, 2009 4:36 pm

Re: Dynamic properties

Postby Matten » Fri May 28, 2010 8:32 am

Great!
This will help in some of my projects :thumbup:
Cave Johnson wrote:Do you know who I am? I'm the man who's gonna burn your house down! With the lemons! I'm gonna get my engineers to invent a combustible lemon that burns your house down!
User avatar
Matten
 
Posts: 435
Joined: Mon Apr 05, 2010 2:03 pm
Location: The Netherlands


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest