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

#1 2010-12-27 00:21:14

nuoyalala
New Scratcher
Registered: 2010-12-24
Posts: 6

how to make recursive call? Or does it support?

I am trying to set couple of cars to cross the screen one by one. The distance is sort of random and the speed is random as well.

Basically in stage I use:
<when I receive[ car_started ] >
<set{ next_car  }to(  ) >

when I receive "car_started"
  set "next_car" = "current_car" + 1
  if "next_car" > total_cars
     set "next_car" = 1
  broadcase "start_new_car"

for each car, I set a private variable = mynum and private flag

when receive "start_new_car"  it checks if "mynum" == "next_car";
if yes, wait untail "flag" ==  0
then pick random number for waiting / costume etc
then show the car ; set flag = 1; set current_car = mynum;
broadcast "car_started";
glide the car to the right side
hide the car;
set back to 0

but it doesn't work unless I broadcase "car_started" after the car finish its moving. I am guessing there is restrict for the re_enter the same submodule.

How to handle it?  I am  trying to create a array to maintain a public flag then I can decide any empty car as "next_car" but it doesn't support array variable

The example sb file can be found from
http://cid-315164ca3f0b4b54.office.live.com/self.aspx/scratch/cross^_the^_street.sb

Thanks for the help

Offline

 

#2 2010-12-27 00:51:38

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: how to make recursive call? Or does it support?

Well, i suppose...

Is this what you wanted? http://scratch.mit.edu/projects/ssss/1503351


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#3 2010-12-27 07:49:35

nuoyalala
New Scratcher
Registered: 2010-12-24
Posts: 6

Re: how to make recursive call? Or does it support?

Thanks for the quick reply. I apologize to make it unclear.  Could you please look at my code at:  http://cid-315164ca3f0b4b54.office.live.com/self.aspx/scratch/cross%5E_the%5E_street%5E_save.sb again?

My main purpose is to create an my own sprite with as much shared codes as possible.

You can see all my cars have only difference is the "mynum". So it will be easier to duplicate. This is just like to create a class then make multiple instances but I don't know if scratch support this.

Thanks again for you quick reply  smile

Offline

 

#4 2010-12-27 08:27:31

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: how to make recursive call? Or does it support?

Scratch doesn't support classes and instances.  sad  I'll take a look at your code.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#5 2010-12-27 08:34:25

nuoyalala
New Scratcher
Registered: 2010-12-24
Posts: 6

Re: how to make recursive call? Or does it support?

Thanks.

I used to try the GM (game maker) and it support the class and instance but I cannot figure out how it make the collision calculation (I may have the trend to make simple things complex  sad  ) so I moved to the simple scratch.

Offline

 

#6 2010-12-27 08:37:05

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: how to make recursive call? Or does it support?

Hmmm... could you explain what your game is supposed to do? I'd be able to help you more if I knew  smile


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#7 2010-12-27 08:51:42

nuoyalala
New Scratcher
Registered: 2010-12-24
Posts: 6

Re: how to make recursive call? Or does it support?

the car will come from either left or right. For different level the speed will be different and the space is somehow a prime number (level related) + some random number. Also, we will have six lanes for the highest level (bidirectional). The little monkey need to cross the street to save / pick little monkey / banana.

Randomly there is a speed car come up at higher level.  Just like the famous game frog cross the street. 

That's what my plan.

maybe I really should use forever loop to do such things.  Just like the way I am currently using  smile

Offline

 

#8 2010-12-27 09:07:45

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: how to make recursive call? Or does it support?

nuoyalala wrote:

the car will come from either left or right. For different level the speed will be different and the space is somehow a prime number (level related) + some random number. Also, we will have six lanes for the highest level (bidirectional). The little monkey need to cross the street to save / pick little monkey / banana.

Randomly there is a speed car come up at higher level.  Just like the famous game frog cross the street. 

That's what my plan.

maybe I really should use forever loop to do such things.  Just like the way I am currently using  smile

Okay. I'll work on that using your base. Wouldn't you want top views of the cars instead of side views?


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#9 2010-12-27 09:10:39

nuoyalala
New Scratcher
Registered: 2010-12-24
Posts: 6

Re: how to make recursive call? Or does it support?

ScratchReallyROCKS wrote:

Okay. I'll work on that using your base. Wouldn't you want top views of the cars instead of side views?

It doesn't matter at this stage.  Will that make any difference?

Offline

 

#10 2010-12-27 09:20:21

nuoyalala
New Scratcher
Registered: 2010-12-24
Posts: 6

Re: how to make recursive call? Or does it support?

ScratchReallyROCKS wrote:

Okay. I'll work on that using your base. Wouldn't you want top views of the cars instead of side views?

at the same time, could you tell me which way you will like to do it?  Just want to open my mind.

Thanks,

Offline

 

Board footer