The Dragon King
Mamehooker: Tweaking Effect Files 
About Mame Hooker Mame Hooker: Tweaking Effect Files.

In our previous tutorials I showed you how to hook up the canned effect offroad3 to Outrunners, which works but doesn't have a spring effect. In the last tutorial, I showed you how to create essentially the same effect with a spring effect, but as-is it won't work properly. We need to now start using the more advanced and proper technique of "tweaking". In this tutorial I'll explain the concept of tweak files and how they can be used to control individual layers of a effect file.

What we want to do first is make a tweak file to go along with the "customwheel" effect we made in the last tutorial. In your docs folder you'll find all kinds of info in regards to what you can tweak, but for now I'm going to walk you through one. Ok the first layer of our effect was that square wave that creates the rumble. The second was the center spring. What we want to happen is leave the spring (layer 2) playing all the time, while the square wave (layer 1) should be setup as a tweak. We can turn a layer off by setting it's duration to 0 and set it to -1 (infinite) to turn it back on again.

Tweak files are just plain old text files in the format:


You can add as many tweaks as you want by adding more lines, but we just need one.
Since we want to control the duration of layer 1 let's set it up like this:


Now our special current state flag will set the duration when the tweak file is called. Note that instead of %s% we could have used an absolute number, a specific output label (%ma_steering_wheel_lamp%), a buffer, or anything really. That is entirely up to you.

Anyway, that is all we need to do. Save this file as "customwheel.twk" in the effect folder, so mamehooker will load it when the effect is loaded.

Ok now to explain how we will apply the tweak. First open up the good old orunners.ini in mamehooker so we can edit it some more. Instead of calling the "load effect file" command every single time the state changes, we will only load it once, at the game start. So In the "MameStart" entry, add a load effect file command to load customwheel. But when it's loaded it's going to play and we don't want that, so immediately after loading we want to tweak the file to stop the square wave, so add a command break and then add the "force feedback tweak" command. Joystick id is self explanatory. The on/off state is for controlling the entire effect, not individual layers, so set it to 1. Note that unlike most commands we can manually control the state instead of just passing the current one. For this initial startup, we want to tweak the %s% to 0, so set this to 0.

Your ini should now look like this:

MameStart=ffe 1 customwheel,fft 1 1 0

So it loaded the effect, playing both the center spring and square wave and immediately turned off the square wave, leaving only the spring playing. In case you are confused, it knows to control just the square effect via reading the twk file we created earlier.

Now what? Well, we again want the "ma_steering_wheel_lamp" output to control the rumble, but instead of reloading the effect, we will tweak it on a state change. When the output is 0 we tweak the duration to 0 and when it's 1 we tweak it to -1 (infinite).

So delete our commands from the preview tutorial and add some new ones. Add a "force feedback tweak" command with the state set to 0 followed by a command break, follwed by another "force feedback tweak" command with the state set to -1 to the "ma_steering_wheel_lamp" output.

Your ini file should now look similar to this:

MameStart=ffe 1 customwheel,fft 1 1 0
ma_steering_wheel_lamp=fft 1 1 0|fft 1 1 -1

And that's it really. Mamehooker will now always play the spring effect and use the steering wheel output to control the square wave rumble. It's as simple as that!

You can fire up OutRunners and try it for yourself. You will get the same rumble you did before, only now there is a nice center spring the whole time you play.

Note that this is just the tip of the iceberg. Even though we manipulate the %s% flag in this example, any time the tweak command is called, it will lookup and set any flags you have defined. So you could set the tweak to fire at the "StateChange" event instead and tweak multiple aspects of an effect using multiple outputs at once.