Limit Value Range?

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

Limit Value Range?

Postby VFB1210 » Sun Oct 03, 2010 4:57 am

Hey all, I'm trying to make a Thyme gearbox for just for fun, and I'm running into problems. Its supposed to be a manual transmission, and my way of making it work as such is to have a key bound variable, in this case tran1, have a range between 1 and 5; representing, of course, gears 1st through 5th. I have been using this if statement:
Code: Select all
TranLims = (tran1)=>{tran1 > 5 ? {tran1 = 5} : {tran1 < 1 ? {tran1 = 1} : {}}};
to limit tran1's range to between one and five. My problem, it's not working. No matter what I can still make tran1 greater than five and less than one. Can someone please show me a working code and explain to me what I am doing wrong?

Thanks!
-Jake
VFB1210
 
Posts: 5
Joined: Sun Oct 03, 2010 4:48 am

Re: Limit Value Range?

Postby tatt61880 » Sun Oct 03, 2010 6:21 am

VFB1210 wrote:Hey all, I'm trying to make a Thyme gearbox for just for fun, and I'm running into problems. Its supposed to be a manual transmission, and my way of making it work as such is to have a key bound variable, in this case tran1, have a range between 1 and 5; representing, of course, gears 1st through 5th. I have been using this if statement:
Code: Select all
TranLims = (tran1)=>{tran1 > 5 ? {tran1 = 5} : {tran1 < 1 ? {tran1 = 1} : {}}};
to limit tran1's range to between one and five. My problem, it's not working. No matter what I can still make tran1 greater than five and less than one. Can someone please show me a working code and explain to me what I am doing wrong?

Thanks!
-Jake


At first, when you declare new variable, I recommend to name your variable as "Scene.my.***" (For example, Scene.my.TranLims).
This is not only for your script but for every scripts.
When you declared TransLims (without Scene.my.), the variable will be saved on config.cfg not in scene file. :|

Your code doesn't work because your code doesn't mean changing real trans1 (argument) but changing pseud trans1 (parameter) in your function.

== Exact code of the function and how to use it ==
1) Declare the next function.
Code: Select all
Scene.my.TranLims = (tran_)=>{tran_ > 5 ? {5} : {tran_ < 1 ? {1} : {tran_}}};

Note: tran_ is a parameter for this function. ;)

2) Declare your variable, for example "Scene.my.tran1".
Code: Select all
Scene.my.tran1 = 10;


3) The function "Scene.my.TranLims" can be used as below.
Code: Select all
Scene.my.tran1 = Scene.my.TranLims(Scene.my.tran1)

The code above substitute 5 for "Scene.my.trans1" (because 10 > 5).

I hope my explanation is OK. :)
-Tatt

P.S.
Welcome to this forum. :thumbup:
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan

Re: Limit Value Range?

Postby VFB1210 » Thu Oct 07, 2010 4:36 am

Hey, thanks for the help and the welcome! Sorry I haven't been able to reply for a while, I've been busy with school work. I appreciate the help, but I'm still not entirely understanding what I am supposed to do, and my attempts to figure it out on my own aren't working. Could you tell me the exact code I should use? Assuming that the variable I am using is Scene.my.Tran1, so this time it gets saved to the scene... :lol:

Thanks!
--Jake
VFB1210
 
Posts: 5
Joined: Sun Oct 03, 2010 4:48 am

Re: Limit Value Range?

Postby tatt61880 » Thu Oct 07, 2010 10:17 am

VFB1210 wrote:Hey, thanks for the help and the welcome! Sorry I haven't been able to reply for a while, I've been busy with school work. I appreciate the help, but I'm still not entirely understanding what I am supposed to do, and my attempts to figure it out on my own aren't working. Could you tell me the exact code I should use? Assuming that the variable I am using is Scene.my.Tran1, so this time it gets saved to the scene... :lol:

Thanks!
--Jake


I've edit my post for exact code. ;)
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan

Re: Limit Value Range?

Postby Kilinich » Thu Oct 07, 2010 3:33 pm

I've use this one:

Code: Select all
scene.my.minmax = (x,min,max) => {x < min ? min : {x > max ? max : x}}
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: Limit Value Range?

Postby VFB1210 » Thu Oct 07, 2010 11:12 pm

Thanks, but I'm still having trouble. Every time I enter the code
Code: Select all
scene.my.minmax = (Scene.my.Tran1,1,5) => {Scene.my.Tran1 < 1 ? 1 : {Scene.my.Tran1 > 5 ? 5 : Scene.my.Tran1}}
it tells me that there is a parse error and that I'm missing a period somewhere. :crazy:
VFB1210
 
Posts: 5
Joined: Sun Oct 03, 2010 4:48 am

Re: Limit Value Range?

Postby Kilinich » Fri Oct 08, 2010 3:02 pm

You get all wrong.
I've give you code for declare function scene.my.minmax, which you can use in your scripts...

for example:

scene.my.minmax (15, -1,10)
gives you 10

scene.my.minmax (-15, -1,10)
gives you -1

scene.my.minmax (5.4, -1,10)
gives you 5.4

if you want to increase value to the limit just enter
scene.my.value = scene.my.minmax (scene.my.value+1, 0, 100)
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


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests