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

#1 2011-06-18 05:52:26

redman123
New Scratcher
Registered: 2011-05-18
Posts: 18

set random action for my cpu (platformer fighting game )

I have problem about seting actions for my cpu.
here is part of my script.

if distance to player < 40
set action to pick random 1 to 4
end if
=============================
action 1 move away from the player
action 2 walk toward the player
action 3 punch
action 4 kick
==============================

How do my make the cpu  have 10% chance to do action 1 , 10% chance to do action 2
, 40% chance to do action 3 and 40% chance to do action 4 ?

Offline

 

#2 2011-06-18 07:40:31

majormax
Scratcher
Registered: 2008-04-06
Posts: 1000+

Re: set random action for my cpu (platformer fighting game )

Do something like this:

Code:

set action to pick random 1-10

if action=1
do action 1
end if

if action=2
do action 2
end if

if action>2 and action<7
do action 3
end if

if action>6 and action<11
do action 4
end if

It should work  wink

Offline

 

#3 2011-06-18 09:13:05

redman123
New Scratcher
Registered: 2011-05-18
Posts: 18

Re: set random action for my cpu (platformer fighting game )

thanks a lot. Man ~
It works.

Offline

 

Board footer