Codename Logo Codename Logo

Events

APIWiki

Events

Codename Engine's charter comes with 9 built-in events. To help you get some basic effects without having to script much.

HScript Call

When this event is ran, it calls the function of the same name as the first parameter in any of the loaded scripts.

It can mainly be used if you wanna trigger a specific function at a specific time without having to code it like if(curBeat == 69).

Arguments are passed as strings. You may need to convert it.

Camera Movement

This event is used to focus on a specific character, can be used to show the current character who is singing, and for extra movement during sections of a song where no one is singing.

In Legacy FNF charts this used to be the mustHitSection which moved the camera. This event is automatically created when using Legacy FNF charts in Codename.

Add Camera Zoom

When this event is ran, the selected camera in the Camera parameter zooms the amount in the Amount parameter. This can be used to create intensity in a song where it would feel normally static without it.

Note that this does not change the zoom of the camera permanently. It zooms back to the value of defaultCamZoom.

Camera Modulo Change

This event changes the amount of beats before the camera bumps. This can be used to create a similar effect to M.I.L.Fs drop where the camera bumps every beat, without having to script anything.

In the image below, the event will make the camera bump after every 4th beat

Camera Flash

This event simply runs the flixel function to flash the camera. This can be used to add a simple camera flash without having to type camHUD.flash(FlxColor.WHITE, 0.6); whenever you want to add a camera flash.

BPM Change

This event simply changes the BPM of the Conductor. Making sure everything stays in sync with your song.

Scroll Speed Change

This event changes the scroll speed of all the strumlines. It can be used to increase or decrease difficulty mid-song. It also has a parameter to tween the scroll speed, making it feel less snappy and much smoother.

Alt Animation Toggle

This event toggles if the chosen strumlines characters will use their animation with the -alt suffix to the animation for their sing poses and/or their idle poses.

This is used in the christmas week, when the parents take turns singing.

Play Animation

This event plays a characters animation. Can be used to make a small cutscenes or small dialogue moments within the song.

This event is used in Stress when Tankman says "Heh. Pretty good!".

Custom Events

This tutorial assumes that you already know the basics of using haxeflixel, and scripting in codename. If not please take a look at Scripting.

Your average custom event will usually have 3 files

Each file should be named the exact same.

The JSON file (.json) is to define the parameters of the event. The HScript file (.hx) file is used to handle the event, and the image is the icon that will be used in the charter.

I'm going to show a Play Sound event and explain what is going on in each file.

First lets start with the json file inside .data/events/Play Sound.json

{
    "params": [
        {
            "name": "Sound File Path",
            "type": "String",
            "defaultValue": ""
        },
        {
            "name": "Volume",
            "type": "Float(0, 1, 0.1, 2)",
            "defaultValue": "1"
        },
        {
            "name": "Looped",
            "type": "Bool",
            "defaultValue": "false"
        }
    ]
}

Alright lets break this down. Each parameter in the params array should have a name, type, and defaultValue.

The name is just the name that will be displayed and what you will check for in your script.

The types that you can use are:

And the defaultValue is self explanatory, but it's what is automatically set for the value of the parameter.

Next let's move onto the script itself in .data/events/Play Sound.hx.

First lets make the onEvent function:

function onEvent(event) {

}

To get our event we need to check if the name is the same as the Play Sound event. We can check that by checking event.event.name

function onEvent(event) {
  if(event.event.name == "Play Sound")
  {

  }
}

Now we need to get the parameters from the event, so we can play the correct sound. We can get the parameters by getting the params array: event.event.params.

The params array will be in the same order as the params your event .json.

So in our case, event.event.params[0] will be the Sound File Path parameter, the next will be the volume parameter, and so on.

function onEvent(event) {
  if(event.event.name == "Play Sound")
  {
    // FlxG.sound.play(SoundFilePath, Volume, Looped)
    FlxG.sound.play(Paths.sound(event.event.params[0]), event.event.params[1], event.event.params[2]);
  }
}

And thats it! Whenever our new event Play Sound is ran, it will run this code inside onEvent and play the sound based on the parameters in the event.

Event packing

If you wish to make this all a bit more cleaner and share this event, you can pack the event.

Packing an event is pretty simple. Visit the event packer to pack your event into one .pack file.

This .pack file goes into ./data/events/ and will work identically to its unpacked version.