Limit Value Range?
7 posts • Page 1 of 1
Limit Value Range?
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:
Thanks!
-Jake
- Code: Select all
TranLims = (tran1)=>{tran1 > 5 ? {tran1 = 5} : {tran1 < 1 ? {tran1 = 1} : {}}};
Thanks!
-Jake
- VFB1210
- Posts: 5
- Joined: Sun Oct 03, 2010 4:48 am
Re: Limit Value Range?
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: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?
- Code: Select all
TranLims = (tran1)=>{tran1 > 5 ? {tran1 = 5} : {tran1 < 1 ? {tran1 = 1} : {}}};
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.
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).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-

tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: Limit Value Range?
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...
Thanks!
--Jake
Thanks!
--Jake
- VFB1210
- Posts: 5
- Joined: Sun Oct 03, 2010 4:48 am
Re: Limit Value Range?
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...![]()
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).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-

tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: Limit Value Range?
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...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Limit Value Range?
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}}
- VFB1210
- Posts: 5
- Joined: Sun Oct 03, 2010 4:48 am
Re: Limit Value Range?
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)
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...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
7 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests



