Reverse motor with scripting

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

Reverse motor with scripting

Postby eeieeio » Mon Dec 11, 2017 3:07 pm

Hello everyone

Just spent an hour searching for an answer. Is it possible to reverse the direction of an existing motor with 'onhitbyLaser' or 'onCollide'?

Dave
eeieeio
 
Posts: 25
Joined: Thu Nov 30, 2017 7:02 pm

Re: Reverse motor with scripting

Postby Kilinich » Tue Dec 12, 2017 10:38 am

Yes, but you need to use scene.my variable or link hinge with trigger object.
scene.my. is simpler:
1) Set in console: scene.my.hingeReverse := false
2) Set in trigger object: onCollide = (e) = {scene.my.hingeReverse = ! scene.my.hingeReverse}
3) Set in hinge: ccw = {scene.my.hingeReverse}

To avoid frequent change you could add timout code like this:
onSpawn = (e) => {sim.time == 0 ? {e.this.holdTime := 0}:{}}
onCollide = (e) => {sim.time < holdTime ? {}:{scene.my.hingeReverse = ! scene.my.hingeReverse; holdTime = sim.time + 0.3}}
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: Reverse motor with scripting

Postby eeieeio » Wed Dec 13, 2017 7:09 am

Thanks Kilinich...worked like a charm
eeieeio
 
Posts: 25
Joined: Thu Nov 30, 2017 7:02 pm

Re: Reverse motor with scripting

Postby eeieeio » Sun Dec 17, 2017 8:43 pm

eeieeio wrote:Thanks Kilinich...worked like a charm


If I want to do this more than once in a single scene to a different motor how would I distinguish between the two. Something like scene.my.hingeReverse2 ?
eeieeio
 
Posts: 25
Joined: Thu Nov 30, 2017 7:02 pm

Re: Reverse motor with scripting

Postby Kilinich » Sun Dec 17, 2017 10:03 pm

eeieeio wrote:
eeieeio wrote:Thanks Kilinich...worked like a charm


If I want to do this more than once in a single scene to a different motor how would I distinguish between the two. Something like scene.my.hingeReverse2 ?


Well, yes, it should do the trick, but there is another way - if hinge connect one of "trigger" geom, you could read info directly from it.
Use "readable" to get values from read-only variables like geom0 and geom1 and scene.entityByGeomID / entityByID to access it's properties.
Attachments
MotorReverseDemo.phz
Entity property access demo
(18.98 KiB) Downloaded 108 times
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: Reverse motor with scripting

Postby eeieeio » Mon Dec 18, 2017 5:50 am

Kilinich,

Thanks for your response. Your attached example was quite generous. I am not advanced enough to utilize your suggestion to achieive my results. I used the scene.my.hingeReverse2 method that I required about instead.
eeieeio
 
Posts: 25
Joined: Thu Nov 30, 2017 7:02 pm

Re: Reverse motor with scripting

Postby eeieeio » Fri Dec 22, 2017 9:55 pm

Kilinich,

You helped me with reversing a motor with onCollide, now I need to apply the brakes to a motor using the same method. I tried scene.my.hingeBrake := false but did not work. Any further help would be appreciated.

eeieeio
eeieeio
 
Posts: 25
Joined: Thu Nov 30, 2017 7:02 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest