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

#1 2010-10-16 09:43:35

helpwithcs
Scratcher
Registered: 2010-02-17
Posts: 3

Inconsistent behavior when using a variable inside touching block

I have come across an issue that I need help with. The code that I'm using is:

http://scratch.mit.edu/projects/helpwithcs/1356457

The program above uses a sprite (called dot) to measure the height and width of another sprite (bottomNum). When this program runs locally, I'm able to move dot to the centre of my bottomNum sprite in order to start measuring. When run over the web, the program is unable to find the location of bottomNum using:

[blocks]x position of <{ measureObject }>[/blocks]

I use global variables as a workaround to for the x & y coordinates of the object that I want to measure.

I'm fine with having additional variables, but now I would like to move my dot sprite from the centre of the bottomNum sprite to the edge. I'm able to do this using the touching block. The code works fine locally, but, again, when run over the web it fails to detect the collision between the two sprites when using the following:

[blocks] <touching[ <{ measureObject }> ]pressed?> [/blocks]

In the code above the height routine works because I don't use variables in the touching block. I would, however, like the routine to work like the width routine. Unfortunately, the width routine only works locally.

Any help with this would be greatly appreciated. Thanks.

Offline

 

#2 2010-10-16 10:54:49

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Inconsistent behavior when using a variable inside touching block

I suspect that your trouble is with the way the online player works compared to the offline one. Offline, you are using the variable inside the <touching _ ?> sensor, which works in Squeak (what Scratch is written in). Unfortunately, I don't think the same thing works with the online Java player, simply because of it's not coded in the same language. (These sort of incompatibilities are popping up all the time.) Why exactly do your need a variable in that sensor anyway? I can't really think of why it's necessary.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#3 2010-10-16 14:58:57

helpwithcs
Scratcher
Registered: 2010-02-17
Posts: 3

Re: Inconsistent behavior when using a variable inside touching block

Very good point on the Java vs. Squeak issue, but I was hoping that there might be something that I was missing. In regards to the usage of variables in sensors I'm simply  trying to reuse the code for different sprites (within one or more projects). Essentially, the routine would be more inline with a procedure/function that has parameters; perhaps I should consider BYOB for this.

NOTE: I realize that my code doesn't reflect any need for this, however, by knowing the width and height of a sprite I would be able to stamp the number sprite multiple times in order to perform multi-digit multiplication. The project that would be using this is http://scratch.mit.edu/projects/helpwithcs/1356398. Sizing and spacing of numbers would be necessary if I want to fit 2 vs. 4-digit (or more) multiplication.

Offline

 

#4 2010-10-16 15:51:12

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Inconsistent behavior when using a variable inside touching block

Oh, I see. I take it that the size of the sprite will be changing? If not, you can make a list of the characters' sizes and have the project reference that.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#5 2010-10-17 20:54:59

helpwithcs
Scratcher
Registered: 2010-02-17
Posts: 3

Re: Inconsistent behavior when using a variable inside touching block

I have uploaded a version that allows the user to determine the min and max limit for it to select random numbers from which to ask the user multiplication questions. As noted, by Harakou, it would seem as though the difference between the platform (Java on Web vs. Squeak offline) is what may be the culprit, however, if anyone has another idea I'm willing to try it out.

The project is at: http://scratch.mit.edu/projects/helpwithcs/1356398.

NOTE: This method of determining width and height is intended to be as generic as possible in order to allow for code reuse. Thanks for the help.

Offline

 

Board footer