Variable = "Speed Level"
There is a sprite which is like a bar with 6 costumes (A.B,C,D,E,F)
When Speed Level = 2 then costume of bar = A
When Speed Level = 2.1 then costume of bar = B
When Speed Level = 2.2 then costume of bar = C
When Speed Level = 2.3 then costume of bar = D [This is where the problem happens]
Speed levels 2 through to 2.2 always appear as "true" when checked but when speed level equals 2.3 it says it is false when checked, despite the number being CLEARLY 2.3 when looked at.
Any help would be appreciated.
Offline
acedannyk wrote:
Variable = "Speed Level"
There is a sprite which is like a bar with 6 costumes (A.B,C,D,E,F)
When Speed Level = 2 then costume of bar = A
When Speed Level = 2.1 then costume of bar = B
When Speed Level = 2.2 then costume of bar = C
When Speed Level = 2.3 then costume of bar = D [This is where the problem happens]
Speed levels 2 through to 2.2 always appear as "true" when checked but when speed level equals 2.3 it says it is false when checked, despite the number being CLEARLY 2.3 when looked at.
Any help would be appreciated.
What I'm thinking is that your script might be the problem, so could I see all of your script?
Offline
Instead of testing for specific decimal numbers, try multiplying by 10 and checking integers.
set [MyVar v] to (2.1) if <((MyVar) * (10)) = (21)> switch to costume [A v] endOr, subtract to test the difference
set [MyVar v] to (2.1) if <([abs v] of ((MyVar) - (2.1))) < (0.001)> switch to costume [A v] end
Last edited by BoltBait (2012-10-24 18:44:32)
Offline
BoltBait wrote:
Instead of testing for specific decimal numbers, try multiplying by 10 and checking integers.
set [MyVar v] to (2.1) if <((MyVar) * (10)) = (21)> switch to costume [A v] endOr, subtract to test the differenceset [MyVar v] to (2.1) if <abs(((MyVar) - (2.1))) < (0.001)> switch to costume [A v] end
um,what's with the "x 10" ?
Offline
BoltBait wrote:
Instead of testing for specific decimal numbers, try multiplying by 10 and checking integers.
set [MyVar v] to (2.1) if <((MyVar) * (10)) = (21)> switch to costume [A v] endOr, subtract to test the differenceset [MyVar v] to (2.1) if <([abs v] of ((MyVar) - (2.1))) < (0.001)> switch to costume [A v] end
Fixed.
Offline
ErnieParke wrote:
BoltBait wrote:
Instead of testing for specific decimal numbers, try multiplying by 10 and checking integers.
set [MyVar v] to (2.1) if <((MyVar) * (10)) = (21)> switch to costume [A v] endOr, subtract to test the differenceset [MyVar v] to (2.1) if <([abs v] of ((MyVar) - (2.1))) < (0.001)> switch to costume [A v] endFixed.
Thanks, Ernie. I can never figure out some of the more obscure blocks.
You should edit the scratch wiki and put more examples in there. I would do it, but I can't remember my password.
Last edited by BoltBait (2012-10-24 18:50:39)
Offline
BoltBait wrote:
ErnieParke wrote:
BoltBait wrote:
Instead of testing for specific decimal numbers, try multiplying by 10 and checking integers.
set [MyVar v] to (2.1) if <((MyVar) * (10)) = (21)> switch to costume [A v] endOr, subtract to test the differenceset [MyVar v] to (2.1) if <([abs v] of ((MyVar) - (2.1))) < (0.001)> switch to costume [A v] endFixed.
Thanks, Ernie. I can never figure out some of the more obscure blocks.
You should edit the scratch wiki and put more examples in there. I would do it, but I can't remember my password.
I would like to do that, but I don't have an account on the Scratch Wiki, which makes me wonder... I found out how.
Anyway, I've also found some blocks to be hard to recall at times, so to figure out their code, I often would quickly open Scratch or hunt through the scratchblocks testing area for an example. Anyhow, your welcome!
Offline
It can operate fine when the numbers are integers but that's not how it should be, I need it to use decimals. The script can recognise when the variable is 2 and switch to the corresponding costume, likewise for 2.1 and 2.2. When it gets to 2.3 however, it does not work, though the visual variable bar in the project screen says 2.3. Clicking on the script asking whether or not it is 2.3 shows that it is false, also. This is pretty odd and I cannot find any fault with anything.
I've used Scratch for a long time, not even the text glitch is this is irritating.
Last edited by acedannyk (2012-10-25 12:40:12)
Offline
Try using this before changing the sprite's costumes:
set [variable v] to ((round ((variable) * (10)))/(10))Does it work now?
Offline
Sorry, here is a look of what is fundamentally wrong
Last edited by acedannyk (2012-10-25 16:06:35)
Offline
ErnieParke wrote:
BoltBait wrote:
You should edit the scratch wiki and put more examples in there. I would do it, but I can't remember my password.
I would like to do that, but I don't have an account on the Scratch Wiki, which makes me wonder... I found out how.
Found my password and added the math blocks to the wiki.
Offline
I put it in and Scimonster removed it again saying "why should math blocks get a section to themselves? They shouldn't."
Obviously, I disagree.
But, he's a mod and I'm not. So, I guess, I lose.
Offline