Problem with division of variables
8 posts • Page 1 of 1
Problem with division of variables
I defined two variables Scene.my.up and Scene.my.time which are updated in update()
Then I tried to get Scene.my.up/Scene.my.time but this is what happened:
> Scene.my.up
847.1
> Scene.my.time
1484.1
> Scene.my.up/Scene.my.time
1
> 847.1/1484.1
0.57078362
That means, I get always 1 when dividing variables, but another number when dividing their values.
The problem seems to lie deeper, because I also get
> math.log(Scene.my.up)
9.38304
> math.log(Scene.my.time)
9.4027033
> math.log(Scene.my.up) - math.log(Scene.my.time)
0
What is wrong?
Thanks in advance
Then I tried to get Scene.my.up/Scene.my.time but this is what happened:
> Scene.my.up
847.1
> Scene.my.time
1484.1
> Scene.my.up/Scene.my.time
1
> 847.1/1484.1
0.57078362
That means, I get always 1 when dividing variables, but another number when dividing their values.
The problem seems to lie deeper, because I also get
> math.log(Scene.my.up)
9.38304
> math.log(Scene.my.time)
9.4027033
> math.log(Scene.my.up) - math.log(Scene.my.time)
0
What is wrong?
Thanks in advance
- hpstricker
- Posts: 16
- Joined: Wed Jan 03, 2018 11:10 am
Re: Problem with division of variables
I find a solution (but why is this necessary?)
First define two dummy variables up = Scene.my.up, time = Scene.my.time.
Then calculate x/y.
This works.
First define two dummy variables up = Scene.my.up, time = Scene.my.time.
Then calculate x/y.
This works.
- hpstricker
- Posts: 16
- Joined: Wed Jan 03, 2018 11:10 am
Re: Problem with division of variables
But the problem doesn't cease to exist:
When using this inside (e)=>{} I get the same wrong result:
(e)=>{
x = Scene.my.up;
y = Scene.my.time;
ratio = x/y;
Console.print(ratio)
}
It is written constantly 1 to the console, even though x, y have different values.
When using this inside (e)=>{} I get the same wrong result:
(e)=>{
x = Scene.my.up;
y = Scene.my.time;
ratio = x/y;
Console.print(ratio)
}
It is written constantly 1 to the console, even though x, y have different values.
- hpstricker
- Posts: 16
- Joined: Wed Jan 03, 2018 11:10 am
Re: Problem with division of variables
Couldn't reproduce. In my case (Algodoo 2.1, Windows) there is no such problem at all.
Anyway, you colud use math.toFloat() to ensure you work with float, not integer variables.
Anyway, you colud use math.toFloat() to ensure you work with float, not integer variables.
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: Problem with division of variables
Hi Kilinich, would you mind having a look at the attached .phn file? The update function is defined for the gray box labeled with 1. On the console you can type Scene.my.up (a float), Scene.my.time (another float) and Scene.my.up/Scene.my.time (integer 1).
Thanks a lot in advance
Hans-Peter
Thanks a lot in advance
Hans-Peter
- Attachments
-
- 9.0.phn
- (55.61 KiB) Downloaded 97 times
- hpstricker
- Posts: 16
- Joined: Wed Jan 03, 2018 11:10 am
Re: Problem with division of variables
OMG
There are many errors in code:
1) Actually Scene.my.up and Scene.my.time has same value (increased every update, but same) so there is no wonder division returns 1
2) You should use := for creating local scope variables, not =
3) You mess up with object type and your scene simple broke after save-load
There are many errors in code:
1) Actually Scene.my.up and Scene.my.time has same value (increased every update, but same) so there is no wonder division returns 1
2) You should use := for creating local scope variables, not =
3) You mess up with object type and your scene simple broke after save-load
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: Problem with division of variables
Sorry, but I don't understand:
1. Scene.my.up = Scene.my.up + (Scene.my.sensor.pos(1) > 3.0 ? 1.0 : 0.0);
Scene.my.time = Scene.my.time + 1.0;
Why do you say it's always the same?
2. Thanks for the hint to use :=, but it didn't help
3. Which messing up of object type do you mean? (And which kind of crash? There has never been a crash for me.)
Please check out Scene.my.up and Scene.my.time on the console: they are definitely NOT the same. But Scene.my.up/Scene.my.time is always 1. That's the problem/bug I am looking for a solution/answer.
Thanks in advance
Hans-Peter
1. Scene.my.up = Scene.my.up + (Scene.my.sensor.pos(1) > 3.0 ? 1.0 : 0.0);
Scene.my.time = Scene.my.time + 1.0;
Why do you say it's always the same?
2. Thanks for the hint to use :=, but it didn't help
3. Which messing up of object type do you mean? (And which kind of crash? There has never been a crash for me.)
Please check out Scene.my.up and Scene.my.time on the console: they are definitely NOT the same. But Scene.my.up/Scene.my.time is always 1. That's the problem/bug I am looking for a solution/answer.
Thanks in advance
Hans-Peter
- hpstricker
- Posts: 16
- Joined: Wed Jan 03, 2018 11:10 am
Re: Problem with division of variables
When I looked at your scene, the ratio only stayed 1 as long as the box was above 3. When I pulled the sensor box down below 3, the ratio decreased. Btw, as a Tip: You dont need math.tofloat when the scene.my.values are already non-integer numbers. I also recommend you to use poststep for your script since update ALWAYS runs, not just when the scene runs. Poststep only runs while the scene runs, once per scene frame.
- FRA32
- Posts: 229
- Joined: Wed Dec 03, 2014 9:51 pm
8 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 2 guests