This is an explanation of the code that I
use in VoiceAttack to implement my simplified mouse gliding – the one where I can only move
in four directions using four separate macros. The advanced gliding will be explained in
the next video. On the right will be a list of variables and strings being affected by
the code. For the simplified gliding, you can just say
a direction and either a speed or nothing. I’m using the example of having said Up and
perhaps with a speed. When it’s gliding, the loop condition is for
Moving to be equal to 0, though if you haven’t run any loops yet it will be undefined.
The code initially sets that moving value to 1, to a give chance to perhaps stop any other
Up movement scripts. Then it kills the commands for Left, Right, and Down. It doesn’t terminate
the Up scripts because this way of setting things up means that if I put in ‘Kill command
Up… and so on’, it would stop this macro right after it started it, and I’d get nowhere.
Setting Text Input to CMD basically puts what I said in the string Input. I set Speed to
equal that, and then I replace Up with nothing, and I use Trim to remove the space.
I set the Delay integer to 50, and the Increment integer to 3. Then it runs through a series
of If statements depending on what the content of Speed is. If Speed is crawl the Delay changes
to 125, and Increment changes to 1. If the Speed is slow, Delay is 50, Increment is 1.
If the Speed is fast, Delay is 50, Increment is 9. And if the Speed is sprint, Delay is
50 and Increment is 18. If I said nothing after Up, Delay would be equal to 50 and Increment
equal to 3, as in my original mouse gliding in VoiceBot.
Here you can see the 5 possibilities for Delays and Increments based on the 5 possibilities
of Speeds. Let’s suppose I specifically said Up Fast. Speed would come in as Up Fast, then
remove Up, and then the space using Trim. Because it equals Fast, Delay equals 50 and
Increment equals 9. I introduce the integer Scaler. Scaler is
what to use when you need to increase the speed of all of these glidings, which might
occur in a game where the number of pixels in a revolution is quite large. The default
is for Scaler to equal 1. Scaler is multiplied onto Increment to increase its value accordingly,
so that the gliding looks better in your game. If Scaler equals 2, this Increment would equal
18 for Up Fast. And if it was 7, Increment would become 63.
I set Wait to be equal to Delay, but as a decimal. Delay is the number of milliseconds
to wait during the loop, but I need to turn this into seconds. So I divide Wait by 1000,
and this turns it into 0.05, which when measured in seconds becomes exactly 50 milliseconds.
I then set Moving back to 0, and start the movement loop. The movement loop
moves Up by the value of Increment, then pauses for a variable number of seconds,
which is Wait. And this is enough to keep the loop going.
The only limitation of this is that you can – if you wanted to – say Up Slow then Up Fast
then Up Crawl and so on, and create a series of simultaneous movements going up. Some of
these would be stopped by the brief period in which Moving is equal to 1, while it’s
doing all those calculations, but for the actual practical uses you’d use it for, this
wouldn’t be a problem.