loop script

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

loop script

Postby mistiqpiotr » Tue Dec 15, 2015 5:17 pm

Hello.He is trying to make a circle which dies and creates new same circle endlessly. My scrio in circle (e)=>{
Scene.addCircle({
timeToLive := 3;
collideSet := 1;
friction := 0.5;
color := [0.73151445, 0.55123925, 0.21842225, 1.0];
pos := [-0.84514439, 2.6246722];
onDie := (e)=>{};
density := 2.0;
radius := 0.38
})
}



I can made it like x loop coping script like.

(e)=>{
Scene.addCircle({
timeToLive := 3;
collideSet := 1;
friction := 0.5;
color := [0.73151445, 0.55123925, 0.21842225, 1.0];
pos := [-0.84514439, 2.6246722];
onDie := (e)=>{
Scene.addCircle({
timeToLive := 3;
collideSet := 1;
friction := 0.5;
color := [0.73151445, 0.55123925, 0.21842225, 1.0];
pos := [-0.84514439, 2.6246722];
onDie := (e)=>{};
density := 2.0;
radius := 0.38
})
}
density := 2.0;
radius := 0.38
})
}


but i need infinite loop.
Attachments
kopiowanienieskonczonosc.phz
(5.38 KiB) Downloaded 97 times
mistiqpiotr
 
Posts: 7
Joined: Tue Dec 15, 2015 5:06 pm

Re: loop script

Postby T'wind_ » Tue Dec 15, 2015 6:45 pm

Paste this code in the onDie event.
Code: Select all
timeToLive = 3;
Scene.cloneEntityTo(e.this, Pos)
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: loop script

Postby Kilinich » Tue Dec 15, 2015 8:26 pm

Use tmetolive and ondie
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: loop script

Postby T'wind_ » Tue Dec 15, 2015 8:53 pm

If the ball has to be spawned on position [-0.84514439, 2.6246722] you can write this code in the onDie event
Code: Select all
timeToLive = 3;
Scene.cloneEntityTo(e.this, [-0.84514439, 2.6246722])

You also have to remove the code that you have already written in the circle.
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: loop script

Postby mistiqpiotr » Tue Dec 15, 2015 10:01 pm

Thx. :thumbup:
mistiqpiotr
 
Posts: 7
Joined: Tue Dec 15, 2015 5:06 pm

Re: loop script

Postby mistiqpiotr » Wed Dec 16, 2015 4:11 pm

what i if i wanna make it on group? like i have 2 circle in group and when one of it colide make another group with 2 circle?
mistiqpiotr
 
Posts: 7
Joined: Tue Dec 15, 2015 5:06 pm

Re: loop script

Postby FRA32 » Wed Dec 16, 2015 6:19 pm

ondie = (e)=>{
timetolive = 3;
scene.cloneEntityTo(e.this , pos1);
scene.cloneEntityTo(e.this , pos2)
}
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: loop script

Postby mistiqpiotr » Thu Dec 17, 2015 5:23 pm

no it's no't work.
mistiqpiotr
 
Posts: 7
Joined: Tue Dec 15, 2015 5:06 pm

Re: loop script

Postby FRA32 » Thu Dec 17, 2015 9:03 pm

what doesnt work? does the object not reappear after dying? If you wrote the above code, the circle should create 2 clones when triggering the script. If you want it to clone on death, write it in OnDie, if you want it to clone when colliding, write it in OnCollide
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: loop script

Postby mistiqpiotr » Sat Dec 19, 2015 2:50 pm

scripts must be in first circle not on both
mistiqpiotr
 
Posts: 7
Joined: Tue Dec 15, 2015 5:06 pm

Re: loop script

Postby T'wind_ » Sat Dec 19, 2015 3:12 pm

mistiqpiotr wrote:scripts must be in first circle not on both

I don't think that's possible, unless you know the ID of both circles.
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: loop script

Postby mistiqpiotr » Sat Dec 19, 2015 5:11 pm

ok if we know how make it?
mistiqpiotr
 
Posts: 7
Joined: Tue Dec 15, 2015 5:06 pm

Re: loop script

Postby T'wind_ » Sat Dec 19, 2015 6:12 pm

This code might work, although it's a kinda odd way to do it.
Code: Select all
onCollide = (e)=>{
    scene.cloneEntityTo(e.this, [-1, 1]);
    scene.cloneEntityTo(scene.entityByID(<id1>), [1, 1])
}
update = (e)=>{
    (scene.entityByID(<id1>)).onCollide = (e)=>{
        scene.cloneEntityTo(e.this, [1, 1]);
        scene.cloneEntityTo(scene.entityByID(<id2>), [-1, 1])
    }
}

replace <id1> by the entityID of the other circle and <id2> by the entityID of the circle that runs the code
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: loop script

Postby mistiqpiotr » Sat Dec 19, 2015 9:31 pm

ok thx. :thumbup:
mistiqpiotr
 
Posts: 7
Joined: Tue Dec 15, 2015 5:06 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests

cron