|
-
Apr 27th, 2000, 07:41 AM
#1
Thread Starter
Frenzied Member
How do I make a loop? specifically I want this to loop:
Public Sub Shoot()
If ShotEnabled = True Then
Shot.y = Shot.y - 2
If Shot.y = Enemy.y Then
If Shot.x = Enemy.x Then Enemy.w = Enemy.w + 1
End If
If Shot.x = Enemy.x Then
If Shot.y = Enemy.y Then Enemy.w = Enemy.w + 1
End If
End If
End Sub
-
Apr 27th, 2000, 09:15 AM
#2
Addicted Member
Hi Steve,
You have a couple of options...
If you want the loop to happen a specific number of times then use a FOR ... NEXT Loop.
Code:
For intCnt = 0 to 3
Call Shoot
Next intCnt
If you want the loop to continue looping until a certain criteria is met then use a DO [While/Until] LOOP Loop
Code:
blnFlag = False
Do Until blnFlag = True
Call Shoot
'Somewhere in your Shoot sub you will
'need to set the value
'of blnFlag to True if you don't want an
'infinite loop. blnFlag will need to be
'Public in this case to be able to be set
'from your Shoot sub.
Loop
Hope this helps.
-
Apr 27th, 2000, 09:23 AM
#3
Hyperactive Member
Well, you could put in a timer with a refresh rate of about 100 milliseconds. in it, put
Call Shoot()
That will call your sub every 100 milliseconds. To stop it, put
Timer1.Enabled = False
or to start the looping
Timer1.Enabled = True
Another thing you can consider is condensing your code to:
Code:
Public Sub Shoot()
If ShotEnabled = True AND Shot.y-2 = Enemy.y AND Shot.x = Enemy.x Then
Enemy.w = Enemy.w + 1
End If
End Sub
That should do the same thing, I think.
bob
-
Apr 27th, 2000, 09:26 AM
#4
Just a thought
In the posting Do...Loop example. If there are a number of lines of code following the test you conduct use "Exit Do" after the exact exit criteria is meet. vb will pop you out of the loop without executing unwaited sequences of code.
-
Apr 27th, 2000, 09:31 AM
#5
Hyperactive Member
The problem with jcouture100s answer is that it will suspend everything until this happens. I'm assuming you're making a game that has a bullet colliding with the enemy. In this case, you won't want everything frozen until the collision occurs. Instead, you'll need the separate function that tests for a collision(you named it Shoot already), repeated often, like with a timer.
bob
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|