Once a certain value is reached, change a different value

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

Once a certain value is reached, change a different value

Postby royalblue » Sat Jun 12, 2010 9:28 am

I'm making an automatic transmission and I need a way to make it upshift once it has reached a certain speed but only once until the rpm's come back up again

currently i have a circle with an oncollide script but that sometimes gets hit multiple times which ends up shifting too many or making the collision set too large for the gears I have set out. basically how i have it is 4 circles in a target shape and for 1st gear, for example, the smallest ring on the left + the largest ring on the right have a collision menu of A, and then you just work towards the inside/outside of the circles till you get to the largest gear ratio which is collision menu D. I have a circle with strong springs connected to it's center and you can manually change the gears by using the arrows of the collision menu, but I want this to be fully automated. Since collision values are in binary i currently have it set to (current collide set) * 2 each time it hits. Once it hits the RPM's shoot down until you accelerate more but like I said sometimes it hits 2 or more times which screws it all up. I wish thyme would just work with collide sets of A, B, C, etc rather than exponents of 2. Is there a thyme equivalent to the "shift collision sets down" arrows in the collision menu?
royalblue
 
Posts: 14
Joined: Mon Aug 31, 2009 9:22 pm

Re: Once a certain value is reached, change a different value

Postby Rideg » Sat Jun 12, 2010 4:27 pm

I didn't get the text alright but Do you need something like this?
Code: Select all
scene.my.value1 == x ? {scene.my.value2 = y}:{}


X = value that it should reach.
Y = the number an other value should change to.
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: Once a certain value is reached, change a different value

Postby Mr_Stabby » Mon Jun 14, 2010 6:47 am

2 things u need really

1: a decent speedometer - on sides of the circle producing the spin put 2 large boxes, and i mean atleast as large as the circle (they dont have to be wide tho just long if you know what i mean), on both boxes first set a condition in which u put ur script something like e.laser.maxrays==1021?{script here}:{}, this isnt absolutely necessary but will prevent alot of mess when dealing with multi laser open systems. After this in first box make a script e.laser.collideSet=a and in the other e.laser.collideset=b and then place a laser somewhere on the spinning circle with maxrays and initial collideset as previously specified. This serves as the main structure and gives you 2 things: the boxes are big so the laser wont miss them at high speed and alternating collides with specified laser gives u cpu efficiency since the laser only hits each box once on each pass. After this you can put a simple rotation frequency script in either of the boxes or the laser if you like that would control the gearbox. Something like textcolor=[textcolor(0)/3*2+textcolor(1)-sim.time/3, sim.time, 0, 0] should do (will give you the average rotation period of last 3 turns which you can turn to frequency via someconst/textcolor(0) if you like).

2: gear change mechanism - again to avoid the mess stick an ID on the script laser in a generally useless variable like color or maxrays, then just make a laser that collides with everything except 1 layer. Have the laser be in that layer by default (less laser hits less performance hit). Now if you previously put the speedometer script in one of the boxes this is a convenient way to also trigger the chain, when a certain spin speed is achieved have it change its collideset to the rest collide of the gearchange laser and add a script like e.laser.maxrays=gearchangelaserid ? {e.laser.collideset=everything but rest; collideset=switch back to default; e.laser.CHCollide:=collide required of the gears}:{} and then just have the gear changing laser to appropriately id and change collides for the needed gears and eventually swapping back to its rest collide by either timer or a target that will be reached after all else has been hit
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests

cron