Script to brake motor
9 posts • Page 1 of 1
Script to brake motor
Hi,
a few weeks ago Kilinich helped me to reverse a motor using Thyme Scripting. He was very helpful and I was able to accomplish this. I now need to brake a motor using the same technique. I tried adapting his instructions [seen here: viewtopic.php?f=13&t=11976] to fit my new needs but I was unsuccessful. Can anyone help me apply the brakes to a motor using onCollide between two other objects? Thanks
Dave
[eeieeio]
a few weeks ago Kilinich helped me to reverse a motor using Thyme Scripting. He was very helpful and I was able to accomplish this. I now need to brake a motor using the same technique. I tried adapting his instructions [seen here: viewtopic.php?f=13&t=11976] to fit my new needs but I was unsuccessful. Can anyone help me apply the brakes to a motor using onCollide between two other objects? Thanks
Dave
[eeieeio]
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Script to brake motor
While waiting for someone to help with this, I continued to try to answer my own question. Here's what worked for me:
I created a variable in the console scene.my.hingebrake := false
Then in the motor script menu under autoBrake I put scene.my.hingebrake
In the colliding object I put under onCollide , I put scene.my.hingebrake = ! scene.my.hingebrake
This works fine. When the collision occurs the motor stops. when the collision occurs again the motor starts again. There's just one thing I would like to change but can't figure out myself. The way it is now it is working as a toggle ie; on then off then on and so on. I need to use an if statement so that if the motor is braked, the collision will un-brake but if it is already braked, it will do nothing. Subsequently if the motor is already un-braked, the motor will brake, else it will do nothing.
Having trouble with the if statement.
Any help would be appreciated.
Thanks,
Dave
[eeieeio]
I created a variable in the console scene.my.hingebrake := false
Then in the motor script menu under autoBrake I put scene.my.hingebrake
In the colliding object I put under onCollide , I put scene.my.hingebrake = ! scene.my.hingebrake
This works fine. When the collision occurs the motor stops. when the collision occurs again the motor starts again. There's just one thing I would like to change but can't figure out myself. The way it is now it is working as a toggle ie; on then off then on and so on. I need to use an if statement so that if the motor is braked, the collision will un-brake but if it is already braked, it will do nothing. Subsequently if the motor is already un-braked, the motor will brake, else it will do nothing.
Having trouble with the if statement.
Any help would be appreciated.
Thanks,
Dave
[eeieeio]
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Script to brake motor
There is a problem in your logic. Just clear it for youself. What should script do and when?
You said "if the motor is braked, the collision will un-brake but if it is already braked, it will do nothing" - it's nonsence.
You said "if the motor is braked, the collision will un-brake but if it is already braked, it will do nothing" - it's nonsence.
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Script to brake motor
There is a problem in your logic. Just clear it for youself. What should script do and when?
You said "if the motor is braked, the collision will un-brake but if it is already braked, it will do nothing" - it's nonsence.
You said "if the motor is braked, the collision will un-brake but if it is already braked, it will do nothing" - it's nonsence.
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Script to brake motor
The script would run as an onCollide between two circles. The script would run the motor if the brake is on but do nothing if the motor is already running and it will brake the motor if it is running but do nothing if already braked. I know what I'm trying to say but if it still is nonsense to you, as you put it, then maybe someone else can answer.
Thanks, Dave
[eeieeio]
Thanks, Dave
[eeieeio]
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Script to brake motor
"The script would run the motor if the brake is on"
and
"do nothing if already braked"
are not clear how to fit together.
and
"do nothing if already braked"
are not clear how to fit together.
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Script to brake motor
I'll try again
The way my script works now. This is the way I don't want it:
if the motor is currently running and circle a collides with circle b the motor stops
next time circle a collides with circle b the motor runs
next collision the motor stops again, and so on.
here is the script I have now which I adapted from your earlier script to reverse the motor
in circle a I have onCollide = scene.my.hingebrake1 = ! scene.my.hingebrake1
in the motor I have AutoBrake = {scene.my.hingebrake1}
in console I have scene.my.hingebrake1 = true
Here is what I need:
if the motor is currently running and circle a collides with circle b the motor will stop
next time circle a collides with circle b nothing should happen because the motor is already stopped.
If I am still not communicating clearly, I promise not to bother you with this thread any more.
Dave
[eeieeio]
The way my script works now. This is the way I don't want it:
if the motor is currently running and circle a collides with circle b the motor stops
next time circle a collides with circle b the motor runs
next collision the motor stops again, and so on.
here is the script I have now which I adapted from your earlier script to reverse the motor
in circle a I have onCollide = scene.my.hingebrake1 = ! scene.my.hingebrake1
in the motor I have AutoBrake = {scene.my.hingebrake1}
in console I have scene.my.hingebrake1 = true
Here is what I need:
if the motor is currently running and circle a collides with circle b the motor will stop
next time circle a collides with circle b nothing should happen because the motor is already stopped.
If I am still not communicating clearly, I promise not to bother you with this thread any more.
Dave
[eeieeio]
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Script to brake motor
just scene.my.brake = true on collide?
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
9 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 8 guests