I need help on randomizing variables
Author Message
I need help on randomizing variables

alright, i'm a bit new to VB, and i can't afford those big books, so...

I'm making a game.  i have defined variables for stats of players.  i'd like to
know how to generate a random number based on a variable.

the general idea of my code is like this:

Option Explicit

Dim accuracy as integer
Dim CoH as Integer
Dim SCoH As Integer
Dim TCoH As Integer
Dim Hit As Boolean

Public Sub Chance_Of_Hit
Accuracy  = 20

'(Insert how to randomize CoH Here)

SCoH = Accuracy*4 + Evade * 2
TCoH = SCoH - CoH
If TCoH > (what ever value i put here) Then
Hit = True
Else
If TCoH < (What ever value i put here) Then
Hit = False
End If
End If
End Sub

Sun, 21 Apr 2002 03:00:00 GMT
I need help on randomizing variables
Just use Rnd, it is built into VB. You can find it in the help file. It
generates numbers between 0 and 1, but you can scale them up if you need to.
Randomize it the first time you use it.
Maybe try: chance_of_hit = rnd * accuracy * (1 - evade)
with everything on a 0 to 1 scale. (Or 0 to 100%)

Quote:
>alright, i'm a bit new to VB, and i can't afford those big books, so...

>I'm making a game.  i have defined variables for stats of players.  i'd
like to
>know how to generate a random number based on a variable.

Sun, 21 Apr 2002 03:00:00 GMT
I need help on randomizing variables
Randomize
CoH = Rnd

Hope this helps,
Jason Bouzane

Quote:
> alright, i'm a bit new to VB, and i can't afford those big books, so...

> I'm making a game.  i have defined variables for stats of players.  i'd
like to
> know how to generate a random number based on a variable.

> the general idea of my code is like this:

> Option Explicit

> Dim accuracy as integer
> Dim CoH as Integer
> Dim SCoH As Integer
> Dim TCoH As Integer
> Dim Hit As Boolean

> Public Sub Chance_Of_Hit
> Accuracy  = 20
> CoH  = Accuracy*2 + Evade

> '(Insert how to randomize CoH Here)

> SCoH = Accuracy*4 + Evade * 2
> TCoH = SCoH - CoH
> If TCoH > (what ever value i put here) Then
> Hit = True
> Else
> If TCoH < (What ever value i put here) Then
> Hit = False
> End If
> End If
> End Sub

Mon, 22 Apr 2002 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages