jd678
|
  |
| Joined: 18 Apr 2008 |
| Total Posts: 11529 |
|
|
| 05 Feb 2014 11:01 PM |
if Gear >=5 and Gear < 7 then Gear = Gear + 0.1 updateForce() updateGui() end
'Gear' will go up to 7.1 NOT 7(What it is supposed to do) THEN stop at 7.1? |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 05 Feb 2014 11:06 PM |
| Could you tell me what your trying to do here exactly? Give us more of the script? 'Gear' isn't even defined as far as we know |
|
|
| Report Abuse |
|
|
jd678
|
  |
| Joined: 18 Apr 2008 |
| Total Posts: 11529 |
|
|
| 05 Feb 2014 11:16 PM |
the full script is a couple hundred lines.
Gear is defined in the script, but here is an example script:
--LocalScript Mouse = game.Players.LocalPlayer:GetMouse() Gear = 5
Mouse.KeyDown:connect(function(key) if key == "e" then if Gear >=5 and Gear < 7 then Gear = Gear + 0.1 updateForce() updateGui() else end end end) |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 05 Feb 2014 11:20 PM |
| I don't see anything wrong with this.. if the Gear's value was 7 then according to the script .1 should be added and you're saying it ends up as 7.1, check if every situation's Gear value that your testing is 7..? |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2014 11:23 PM |
It isn't just his script this is replicated in this script of mine:
x = 5 while (x >= 5 and x < 7) do x = x + .1 print(x) end
... Here is my explanation. Lua encounters a weird error when dealing with for example .1, .3, .7 etc. I can't say for sure why. but your best bet would be:
while (x >= 5) do x = x + .1 if x > 7 then x = 7 break end
end |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 05 Feb 2014 11:26 PM |
| ^Only other solution I can think to be viable, I'd go with it. |
|
|
| Report Abuse |
|
|
jd678
|
  |
| Joined: 18 Apr 2008 |
| Total Posts: 11529 |
|
|
| 06 Feb 2014 12:25 AM |
| Alright, I figured that'd be my Plan B if nothing could be fixed. The explanation was nice though, thanks! |
|
|
| Report Abuse |
|
|
iYoshiFox
|
  |
| Joined: 14 Apr 2012 |
| Total Posts: 1058 |
|
|
| 06 Feb 2014 01:05 AM |
| If it goes up 0.1 more than it should.. Why not end it at 6.9, then have another if statement to see if it is 7? |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 06 Feb 2014 01:13 AM |
I'm guessing this is a floating point error... 6.99999999999999999999999999999999999999999999 < 7 +0.1 --not quite .1, but a bit more -> 7.1 Therefore... |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 06 Feb 2014 01:14 AM |
Therefore a different solution is
if Gear/10 >= 5 and Gear/10 < 7 then Gear = Gear + 1 ._. |
|
|
| Report Abuse |
|
|
252Taylor
|
  |
| Joined: 02 Apr 2012 |
| Total Posts: 1316 |
|
| |
|
jd678
|
  |
| Joined: 18 Apr 2008 |
| Total Posts: 11529 |
|
|
| 06 Feb 2014 02:42 AM |
| ella what r u doing here x3 |
|
|
| Report Abuse |
|
|
252Taylor
|
  |
| Joined: 02 Apr 2012 |
| Total Posts: 1316 |
|
|
| 06 Feb 2014 04:01 AM |
| idk i just saw ur name here and clicked |
|
|
| Report Abuse |
|
|