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

#1 2012-03-17 19:01:36

SoulAlly_Hanna
Scratcher
Registered: 2012-03-10
Posts: 100+

Random "Hit Points"?

So, for my game I am going to have battle simulations, but I have no clue how to make "Random Hit Points". I know, just about, how to do the HP Bar, just not how to make the HP bar go down a random amount. Any ideas? Is that even available to do in Scratch or am I just wasting my time with trying? Please help!

Offline

 

#2 2012-03-17 19:42:05

Haiming
Scratcher
Registered: 2011-08-20
Posts: 1000+

Re: Random "Hit Points"?

Here's what you do.

Go to operators. Look for pick random from _ to _

Plug that into change health by _________

Then, add desired numbers to pick randomly from. Make sure both of the numbers are negative, and the smaller number goes first. (That is if you want to lose health)

If you want to have a random amount of hit points in the beginning, you would do a script as follows:

when gf clicked
set health to (pick random from 1 to 100)

Offline

 

#3 2012-03-17 19:48:16

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

Re: Random "Hit Points"?

Use the 'pick random' block.
It is under the 'operators' tab.

(pick random (1) to (10))
You could use it like this:
when I receive [attacked v]
change [health v] by (join [-] (pick random (lowestattackpower) to (highestattackpower) ) )
other scripts here


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

Offline

 

#4 2012-03-19 14:43:49

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Random "Hit Points"?

trinary wrote:

Use the 'pick random' block.
It is under the 'operators' tab.

(pick random (1) to (10))
You could use it like this:
when I receive [attacked v]
change [health v] by (join [-] (pick random (lowestattackpower) to (highestattackpower) ) )
other scripts here

Using (join [-] (number)) will not negate negative values. If it tries to negate -26, it will produce --26, not 26. Use ((number) * (-1)).

Last edited by rdococ (2012-03-19 14:44:10)

Offline

 

Board footer