Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 12-19-2005, 09:47 PM   #1
In Runtime
 
killzoneman0's Avatar
 
Join Date: Aug 2005
Posts: 339
Send a message via AIM to killzoneman0
Default vb6 help needed please!!!

i am making a text-adventure game in visual basic 6 and was wondering how i could randomize an event that occurs. an example would be a label that pops up randomly in the game and says "you encounter dust storm and lose 3 health"

does anyone know of any code that could do this?
__________________

killzoneman0 is offline   Reply With Quote
Old 12-20-2005, 04:53 AM   #2
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,003
Default Re: vb6 help needed please!!!

Since it's a text adventure.... use code that simulates a dice being rolled...
Code:
Private Sub Form_Load()
  'Initialize the psuedo-random # generator.
  Randomize
End Sub
this is a regular 6 sided dice.
Code:
private sub button1_click()
DieValue = Rand(1, 6)

if DieValue = 1 then
msgbox "you encounter dust storm and lose 3 health" 
end if

end sub

change this line
Code:
DieValue = Rand(1, 6)
for more values

eg 24side dice
Code:
DieValue = Rand(1, 24)
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 12-20-2005, 03:23 PM   #3
In Runtime
 
killzoneman0's Avatar
 
Join Date: Aug 2005
Posts: 339
Send a message via AIM to killzoneman0
Default Re: vb6 help needed please!!!

Private Sub Form_Load()
'Initialize the psuedo-random # generator.
Randomize
End Sub


Private Sub Command1_Click()
DieValue = Randomize(1, 6)
If DieValue = 1 Then
MsgBox "you encounter dust storm and lose 3 health"
Else
MsgBox "it didnt work"
End If
End Sub





when i hit the command button it highlights randomize in the command_click and a messagebox says"compile error: wrong number of arguements or invalid property assignment"

when i go to the object browser, it says that "Sub Randomize([Number])" is the right way to put it. it also says that it initializes the random number generator.

what do i do now?
killzoneman0 is offline   Reply With Quote
Old 12-21-2005, 04:46 PM   #4
Baseband Member
 
Griz803's Avatar
 
Join Date: Jun 2004
Posts: 89
Default Re: vb6 help needed please!!!

Er... How about you refer to root's earlier post and check out the part about the function Rand, not Randomize. One sets the psuedorandom seed for the initialization (Randomize) and gets used only once. The other (Rand) is used to get a random number returned within a specified range ( as in DieValue = Rand(1,6) ). Recheck your code and try, try again...
__________________
/*What does not kill us, makes us drink far too much caffeine*/
Griz803 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 01:30 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0