Oncollide Scripting

Discuss things about Phun that don't fit into the other forums.

Oncollide Scripting

Postby Rhett97 » Tue Sep 01, 2009 4:21 am

Well since I dont know if they are gonna move the forums im gonna start RE-posting Important topics.

[From: Physics.Dude]
I put together a little guide of oncollide scripting since I always see people asking how to do this. So here it is
and if you need to change values just mess with the numbers, letters, or true and false.


Water Spawner
(e)=>{Scene.addWater({vecs = [e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos, e.pos]})}

Circle Spawner
(e)=>{scene.addCircle({ radius := 0.1; density := 2.0; restitution := 0.5; friction := 0.5; pos := e.pos }) };

Box Spawner
(e)=>{ Scene.addBox({size := [0.83575642, 0.27858579]; density := 2.00; pos := e.pos; restitution := 0.5; friction = 0.5; angle := 0}) }

----------------------------------------------------------------------------------------------------------------------------------

Self Collision
(e)=>{heteroCollide = false;}

Collide water
(e)=>{collideWater = true }

----------------------------------------------------------------------------------------------------------------------------------

Shape color([R,G,B,A] 0-255)
(e)=>{color = [1.0, 0.0, 0.0, 1.0]}

Text Color ([R,G,B,A] 0-255)
(e)=>{textColor = [1.0, 0.0, 0.0, 1.0]}

Text Size
(e)=>{textScale = 3;}

----------------------------------------------------------------------------------------------------------------------------------

Density
(e)=>{density = 10.02;}

Repel
(e)=>{attraction = - 20;}

Attract
(e)=>{attraction = 50;}

Killer
(e)=>{killer = true }

----------------------------------------------------------------------------------------------------------------------------------

"Anti-Gravity"
(e)=>{Sim.gravityAngleOffset = 3.1415927;}

Pause Sim
(e)=>{sim.running = false;}

Change Zoom
(e)=>{scene.camera.zoom = 17.700001}

change Camra Pan
(e)=>{scene.camera.pan = [ - 446, 14.6];}

----------------------------------------------------------------------------------------------------------------------------------

Set destroy key (With spawned objects)
buttonDestroy := "e"

Set collision (With spawned objects)
collideSet := 0;

Add Text (With spawned objects)
text := "Hello World!"

----------------------------------------------------------------------------------------------------------------------------------

If you wish to use more than one script in an object then the format should be as follows
Say you want to combine (e)=>{attraction = 50;} and (e)=>{color = [1.0, 0.0, 0.0, 1.0]}
You would write it as… note the semicolon and spaces.
(e)=>{ attraction = 50; color = [1.0, 0.0, 0.0, 1.0]}
Chronos wrote:There's nothing wrong with swearing. They're just words. People just think they have a bad meaning. What's the difference between shit and poo? Nothing. They're the same.
User avatar
Rhett97
 
Posts: 522
Joined: Mon Aug 31, 2009 10:32 pm

Re: Oncollide Scripting

Postby Torpedo » Tue Sep 01, 2009 8:50 pm

Nice post. is it possible to spawn fixates or hinges as well though?
Image
User avatar
Torpedo
 
Posts: 120
Joined: Mon Aug 31, 2009 8:51 pm

Re: Oncollide Scripting

Postby Rhett97 » Tue Sep 01, 2009 10:48 pm

Yes Niffirg i think made a Fixate spawner but since its on collision spawning it would spawn in the TINY space between the two objects to it would instantly delete
Chronos wrote:There's nothing wrong with swearing. They're just words. People just think they have a bad meaning. What's the difference between shit and poo? Nothing. They're the same.
User avatar
Rhett97
 
Posts: 522
Joined: Mon Aug 31, 2009 10:32 pm

Re: Oncollide Scripting

Postby Chronos » Tue Sep 01, 2009 11:49 pm

shouldnt this be in the thyme section? ;)
TheWinkits wrote:They both looks of cuking amazing
User avatar
Chronos
[Most Active Member 2010]
 
Posts: 4457
Joined: Mon Aug 31, 2009 6:00 pm
Location: Californania

Re: Oncollide Scripting

Postby Rhett97 » Wed Sep 02, 2009 12:23 am

no because it was made in 5.28 and algodoo might have changed some code
Chronos wrote:There's nothing wrong with swearing. They're just words. People just think they have a bad meaning. What's the difference between shit and poo? Nothing. They're the same.
User avatar
Rhett97
 
Posts: 522
Joined: Mon Aug 31, 2009 10:32 pm

Re: Oncollide Scripting

Postby Mystery » Thu Sep 03, 2009 1:42 pm

I think it should go here, algodoo is like an alien to phun and if there's anything we know about aliens it's that they are short green guys with ray guns.
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: Oncollide Scripting

Postby electronicboy » Thu Sep 03, 2009 2:05 pm

dont forget the probes :lol:
this will help a lot of people!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Oncollide Scripting

Postby CrystalCube » Tue Oct 13, 2009 2:31 am

This just made my life a whole lot easier!!! I used to have to make logical guesses and try again and again!
I'm not CrystalCube anymore.
User avatar
CrystalCube
 
Posts: 35
Joined: Sat Sep 26, 2009 11:48 pm
Location: Poulsbo WA

Re: Oncollide Scripting

Postby EPR_89 » Mon Dec 14, 2009 10:05 pm

Is there a code that can be used to cahnge the simulation time?
User avatar
EPR_89
 
Posts: 19
Joined: Thu Sep 10, 2009 1:14 pm
Location: Germany

Re: Oncollide Scripting

Postby standardtoaster » Mon Dec 14, 2009 10:32 pm

Changing the value of sim.time? No. Sim.time is a constant value and you cannot change it.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Oncollide Scripting

Postby sheepborg » Fri Dec 18, 2009 11:43 pm

how do you script springs to make them change length
i cant make the variable thing stay in the length box of the spring script menu
BTC: 12wcLxBejr6rhCk6WPyVSNmkjwwbxXEvBG
LTC: LQ17UdL71xzLCprSfkoWUQXDXWuHjx2nf9
FTC: 6nfbPuFbtk8uNokYSsVfbzc5393ggxNGDC

polygons > textures

STUFFES:
http://www.algodoo.com/algobox/profile.php?id=4540
User avatar
sheepborg
 
Posts: 203
Joined: Sat Dec 05, 2009 10:44 pm
Location: North Carolina USA

Re: Oncollide Scripting

Postby Chronos » Fri Dec 18, 2009 11:57 pm

sheepborg wrote:how do you script springs to make them change length

You can't
sheepborg wrote:i cant make the variable thing stay in the length box of the spring script menu

Press enter when you're done typing. If you mean that it disappears after a while, it happens to everyone.
TheWinkits wrote:They both looks of cuking amazing
User avatar
Chronos
[Most Active Member 2010]
 
Posts: 4457
Joined: Mon Aug 31, 2009 6:00 pm
Location: Californania

Re: Oncollide Scripting

Postby standardtoaster » Sat Dec 19, 2009 1:50 am

Chronos wrote:
sheepborg wrote:how do you script springs to make them change length

You can't

Yes you can. :|

Make a variable.
Code: Select all
scene.my.length = 1

In the length part of the script menu of the spring(remember to press enter when you are done) put:
Code: Select all
{scene.my.length}

Now, whenever you change the variable scene.my.length, the length of the spring will change.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Oncollide Scripting

Postby Chronos » Sat Dec 19, 2009 3:47 am

Oh, he said springs. >.< I thought he said "script things."
TheWinkits wrote:They both looks of cuking amazing
User avatar
Chronos
[Most Active Member 2010]
 
Posts: 4457
Joined: Mon Aug 31, 2009 6:00 pm
Location: Californania

Re: Oncollide Scripting

Postby standardtoaster » Sat Dec 19, 2009 4:29 am

Even that way, you can. :)
Code: Select all
e.other.onCollide = e.this.onCollide


:D
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Oncollide Scripting

Postby matt28 » Thu Dec 24, 2009 8:37 pm

Chronos wrote:
sheepborg wrote:how do you script springs to make them change length

You can't
sheepborg wrote:i cant make the variable thing stay in the length box of the spring script menu

Press enter when you're done typing. If you mean that it disappears after a while, it happens to everyone.

what non-sense!!!
about that script springs to make them change length thing it's possible!
1. make a spring.
2. press F11
3. A thing with words would pop up at the top of the program
4. type in a variable
5. give the variable a value (number)
6. press F11 to close it
7. make sure you're on advanced mode
8. click the spring and go into script menu
9. in "springLength = (number)" or something similar, change the number to scene.my.(whatever variable you named it) and put it in a {} bracket and press enter.
10. whatever value you give the variable like 30, your spring length will be 30m.
more about scripting...
a variable is like a memory chip, if you prss F11 that thing that pops up is called the variable console and you can type in all the variables you want. so if you type scene.my.g = 10 in the variable console the variable scene.my.g will hold a value of 10.. to be continued...
matt28
 
Posts: 7
Joined: Wed Dec 23, 2009 11:19 pm

Re: Oncollide Scripting

Postby Chronos » Thu Dec 24, 2009 9:55 pm

matt28 wrote:
Chronos wrote:
sheepborg wrote:how do you script springs to make them change length

You can't
sheepborg wrote:i cant make the variable thing stay in the length box of the spring script menu

Press enter when you're done typing. If you mean that it disappears after a while, it happens to everyone.

what non-sense!!!
about that script springs to make them change length thing it's possible!
1. make a spring.
2. press F11
3. A thing with words would pop up at the top of the program
4. type in a variable
5. give the variable a value (number)
6. press F11 to close it
7. make sure you're on advanced mode
8. click the spring and go into script menu
9. in "springLength = (number)" or something similar, change the number to scene.my.(whatever variable you named it) and put it in a {} bracket and press enter.
10. whatever value you give the variable like 30, your spring length will be 30m.
more about scripting...
a variable is like a memory chip, if you prss F11 that thing that pops up is called the variable console and you can type in all the variables you want. so if you type scene.my.g = 10 in the variable console the variable scene.my.g will hold a value of 10.. to be continued...


Chronos wrote:Oh, he said springs. >.< I thought he said "script things."



Learn to read. I already know about scripting, so don't try to teach or lecture me about it. Just stop being a forum noob and actually learn about me before making assumptions.
TheWinkits wrote:They both looks of cuking amazing
User avatar
Chronos
[Most Active Member 2010]
 
Posts: 4457
Joined: Mon Aug 31, 2009 6:00 pm
Location: Californania

Re: Oncollide Scripting

Postby sheepborg » Fri Jan 01, 2010 10:29 pm

by the time i got back to this page i have already gotten the scripting stuff down

the problem was that i forgot to set the custom variable before trying to type it int the spring's length box
thanks for the help even if i didnt use it! :wtf:
BTC: 12wcLxBejr6rhCk6WPyVSNmkjwwbxXEvBG
LTC: LQ17UdL71xzLCprSfkoWUQXDXWuHjx2nf9
FTC: 6nfbPuFbtk8uNokYSsVfbzc5393ggxNGDC

polygons > textures

STUFFES:
http://www.algodoo.com/algobox/profile.php?id=4540
User avatar
sheepborg
 
Posts: 203
Joined: Sat Dec 05, 2009 10:44 pm
Location: North Carolina USA


Return to Phun Edition in general

Who is online

Users browsing this forum: No registered users and 5 guests