This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-19 13:13:04

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Var is set to 2.1 but the <[] = []> block returns false when checking?

I have a setup similar to this:

when gf clicked
set [var v] to [0.1]
go to x: (0) y: (3)
point in direction (90 v)
clear
set pen color to (0)
pen down
forever
  move (dir) steps
  turn cw (1) degrees
  if <(direction) = [90]>
    pen up
    change y by (6)
    pen down
    change pen color by (10)
    if <(var) = [2.1]>
      play sound[Pop v]
      stop script
    else
      change [var v] by (0.1)
    end
  end
end
but for some reason, the if block doesn't fire the code inside of it. Any ideas?
EDIT: Just a note, the say block is replaced by code to stop the script and play a sound, but the Scratchblocks BBcode didn't work on it for me for a weird reason.

Last edited by DigiTechs (2012-12-19 14:45:42)


I'm back.
Maybe.

Offline

 

#2 2012-12-19 13:53:50

technoboy10
Scratcher
Registered: 2007-08-25
Posts: 1000+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

Actually, the way you have the script, var is equal to 0.2.  smile


So long, 1.4.
http://goo.gl/3JEV9

Offline

 

#3 2012-12-19 14:30:26

TheScratchCircle
New Scratcher
Registered: 2012-12-17
Posts: 7

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

Because your changing var by 0.1 forever. When it's changing forever, it goes on and on and on. Try this:

when gf clicked
set [var v] to [0.2]
forever
 if (var) = [2.1]
 say [var is more than 2.1!]
 end
end

Offline

 

#4 2012-12-19 14:42:13

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

TheScratchCircle wrote:

Because your changing var by 0.1 forever. When it's changing forever, it goes on and on and on. Try this:

when gf clicked
set [var v] to [0.2]
forever
 if (var) = [2.1]
 say [var is more than 2.1!]
 end
end

*facepalm* I should put my script PROPERLY.


I'm back.
Maybe.

Offline

 

#5 2012-12-19 14:50:58

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

technoboy10 wrote:

Actually, the way you have the script, var is equal to 0.2.  smile

It repeats the loop until var is equal to 2.1, but for some reason the []=[] block seems to only work sith STRINGS.
EDIT: It doesn't even work when comparing to a variable that's set EXACTLY THE SAME!

Last edited by DigiTechs (2012-12-19 14:53:11)


I'm back.
Maybe.

Offline

 

#6 2012-12-19 15:06:39

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

Hmm. Does anyone know at all? Scratch seems to think 2.1 isn't 2.1


I'm back.
Maybe.

Offline

 

#7 2012-12-19 15:10:22

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

Show the variable and see if it ever reaches 2.1


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#8 2012-12-19 16:00:44

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

if nothing else works, just do (var)>2 instead


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#9 2012-12-20 04:32:01

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

Firedrake969 wrote:

Show the variable and see if it ever reaches 2.1

I've already tried that. I've also tried the single stepping mode, and Scratch just skips the if block it's in.


I'm back.
Maybe.

Offline

 

#10 2012-12-20 04:35:15

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

Wes64 wrote:

if nothing else works, just do (var)>2 instead

Yes, it worked. Mabye it's because Scratch is changing the value BEFORE checking, even though I set it to not do that.


I'm back.
Maybe.

Offline

 

#11 2012-12-20 11:42:42

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

It only fires off if the direction = 90.  Maybe it's because of that?


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#12 2012-12-20 11:48:27

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

Firedrake969 wrote:

It only fires off if the direction = 90.  Maybe it's because of that?

No, it's not. Go to my latest project and download it, That's the problem I had it with.


I'm back.
Maybe.

Offline

 

#13 2012-12-21 16:31:51

Freibauer
Scratcher
Registered: 2011-03-30
Posts: 8

Re: Var is set to 2.1 but the <[] = []> block returns false when checking?

The problem might base on loss of precision related to floating point arithmetic.
Try to use integer variables for loop control.

Offline

 

Board footer