Changing Spring Constant On Laser Collide?

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

Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Thu May 16, 2013 4:40 am

I'm wondering how to change a spring's constant with lasers. I know how to do it with spring length, but I don't know the code to do it for constant. any help would be greatly appreciated : )
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby Xray » Sat May 18, 2013 4:30 am

lethalsquirl wrote:I'm wondering how to change a spring's constant with lasers. I know how to do it with spring length, but I don't know the code to do it for constant. any help would be greatly appreciated : )


I don't believe that it's possible because you would need to have collision layers, and springs do not have collision layers. How were you able to change spring length with a laser? I didn't think that was possible either without collision layers!
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sat May 18, 2013 6:07 am

I set spring length to
{
scene.my.lenght
}

and set an object that will collide with laser to
(e)=>{
scene.my.lenght = XX
}

An example of this.
Rating: rated 5
Filesize: 52.59 kB
Comments: 1
Ratings: 1
download


I want to try this again, but have points in the piston stroke where the spring constant goes to 0 to prevent the sloppy movement in between the spring length changes.
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby Someone Else » Sat May 18, 2013 7:46 am

Typing
Code: Select all
constant = {scene.my.constant}

into the spring's script menu didn't work?

The variable for spring length is called "length", and the variable for spring constant is similarly called "constant". You can use exactly the same code structure to control either (or any variable in any object, for that matter) via scene.my variables.

Did you misspell something?
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sat May 18, 2013 4:34 pm

Exactly what I thought, but when I press enter, it just goes clears back to the default value. What's strange is I just realized that
constant = {scene.my.length} actually works, but then the laser collide effects both length and constant at the same time, and I don't want that.
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby Xray » Sat May 18, 2013 6:04 pm

I defined scene.my.constant, and then used it as the variable for the spring's constant, and it works just fine for me. I put a simple script in the laser which increments the constant value while the laser is firing. No problems here!
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sat May 18, 2013 9:19 pm

For some reason when I try to add scene.my.constant to the constant box, I press enter and it just goes back to the default value.
The same thing is now happening with length. I type it in, press enter, and it just goes back to default.
It was just working for length. I'm pretty sure I'm typing it right : /
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sat May 18, 2013 9:21 pm

Could you maybe send me your scene so I can see how you typed it out?
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby Xray » Sun May 19, 2013 1:06 am

lethalsquirl wrote:For some reason when I try to add scene.my.constant to the constant box, I press enter and it just goes back to the default value.
The same thing is now happening with length. I type it in, press enter, and it just goes back to default.
It was just working for length. I'm pretty sure I'm typing it right : /


I believe I know what the problem is. Before you can add {scene.my.constant} to the spring's constant value window, you need to first DEFINE it! So, either in the console, or in the text box in the upper left corner of the script menu, enter scene.my.constant:= 10 ( or whatever initial value that you want to give it).
Then hit Enter. After defining the variable, you should be able to add it to the spring constant value window without it reverting back to the default value. Try that and let me know if it works.
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sun May 19, 2013 1:59 am

Oh man, I totally forgot about that part. It's been a while since I made that first one, I forgot the entire process. I'm still just a thyme noob :oops:
That was my problem all along

Thanks for the help though, I think I got this now :D
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sun May 19, 2013 2:22 am

I'm still a little confused but im not even sure how to explain. so when I define it, how do I then get the spring to change from what I defined it to by lasers. I type scene.my.constant:= 500 for example, then I type {scene.my.constant} in the constant box, and the constant changes to 500 of course, but when I set a box to collide with a laser to onCollide = (e)=>{scene.my.constant = 1}
nothing happens.
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby electronicboy » Sun May 19, 2013 2:40 am

if you're triggering it with a lazer, make sure you're using "OnLaserHit" and not "onCollide"!

OnLaserHit - laser to geom collisions
OnCollide - geom to geom collisions

I can only see that possible issue based on what you have wrote, as the code example works fine.
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sun May 19, 2013 2:57 am

Yep that was the issue. *facepalm* I feel like a total noob. I guess we all gotta learn somehow xD

Thanks for the help! :D
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sun May 19, 2013 3:02 am

One last thing though, is it possible to change the constant, AND length of 1 spring at the same time?
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am

Re: Changing Spring Constant On Laser Collide?

Postby lethalsquirrel » Sun May 19, 2013 3:46 am

Never mind, I figured it out :lol:
User avatar
lethalsquirrel
[ex-squirl]
 
Posts: 54
Joined: Fri Sep 11, 2009 5:03 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests