 |
 |

05-28-2001, 11:03 PM
|
|
|
Timers
|
Is there an easy way to have to one timer turn off when another is enabled?
|
|

05-28-2001, 11:24 PM
|
|
|
Re: Timers
|
I tried to get it to work but failed, this is some of the code from my forms if it helps.
for form 6>
Private Sub Timer3_Timer()
problem = Int(4 - 1 + 1) * Rnd + 1
If problem = 5 Then problemtxt = "you were hit in the arm by flying debries!"
If problemtxt = "you were hit in the arm by flying debrie!" Then
MsgBox ("You must go to the first aid building to get a sling for your arm, or you keep losing satisfaction")
Timer17.Enabled = False
Timer8.Enabled = True
Timer1.Enabled = True
Form14.Check2.Enabled = True
End If
Private Sub Form_Load()
Randomize
End Sub
Private Sub Timer1_Timer()
Do While DoEvents()
Text2 = Text2 + 0.0001
Loop
End Sub
Private Sub Timer8_Timer()
Do While DoEvents()
Text3 = Text3 - 0.0001
Loop
End Sub
Private Sub Timer17_Timer()
Do While DoEvents()
Text3 = Text3 + 0
Loop
End Sub
for form14>
If Form6.Timer8.Enabled = True Then
Check2.Enabled = True
End If
If Check2.Value = True Then
Form6.Timer8.Enabled = False
Form6.Timer17.Enabled = True
Form6.Timer1.Enabled = True
MsgBox ("A sling holds and stops pain, this stops the loss of satisfaction")
Check2.Enabled = False
End If
for some reason i can't get this to work, can you suggest any other ways of doing this?
|
|

05-29-2001, 12:15 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Re: Timers
|
This is some of the most convoluted code I've seen in such a small space.
It appears that you wish to get a 12.5% chance of getting hit, and a certain time later, of getting healed (it may appear to be 1 in 5, ie 20%, but it is more like .5 in 4, or 12.5%: 1=12.5% 2=25% 3=25% 4=25% 5=12.5%)
I'm not sure what your other timers are for, especially timer17.
You have some code for checking the value of your checkbox, but it's not clear when this code is supposed to execute.
In general, you are probably better off having just one timer or main loop with several states. Ie. a state machine.
For instance:
<PRE>
dim State as integer
private sub timer1_timer()
select case state
case 0 'defaul normal state
if rnd() < 0.2 then
problemtext = "Hit in arm by debris"
msgbox "Go to first aid"
state = 1 'wounded state
form14.check2.enabled = true
end if
case 1 'wounded
if form14.check2.value=1 then
msgbox "bandaged"
state = 0 'normal health
form14.check2.enabled = false
form14.check2.value = 0
end if
end select
end sub
</PRE>
You can add other states as required. Alternatively, instead of a timer event, you could put this into a code module as a do loop.
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

05-29-2001, 03:32 AM
|
|
|
Re: Timers
|
two timers and two text,
Dim x As Integer
Private Sub Form_Load()
Timer2.Enabled = False
Timer1.Interval = 1000
Timer2.Interval = 1000
End Sub
Private Sub Timer1_Timer()
x = x - 1
Text1.Text = x
If Text1.Text = -10 Then
Timer2.Enabled = True
Timer1.Enabled = False ' timer one is off, timer2 enabled
End If
End Sub
Private Sub Timer2_Timer()
x = x - 1
Text2.Text = x 'continue to count down x value
End Sub
is this what you want ? ...???
a novice
|
|

05-29-2001, 09:45 PM
|
|
|
Re: Timers
|
ok i think i have that figured out. What would be a good way to have a timer run and subract a certain amount from a total while it's running?
|
|

05-30-2001, 12:07 AM
|
|
Senior Contributor
* Guru *
|
|
Join Date: Mar 2000
Location: Christchurch, New Zealand
Posts: 470
|
|
Re: Timers
|
Declare a module level variable (i.e. in the General Declarations section at the top of the module) and use that as your running total.
A module level variable can be "seen" in all procedures so it maintains it's value across all procedures. Therefore, be careful to initialise it when you need to.
HINT: use the suffix "m" to indicate a module level var.
e.g. Private mlngTotal As Long
m = module, lng = Long, Total= what the variable is for.
HTH
<font color=blue>Better to remain a fool than write a quote and remove all doubt. (****!!)</font color=blue>
|
|

05-30-2001, 06:12 AM
|
|
|
Re: Timers
|
subtract a mount from a total while it's running ?
the timer is running
x = x-1
and the text1.text
=-1,
=-2
=-3
=-4
=-5,....
if i choose to subtract amount from a total after 5 seconds
then you just add
if x = - 5 then
x = -5-20 'subtract 20
end if
'after this x will be -25
a novice
|
|

05-30-2001, 05:30 PM
|
|
|
Re: Timers
|
ok this is my code i'm trying to have a character walk around in a theme park and hit objects which load forms, i have that part of it working but i also have a timer system i'm working on the that makes points go up all the time, i got that to work to, but my big problem is that i cannot get different timers to make a number go down after a certain random event has happen, then turn off when the character goes to another form and clicks on a check box that fixes it and the timer stops counting down.
This is my code, can anyone think of a way to help me make this work?
Private Sub test(ByVal n As Image, ByVal p As Image, ByVal Coll As Integer)
If n.Left >= (p.Left - p.Width) And n.Left <= (p.Left + p.Width) And n.Top >= (p.Top - p.Height) And n.Top <= (p.Top + p.Height) Then
Select Case Coll
Case 1
Form7.Show
Case 2
Form8.Show
Case 3
Form9.Show
Case 4
Form10.Show
Case 5
Image8.Left = Image8.Left - 40
Image8.Top = Image8.Top + 40
Case 6
Image8.Left = Image8.Left - 40
Image8.Top = Image8.Top + 40
Case 7
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top + 40
Case 8
Image8.Left = Image8.Left - 40
Image8.Top = Image8.Top - 40
Case 9
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top - 40
Case 10
Image8.Left = Image8.Left - 40
Image8.Top = Image8.Top - 40
Case 11
Form11.Show
Case 12
Form14.Show
Case 13
Form15.Show
Case 14
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top - 40
Case 15
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top - 40
Case 16
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top - 40
Case 17
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top - 40
Case 18
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top - 40
Case 19
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top - 40
Case 20
Image8.Left = Image8.Left + 40
Image8.Top = Image8.Top - 40
Case 21
Image8.Left = Image8.Left - 40
Image8.Top = Image8.Top - 40
End Select
End If
End Sub
Private Sub form_keydown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyLeft Then
Image8.Left = Image8.Left - 40
Call Collision
End If
If KeyCode = vbKeyRight Then
Image8.Left = Image8.Left + 40
Call Collision
End If
If KeyCode = vbKeyUp Then
Image8.Top = Image8.Top - 40
Call Collision
End If
If KeyCode = vbKeyDown Then
Image8.Top = Image8.Top + 40
Call Collision
End If
End Sub
Private Sub Collision()
Call test(Image8, Image9, 1)
Call test(Image8, Image10, 2)
Call test(Image8, Image11, 3)
Call test(Image8, Image12, 4)
Call test(Image8, Image13, 5)
Call test(Image8, Image14, 6)
Call test(Image8, Image15, 7)
Call test(Image8, Image16, 8)
Call test(Image8, Image17, 9)
Call test(Image8, Image18, 10)
Call test(Image8, Image1, 11)
Call test(Image8, Image3, 12)
Call test(Image8, Image4, 13)
Call test(Image8, Image2, 14)
Call test(Image8, Image5, 15)
Call test(Image8, Image6, 16)
Call test(Image8, Image19, 17)
Call test(Image8, Image20, 18)
Call test(Image8, Image21, 19)
Call test(Image8, Image22, 20)
Call test(Image8, Image23, 21)
End Sub
Private Sub Form_Load()
Randomize
End Sub
Private Sub Timer1_Timer()
Do While DoEvents()
Text2 = Text2 + 0.0001
Loop
End Sub
Private Sub Timer2_Timer()
Do While DoEvents()
Text2 = Text2 + 0.0002
Loop
End Sub
Private Sub Timer4_Timer()
problem = Int(4 - 1 + 1) * Rnd + 1
If problem = 1 Then problemtxt = "you were in the sun to long and got sun burned!"
If problem = 2 Then problemtxt = "you just got stung by a bee!"
If problem = 3 Then problemtxt = "you got a headache from being in the sun to long!"
If problem = 4 Then problemtxt = "you were cut by a rusty nail while walking in the park!"
If problem = 5 Then problemtxt = "you were hit in the arm by flying debries!"
If problem = 6 Then problemtxt = "you were walking to fast in the park and ran out of breath!"
If problem = 7 Then problemtxt = "you were walking down the path when a water pipe broke and sprayed all over you!"
If problem = 8 Then problemtxt = "you tripped and hit your knee!"
If problem = 9 Then problemtxt = "A freak snow storm hits!"
Select Case State
Case 0 'defaul normal state
If problemtxt = "you were in the sun to long and got sun burned!" Then
MsgBox "you were in the sun to long and got sun burned!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check5.Enabled = True
End If
Case 1 'wounded
If Form14.Check5.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check5.Enabled = False
Form14.Check5.Value = 0
End If
Case 2 'defaul normal state
If problemtxt = "you just got stung by a bee!" Then
MsgBox "you just got stung by a bee!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check3.Enabled = True
End If
Case 3 'wounded
If Form14.Check3.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check3.Enabled = False
Form14.Check3.Value = 0
End If
Case 4 'defaul normal state
If problemtxt = "you got a headache from being in the sun to long!" Then
MsgBox "you got a headache from being in the sun to long!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check4.Enabled = True
End If
Case 5 'wounded
If Form14.Check4.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check4.Enabled = False
Form14.Check4.Value = 0
End If
Case 6 'defaul normal state
If problemtxt = "you were cut by a rusty nail while walking in the park!" Then
MsgBox "you were cut by a rusty nail while walking in the park!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check1.Enabled = True
Form14.Check6.Enabled = True
End If
Case 7 'wounded
If Form14.Check1.Value = 1 And Form14.Check6.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check1.Enabled = False
Form14.Check6.Enabled = False
Form14.Check1.Value = 0
Form14.Check6.Value = 0
End If
Case 8 'defaul normal state
If problemtxt = "you were hit in the arm by flying debries!" Then
MsgBox "you were hit in the arm by flying debries!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check2.Enabled = True
End If
Case 9 'wounded
If Form14.Check2.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check2.Enabled = False
Form14.Check2.Value = 0
End If
Case 10 'defaul normal state
If problemtxt = "you were walking to fast in the park and ran out of breath!" Then
MsgBox "you were walking to fast in the park and ran out of breath!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check7.Enabled = True
End If
Case 11 'wounded
If Form14.Check7.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check7.Enabled = False
Form14.Check7.Value = 0
End If
Case 12 'defaul normal state
If problemtxt = "you were walking down the path when a water pipe broke and sprayed all over you!" Then
MsgBox "you were walking down the path when a water pipe broke and sprayed all over you!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check8.Enabled = True
End If
Case 13 'wounded
If Form14.Check8.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check8.Enabled = False
Form14.Check8.Value = 0
End If
Case 14 'defaul normal state
If problemtxt = "you tripped and hit your knee!" Then
MsgBox "you tripped and hit your knee!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check9.Enabled = True
End If
Case 15 'wounded
If Form14.Check9.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check9.Enabled = False
Form14.Check9.Value = 0
End If
Case 16 'defaul normal state
If problemtxt = "A freak snow storm hits!" Then
MsgBox "A freak snow storm hits!"
MsgBox "Go to first aid"
State = 1 'wounded state
Form14.Check10.Enabled = True
End If
Case 17 'wounded
If Form14.Check10.Value = 1 Then
MsgBox "cured"
State = 0 'normal health
Form14.Check10.Enabled = False
Form14.Check10.Value = 0
End If
End Select
End Sub
Private Sub Timer3_Timer()
problem = Int(4 - 1 + 1) * Rnd + 1
If problem = 1 Then problemtxt = "you were in the sun to long and got sun burned!"
If problem = 2 Then problemtxt = "you just got stung by a bee!"
If problem = 3 Then problemtxt = "you got a headache from being in the sun to long!"
If problem = 4 Then problemtxt = "you were cut by a rusty nail while walking in the park!"
If problem = 5 Then problemtxt = "you were hit in the arm by flying debries!"
If problem = 6 Then problemtxt = "you were walking to fast in the park and ran out of breath!"
If problem = 7 Then problemtxt = "you were walking down the path when a water pipe broke and sprayed all over you!"
If problem = 8 Then problemtxt = "you tripped and hit your knee!"
If problem = 9 Then problemtxt = "A freak snow storm hits!"
End Sub
Private Sub Timer5_Timer()
If State = 1 Then
Text3 = Text3 - 0.0001
Do Until DoEvents
Timer5.Enabled = False
Loop
End If
End Sub
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|