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

#1 2013-04-22 12:41:38

Muttley1
New Scratcher
Registered: 2013-04-20
Posts: 10

Can I control 2 sprites?

Hi all, I really need some help as I am pulling out what little hair I have left.  I have programmed a simple game where by 2 "tanks" chase each other around an arena playing tag.  It seemed to be working but for some reason, since programming in the controls for player 2, player 1 won't move.  The broadcast to change costume works, but no movement which kind of defeats the object of a game of tag!

Where have I gone wrong?  The scripts for both sprites are the same (apart from the controlling keys of course).

Offline

 

#2 2013-04-22 12:56:42

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: Can I control 2 sprites?

http://scratch.mit.edu/projects/Firedrake969/2925625

Somewhat complicated, but I believe this may work.  only 1s1s.


Alt of Firedrake969.

Offline

 

#3 2013-04-22 13:00:07

Muttley1
New Scratcher
Registered: 2013-04-20
Posts: 10

Re: Can I control 2 sprites?

Somewhat, just looking at that has given me a headache!...I really thought it would be much simpler, just assign different keys to control the different sprites.  Might have to think about another control device.

Offline

 

#4 2013-04-22 13:20:11

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: Can I control 2 sprites?

could you show us what you currently have?

Offline

 

#5 2013-04-22 13:31:25

Muttley1
New Scratcher
Registered: 2013-04-20
Posts: 10

Re: Can I control 2 sprites?

OK, so what I have at the moment is something like this:

when gf clicked
go to x: -234 y: -180
set player1 to 0
forever
if key q pressed?
change y by 10
if key a pressed?
change y by -10
if key z pressed?
change x by -10
if key x pressed?
change x by 10
if key s pressed?
rotate anti-clockwise 15 degrees
if key d pressed?
rotate clockwise by 15 degrees

When f pressed
Broadcast Ram2

When I receive Ram2
switch to costume2
wait 1 secs
switch to costume1
if touching Sprite2
change player1 by 1

The exact same script for player 2 apart from different keys being pressed etc.

Offline

 

#6 2013-04-22 13:34:19

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: Can I control 2 sprites?

xlk wrote:

could you show us what you currently have?

Yes please ^^^


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#7 2013-04-22 13:35:43

Muttley1
New Scratcher
Registered: 2013-04-20
Posts: 10

Re: Can I control 2 sprites?

see above (BTW, they aren't all variables, it's just how it's formatted on here)

Offline

 

#8 2013-04-22 15:12:27

Muttley1
New Scratcher
Registered: 2013-04-20
Posts: 10

Re: Can I control 2 sprites?

I have got it to work, although it seems to have quite a few bugs, it is doing the basics:

http://scratch.mit.edu/projects/Muttley1/3283091

Offline

 

#9 2013-04-22 15:31:03

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: Can I control 2 sprites?

Muttley1 wrote:

OK, so what I have at the moment is something like this:

when gf clicked
go to x: [-234] y: [-180]
set [player1 v] to [0]
forever
 if <key [q v] pressed?>
  change y by [10]
 end
 if <key [a v] pressed?>
  change y by [-10]
 end
 if <key [z v] pressed?>
  change x by [-10]
 end
 if <key [x v] pressed?>
  change x by [10]
 end
 if <key [s v] pressed?>
  turn ccw [15] degrees
 end
 if <key [d v] pressed?>
  turn cw [15] degrees
 end


When key [f v] pressed
Broadcast [Ram2 v]

When I receive [Ram2 v]
switch to costume [costume2 v]
wait [1] secs
switch to costume [costume1 v]
if <touching [Sprite2 v]?>
 change [player1 v] by [1]
end
The exact same script for player 2 apart from different keys being pressed etc.

I am still confused by your problem. Let me check out your project to see what's wrong.

With regards,
~7734f


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#10 2013-04-22 15:32:26

Liamadams
Scratcher
Registered: 2012-12-08
Posts: 100+

Re: Can I control 2 sprites?

Muttley1 wrote:

OK, so what I have at the moment is something like this:

when gf clicked
go to x: [-234] y: [-180]
set [player1 v] to [0]
forever
if <key [q v] pressed?>
change y by [10]
if <key [a v] pressed?>
change y by [-10]
if <key [z v] pressed?>
change x by [-10]
if <key [x v] pressed?>
change x by [10]
if <key [s v] pressed?>
turn ccw [15] degrees
if <key [d v] pressed?>
turn cw [15] degrees
end
end
end
end
end
end

When [f v] key pressed
Broadcast [Ram2 v]

When I receive [Ram2 v]
switch to costume [costume2 v]
wait [1] secs
switch to costume [costume1 v]
if <touching [Sprite2 v]?>
change [player1 v] by [1]
end

The exact same script for player 2 apart from different keys being pressed etc.

Fixed.  hmm

Last edited by Liamadams (2013-04-22 15:35:38)


http://i39.tinypic.com/3309476.jpg

Offline

 

#11 2013-04-22 15:33:02

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: Can I control 2 sprites?

Ok, I see your problem. You can't move while the assumed arm comes out. I don't know how to remedy this, in a simple fashion, sorry.  hmm

With regards,
~7734f


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#12 2013-04-22 15:44:31

Muttley1
New Scratcher
Registered: 2013-04-20
Posts: 10

Re: Can I control 2 sprites?

It seems to be working kind of alright (for the moment anyway).  Gave myself quite a headache

Offline

 

#13 2013-04-22 15:56:43

Muttley1
New Scratcher
Registered: 2013-04-20
Posts: 10

Re: Can I control 2 sprites?

Now, anyone got any ideas on how to set a time limit?

Offline

 

#14 2013-04-22 16:44:07

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Can I control 2 sprites?

Muttley1 wrote:

Now, anyone got any ideas on how to set a time limit?

Yes. All you need is to reset the timer at the beginning of each round, figure out which scripts you want to "quit" once you reach the time limit, and change them so that they're more like this:

wait until <(timer) < [limit]>//Precautionary. Only if you want/need it.
forever
 if <(timer) < [limit]>
  Scripts...
 end

Well that should do it!

I hope that I helped!

With regards,

ErnieParke


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer