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

#1 2012-05-11 10:25:36

tomerl
New Scratcher
Registered: 2012-05-11
Posts: 1

new help with random coordinates! please and thank you!

I have a question, I'm making a "hit'em up", it pops out from a "hole" and then you have to hit it, so my problem is making the object pop out in certain coordinates or in the center of the "holes" in a random way. thanks in advance!  smile

Offline

 

#2 2012-05-11 10:36:44

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: new help with random coordinates! please and thank you!

Create a list with the hole coordinates, then do somthing like this:

when gf clicked
forever 
 wait [(pick random 1-4) seconds]
  set x to[(item (pick random 1-7) of [Hole coordinates X pos v]
  set y to[(item (pick random 1-7) of [Hole coordinates Y pos v]
 
You need to create two lists: One holding the "y" pos. of the hole, and one holding the ""x" pos.

Last edited by mythbusteranimator (2012-05-11 10:37:35)


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#3 2012-05-11 21:05:22

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: new help with random coordinates! please and thank you!

mythbusteranimator wrote:

Create a list with the hole coordinates, then do somthing like this:

when gf clicked
forever 
 wait (pick random (1) to (4) ) secs
  set x to (item (pick random (1) to (7) ) of [holecoordinatesXpos v])
  set y to (item (pick random (1) to (7) ) of [holecoordinatesYpos v])
 
You need to create two lists: One holding the "y" pos. of the hole, and one holding the ""x" pos.

Fixed.


http://trinary.tk/images/signature_.php

Offline

 

#4 2012-05-11 21:48:03

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: new help with random coordinates! please and thank you!

trinary wrote:

mythbusteranimator wrote:

Create a list with the hole coordinates, then do somthing like this:

when gf clicked
forever 
 wait (pick random (1) to (4) ) secs
  set x to (item (pick random (1) to (7) ) of [holecoordinatesXpos v])
  set y to (item (pick random (1) to (7) ) of [holecoordinatesYpos v])
 
You need to create two lists: One holding the "y" pos. of the hole, and one holding the ""x" pos.

Fixed.

You can actually just use the

set x to (item (any v) of [holecoordinatesXpos v])
block.

Offline

 

#5 2012-05-11 23:48:30

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: new help with random coordinates! please and thank you!

amcerbu wrote:

trinary wrote:

mythbusteranimator wrote:

Create a list with the hole coordinates, then do somthing like this:

when gf clicked
forever 
 wait (pick random (1) to (4) ) secs
  set x to (item (any v) of [holecoordinatesXpos v])
  set y to (item (any v) of [holecoordinatesYpos v])
 
You need to create two lists: One holding the "y" pos. of the hole, and one holding the ""x" pos.

Fixed.

You can actually just use the

set x to (item (any v) of [holecoordinatesXpos v])
block.

Great point amcerbu, I changed the script. It's more efficient now.  smile

Last edited by jontmy00 (2012-05-11 23:49:46)


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#6 2012-05-12 09:07:15

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: new help with random coordinates! please and thank you!

d

jontmy00 wrote:

amcerbu wrote:

You can actually just use the

set x to (item (any v) of [holecoordinatesXpos v])
block.

Great point amcerbu, I changed the script. It's more efficient now.  smile

Only if the holes are on a grid-like system.  Otherwise, the x and y coordinates won't match up (e.g. go to x: (item 1 of list x) y:(item 4 of list y) )


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-05-12 09:15:47

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: new help with random coordinates! please and thank you!

MoreGamesNow wrote:

d

jontmy00 wrote:

amcerbu wrote:

You can actually just use the

set x to (item (any v) of [holecoordinatesXpos v])
block.

Great point amcerbu, I changed the script. It's more efficient now.  smile

Only if the holes are on a grid-like system.  Otherwise, the x and y coordinates won't match up (e.g. go to x: (item 1 of list x) y:(item 4 of list y) )

Hmm...I just realized that.
Maybe create avariable called "List item1" and set "list item 1" to the item number of the 'holecoordinatesxpos', and then choose item "listitem1" of 'holecoordinatesxpos'?


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#8 2012-05-12 09:23:20

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: new help with random coordinates! please and thank you!

As in,

set x to [(item [any v] of [holex v])]
set [list item v] to item [(x position)] of [holex v]
set y to [(item [(list item) of [holey v])]
 
Hm... that might not work.


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#9 2012-05-12 10:29:44

parcheesidude
Scratcher
Registered: 2009-10-07
Posts: 500+

Re: new help with random coordinates! please and thank you!

Also, you might want to number the holes, and use the following script, so that 2 don't appear in 1 spot.

set [xnum v] to <pick random (1) to (7)>
set [ynum v] to <pick random (1) to (4)>
if <not <[used v] contains <<(ynum)-[1]>*[7]>+(xnum)>>
 go to x: <item (xnum) of [x's v]> y: <item (ynum) of [y's v]>
 add <(ynum)-[1]>*[7]>+(xnum)> to [used v]

Last edited by parcheesidude (2012-05-12 12:28:57)


My signature is trying to find itself :3

Offline

 

#10 2012-05-12 11:25:12

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: new help with random coordinates! please and thank you!

This should do it:

set [listIndex v] to (pick random (1) to (7))
set [desiredXPosition v] to (item (listIndex) of [XPositions v])
set [desiredYPosition v] to (item (listIndex) of [YPositions v])

Last edited by amcerbu (2012-05-12 11:25:29)

Offline

 

#11 2012-05-12 11:40:48

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: new help with random coordinates! please and thank you!

amcerbu wrote:

This should do it:

set [listIndex v] to (pick random (1) to (7))
set [desiredXPosition v] to (item (listIndex) of [XPositions v])
set [desiredYPosition v] to (item (listIndex) of [YPositions v])

Even better. Everyone seems to be trying to be coming up with a better script.  wink


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#12 2012-05-13 14:03:18

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: new help with random coordinates! please and thank you!

jontmy00 wrote:

amcerbu wrote:

This should do it:

set [listIndex v] to (pick random (1) to (7))
set [desiredXPosition v] to (item (listIndex) of [XPositions v])
set [desiredYPosition v] to (item (listIndex) of [YPositions v])

Even better. Everyone seems to be trying to be coming up with a better script.  wink

That works (it was right in front of me the whole time, :p)


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#13 2012-05-14 14:17:22

laser314
Scratcher
Registered: 2010-07-16
Posts: 100+

Re: new help with random coordinates! please and thank you!

mythbusteranimator wrote:

Create a list with the hole's coordinates, then do somthing like this:

when gf clicked
forever 
 wait (pick random (1)to (4)) secs
  set x to[(item (pick random 1-7) of [Hole coordinates X pos v]
  set y to[(item (pick random 1-7) of [Hole coordinates Y pos v]
 
You need to create two lists: One holding the "y" pos. of the hole, and one holding the ""x" pos.

Fixed.

Last edited by laser314 (2012-05-14 14:18:22)


http://alpha.scratch.mit.edu/scratchr2/static//images/logo_sm.png 2.0 Alpha Tester!http://i49.tinypic.com/1zckcqb.png

Offline

 

Board footer