[SOLVED] Change CollideSet with "OnHitByLaser"

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

[SOLVED] Change CollideSet with "OnHitByLaser"

Postby nylan » Thu May 06, 2010 10:25 pm

Hi,

I would like to change the collideSet of my geometry after a laserhit.

I tried to test with :

OnHitByLaser = (e)=>{e.this.collideSet = 2}

but it didn't work ...

In the end, I would like to do :

- CollideSet = 9
- Laser hit -> CollideSet = 2
- Laser hit -> CollideSet = 9
- Laser hit -> CollideSet = 2
...
...etc

Thank you.
( Screen in attachment )
Attachments
Sans titre.jpg
(66.38 KiB) Not downloaded yet
Last edited by nylan on Sat May 08, 2010 1:11 pm, edited 1 time in total.
nylan
 
Posts: 11
Joined: Fri Apr 16, 2010 4:23 pm

Re: Change CollideSet with "OnHitByLaser"

Postby Rideg » Thu May 06, 2010 11:13 pm

In onLaserHit It's not "this" and "other". it's "geom" and "laser".
Code: Select all
(e)=>{e.geom.collideSet}
night!
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: Change CollideSet with "OnHitByLaser"

Postby Matten » Fri May 07, 2010 10:32 am

For the 9 3 9 3 etc. you have to use an if-statement. This is the code for OnHitByLaser of the box
Code: Select all
(e)=>{e.geom.collideSet == 9 ? {e.geom.collideSet := 3}:{e.geom.collideSet := 9}}

Or the "reversed" way:
Code: Select all
(e)=>{e.geom.collideSet == 3 ? {e.geom.collideSet := 9}:{e.geom.collideSet := 3}}
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

Re: Change CollideSet with "OnHitByLaser"

Postby nylan » Fri May 07, 2010 4:54 pm

Hello,

Rideg, thank you for this, I'll know this know.

Matten, Thank you too, it's a nice script but the collision layer is switching too fast.

I used this script for a geometry, pointing a laser on it :

http://www.youtube.com/watch?v=iTcudAJ3714

I would like a "pause" before re-switch for about 2sec, is it possible ?

Thank you.
nylan
 
Posts: 11
Joined: Fri Apr 16, 2010 4:23 pm

Re: Change CollideSet with "OnHitByLaser"

Postby Matten » Fri May 07, 2010 5:12 pm

That the collision script changes to fast is simple: the laser fires every sec. 10000 "beams" or something like that, so every 0.0001 sec. the script is executed. If you want to make a "wait" option the only thing I can think of is this:

Make a variable named something like scene.my.wait and give it the value (beams per sec.×the number of seconds wait). And put the following code into the box (onHitByLaser)
Code: Select all
(e)=>{scene.my.wait == 0 ? {e.geom.collideSet == 9 ? {e.geom.collideSet := 3}:{e.geom.collideSet := 9}; scene.my.wait := 20000}:{scene.my.wait := scene.my.wait - 1}}

I think that you can find in the config the number of beams a laser fires per sec.

Edit I think I have found the beams per sec. In the config you can find a "maxfps" with the value 60. And a beam is fired every frame, so the value you have to give to scene.my.wait is 60×the number of sec.
Here the edit of the code (with 2 sec. waiting)
Code: Select all
(e)=>{scene.my.wait == 0 ? {e.geom.collideSet == 9 ? {e.geom.collideSet := 3}:{e.geom.collideSet := 9}; scene.my.wait := 120}:{scene.my.wait := scene.my.wait - 1}}

Don't forget to declare scene.my.wait in the console first! (with value 120!)
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

Re: Change CollideSet with "OnHitByLaser"

Postby Rideg » Fri May 07, 2010 5:47 pm

That's overcomplicated here's an easy way that i use almost every time I script. first you set the controllerAcc to 0. Then you type
Code: Select all
(e)=>{
    (sim.time - e.geom.controllerAcc) >= 2 ? {
        e.geom.collideSet == 9 ? {e.geom.collideSet := 3} : {e.geom.collideSet := 9};
        e.geom.controllerAcc = sim.time
    } : {}
}
This will change the collideSet and wait 2 second before it changes back and do it all over (I've tested it) Hope this helped ;)
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: Change CollideSet with "OnHitByLaser"

Postby Matten » Fri May 07, 2010 6:02 pm

The way Rideg used is better, because in his code it really switches every 2 sec. I've tested my script and that isn't every 2 sec. (but if you want an interval that isn't in sec. you can use my method)
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

Re: Change CollideSet with "OnHitByLaser"

Postby nylan » Sat May 08, 2010 12:12 am

I tried yours Matten, it's working, and i can do a fine tune for this timer :)

Rideg, I think yours is good too bug i don't know how to set controllerAcc to 0 :roll:

I'm a newbie in scripting :mrgreen:
nylan
 
Posts: 11
Joined: Fri Apr 16, 2010 4:23 pm

Re: Change CollideSet with "OnHitByLaser"

Postby Rideg » Sat May 08, 2010 1:06 pm

Select an object click geometry controller and drag the bar to 0.
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: Change CollideSet with "OnHitByLaser"

Postby nylan » Sat May 08, 2010 1:11 pm

Damn I thought you were talking about other setting :lol:

Thank you again :thumbup:
nylan
 
Posts: 11
Joined: Fri Apr 16, 2010 4:23 pm

Re: [SOLVED] Change CollideSet with "OnHitByLaser"

Postby Rideg » Sat May 08, 2010 8:21 pm

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


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests

cron