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

#1 2007-08-14 15:17:33

AngelEyra
Scratcher
Registered: 2007-07-19
Posts: 100+

When Variable Changed

A When Variable Changed Block would be very useful.

eyra


AngelEyra's . MyScratchR . Blog
Think with portals
Sorry, Companion Cube... I didn't mean to...

Offline

 

#2 2007-08-14 16:15:25

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: When Variable Changed

All "when <condition>" or "wait until <condition>" implicitly have a "when <set of variables> changes", so providing a "when <variable> changes" block should be simple.  The main question is whether enough users would find it useful enough (and not too many users would be confused by it).   

I was going to suggest generalizing to a condition: <variable changed>, which would work fine in "wait until" or  "when" blocks, and even makes sense in "repeat until", but would be hard to assign semantics to in "if" blocks.

Offline

 

#3 2007-08-15 06:53:07

Llamalover
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: When Variable Changed

I was thinking theexact same thing! It's in my "I would like..." topic


Be nice, I'm an old lady  wink

Offline

 

#4 2007-08-15 15:25:24

mdusoe
Scratcher
Registered: 2007-06-14
Posts: 32

Re: When Variable Changed

Kevin, my only thought around the implementation is that "variable changed" is an event, or message if you will.  To me, it doesn't belong as a condition, because what you would truly be asking is "If <variable has changed> then...".  I think that a When <variable changes> "hat" block is absolutely reasonable (and a GREAT suggestion), because it is just another way to react to a message of sorts. 

I also don't know how you could use a <variable has changed> criteria, since you have no way of clarifying <variable has changed since when?>

Of course, I have done this using a forever If block:

Forever If not<value = oldValue>
   ...Do Something
  oldValue = value
end loop

By doing it this way, you are able to tell that the value has changed since the last time i looked at it

I think that giving a user the ability to just check "has a value changed?" opens up a concept that the target audience may not be ready for...

Does this make sense?
Mike.

Offline

 

#5 2007-08-15 15:45:40

beny
Scratcher
Registered: 2007-07-24
Posts: 100+

Re: When Variable Changed

It SuRe WoUlD Be HaNdY


more people like the letter B than the letter A!
i'm going for 250 posts!

Offline

 

#6 2007-08-15 16:04:53

AngelEyra
Scratcher
Registered: 2007-07-19
Posts: 100+

Re: When Variable Changed

Let me try to use your language...
YeS I aM sURE.

eYRa


AngelEyra's . MyScratchR . Blog
Think with portals
Sorry, Companion Cube... I didn't mean to...

Offline

 

#7 2007-08-16 23:21:02

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: When Variable Changed

mdusoe, I agree that the semantics for <variable x changed> is not clear in an if statement.  I think that your suggestion that it means "since the last time this condition was checked" is a reasonable semantics---essentially each instance of the <variable x changed> block would create a shadow variable "oldx" and the block would be implemented something like

      <test= x!=old_x,  oldx := x,  return test>

Of course, wait and when blocks could be more efficiently implemented with daemons.

Offline

 

Board footer