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

#1 2010-06-11 16:13:36

rajababu
Scratcher
Registered: 2010-06-11
Posts: 3

BYOB - Sprites as Objects

Is there a way to pass Sprite's reference to a block created using BYOB?

Offline

 

#2 2010-06-11 16:21:34

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: BYOB - Sprites as Objects

rajababu wrote:

Is there a way to pass Sprite's reference to a block created using BYOB?

Such as the sprites name?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#3 2010-06-11 16:43:56

rajababu
Scratcher
Registered: 2010-06-11
Posts: 3

Re: BYOB - Sprites as Objects

No not just the name .... I need do the same logic i.e. move, change etc. for each sprite and I don't want to put the code block in each sprite ... example I need to move Sprite1 in relation of Sprite2.

Offline

 

#4 2010-06-11 16:51:55

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: BYOB - Sprites as Objects

hmm i dont realy know BYOB but ill have a loook


You can now reach me on Twitter @johnnydean1_

Offline

 

#5 2010-06-11 17:51:47

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB - Sprites as Objects

rajababu wrote:

Is there a way to pass Sprite's reference to a block created using BYOB?

I'm not sure I completely understand your question, but maybe what you're looking for is the [<thing> OF <sprite>] block in the
sensing menu.  The first dropdown will include all the local variables and local methods of the sprite you choose in the second dropdown.

What doesn't seem to work, though, is dropping a variable onto the second dropdown; that makes the first dropdown not work. We'll put it on the list of things to think about, but probably not until 3.1.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#6 2010-06-11 18:38:09

rajababu
Scratcher
Registered: 2010-06-11
Posts: 3

Re: BYOB - Sprites as Objects

Let me try to explain a little more

My understanding of a procedure is to reduce the repetition of the code.... say for example

I have 20 sprites.
I want to make the x and y position for two sprites say Sprite1 and Sprite11 same if the two sprites are touching each other.

The same should be true between
Sprite2 and Sprite12
Sprite3 and Sprite13
Sprite4 and Sprite14
.
.
and so on till  Sprite10 and Sprite20.

So rather than repeating the code in each  Sprite I want to write a procedure which will do this. I need an option to get and set the attributes of a  Sprite reference passed to the procedure.

Offline

 

#7 2010-06-11 20:00:17

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB - Sprites as Objects

rajababu wrote:

I want to make the x and y position for two sprites say Sprite1 and Sprite11 same if the two sprites are touching each other...

Okay, this is a little bit of a kludge but you can do it...

First of all, the procedure to do the work will be global -- you write it once and be sure "for all sprites" is checked; it's the default, so you just have to refrain from changing it.

Let's say sprite11 is going to move to sprite1's position.  Then your block is called, say, CHECKTOUCH, and it has three inputs: TESTER, which is declared of type Predicate, and XPOS and YPOS, which are of type Reporter.  The code of CHECKTOUCH is:

FOREVER IF [CALL <tester>]
   SET X TO [CALL <xpos>]
   SET Y TO [CALL <ypos>]

And then you have a green-flag script in Sprite11 that says

CHECKTOUCH [THE [<TOUCHING? <sprite1>] BLOCK]
                    [THE [<x position> OF <sprite1>] BLOCK]
                    [THE [<y position> OF <sprite1>] BLOCK]

In Sprite12 you have

CHECKTOUCH [THE [<TOUCHING? <sprite2>] BLOCK]
                    [THE [<x position> OF <sprite2>] BLOCK]
                    [THE [<y position> OF <sprite2>] BLOCK]

Now, what you really want is to have

SET <partner> TO <sprite2>

and then be able to use <partner> in the CHECKTOUCH script.  (I know you know that's what you want because of the title you gave this forum!)  First class sprites are definitely on our agenda, but short of a miracle they won't be in BYOB 3.0.  It's high on our wish list for 3.1, though.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

Board footer