LoopsNow that we have our first big feat out of the way, the If statement, we can move on to some basic loops. In many ways, looping is actually easier than the If statement that we just learned. So if you got through that last page okay, you will be just fine from here-on-out! :) For LoopsThe for loop is one of the most often-used loops in VB for games, so we'll start with that. Basically, all that you want it to do is execute a command block a specified number of times. Here is a basic implementation of a simple For loop:
Simple, huh? Basically, this function becomes a 'wrapper' for vb's native For loop, making life simple on you, the coder. One thing to be noticed, though, is that the command block has no way of knowing the contents of the 'counter' variable, i. Implementing this is something that you should try as an exercise. I would suggest waiting on this, though, until I discuss later possible methods of implementing true, named variables. Do...Loop Until LoopsThis type of loop is also quite simple to implement, again 'wrapping' vb's built-in loop of the same name. Look this code over:
Again, this function should be fairly straightforward. The only 'new' thing is the ability for the script to specify whether to check for the flag being "on" (1) or "off" (0) as the fourth parameter, a(3).
|
||||||||||||||||||||