Skip to content

Character and Chart scripts

Super edited this page Nov 4, 2021 · 29 revisions

Scripting:

As of 0.5.0, you can provide a script with characters or charts. You can use scripts to add custom features and such to the game while only having it effect one song. To add a script, you just put a script.hscript in the character or song's folder

What is HScript:

HScript allows the game to run haxe code while the game is running, apart from being dynamicly typed(Not requiring you to specify types), it's really close to Haxe, which itself is a bit like JS syntax if you're used to it.
You can find more about hscript here, Haxe here and haxeFlixel here.
Most Flixel classes are exposed to song and character hscripts. Many things should hopefully be easy to port from hardcoded to BR HScript.

Classes exposed to HScript:

Game:

  • PlayState (0.5.1+)
  • TitleState
  • Character
  • debug - If the game is in debug mode or not
  • makeRangeArray - Alias for numberArray(max:Int, ?min = 0), Makes array filled with numbers(?)
  • Alphabet (0.6.0+)
  • Note (0.6.0+)
  • EmptyCharacter (0.6.0+)
  • HealthIcon (0.6.0+)

Haxe:

Flixel:

Character methods:

All methods contain a reference to the character as the first argument

Method Description
startSong () Called when the song starts
endSong () Called when the song ends
initScript () Called when script is initialised
update (elapsed) Called every update
playAnim (animName) Called when an animation is about to be played
noteHitSelf (char,note) Called when a note is hit by the character
noteHitOpponent (char,note) Called when a note is hit by the opponent
addChars() (0.6.0+) Called after BF is added
addDad() (0.6.0+) Called after opponent is added
addGF() (0.6.0+) Called after GF is added
addUI() (0.6.0+) Called after UI is added
strumNoteLoad (arrow,charID) (0.6.0+) Called when a strumNote is loading, can be used to replace textures
strumNoteAdd (arrow,charID) (0.6.0+) Called when a strumNote is added
noteCreate (note,rawNote) (0.6.0+) Called on note creation, can be used to make custom notes with note.type. rawNote is the rawJson note the game processes, this is called before any textures are loaded
noteAdd (note,rawNote) (0.6.0+) Called after the note is finished loading
keyShit (pressArray, holdArray) (0.6.1+) Called when keyShit is called
keyShitAfter (pressArray, holdArray, hitArray) (0.6.1+) Called after the notes are hit in keyshit, hitArray is a array of the presses corrasponding to the notes hit

Song/Stage methods:

All methods contain a reference to playState as the first argument

Method Description
startSong () Called when the song starts
generateSong () Called when the song is done being generated
endSong () Called when the song ends
initScript () Called when script is initialised
update (elapsed) Called every update
beatHit () Called when a beat is hit
stepHit () Called when a step is hit
strumNoteAdd (Note,Player) Called when a strumNote is added. Player is 0.5.1+, True is if it's player strumline, false is not
noteHit/noteHitDad (char,note) Called when a note is hit
noteMiss (char,note) Called when the player misses with a note(0.8.0- Runs it whenever the player misses)
miss (char,direction) (0.8.1+) Called when the player misses without a notes
noteCreate (note,rawNote) Called on note creation, can be used to make custom notes with note.type. rawNote is the rawJson note the game processes called before the texture is loaded
addChars () (0.6.0+) Called after BF is added
addDad () (0.6.0+) Called after opponent is added
addGF () (0.6.0+) Called after GF is added
addUI () (0.6.0+) Called after UI is added
playAnim (anim,char) (0.6.0+) Called when a character plays an animation, char is the character that played this animation
noteAdd (note,rawNote) (0.6.0+) Called after the note is finished loading
afterStage () (0.6.0+) Called after the stage is loaded, Only for the stage hscript.
keyShit (pressArray, holdArray) (0.6.1+) Called when keyShit is called
keyShitAfter (pressArray, holdArray, hitArray) (0.6.1+) Called after the notes are hit in keyshit, hitArray is a array of the presses corrasponding to the notes hit
startCountdownFirst () (0.7.1+) Called after the camera is centered but before the arrows are added and the countdown. Use playCountdown to control the countdown manually, make sure to use playstate.startCountdown() to start the countdown
startCountdown () (0.7.1+) Called right before the timer for the countdown is started
startTimerStep (loopCount) (0.7.1+) Called every on every step in the timer

Characters have to be accessed using PlayState.CHAR(0.5.1+), however you can use these if you want easier access:

Method Arguments Description
charGet (charId, field) charId is the character's ID, field is the field to access, charGet(0,"curCharacter") would return BF's character name
charGet (charId, field, value) charId is the character's ID, field is the field to access, Value is the what to set it to
charAnim (charId, anim) charId is the character's ID, anim is the animation to play

For charId: 0=BF,1=Opponent,2=GF

BRtools

You can use BRtools to load sprites and play sounds without having to worry about the chart or character's folder path.
Available methods:

Method Arguments Description
BRtools.loadFlxSprite (x, y, PATH) Loads a png and returns a FlxSprite, example:
spacebarthing = BRtools.loadFlxSprite(0,0,"sprites/spacebar.png");
BRtools.loadSparrowSprite (x, y, PATH, ANIMATION, LOOP, FPS) Loads a xml and png, example:
spacebarthing = BRtools.loadSparrowSprite(0,0,"sprites/spacebar","spacepress",true);
BRtools.playSound (PATH, VOLUME) Plays a sound, example: BRtools.playSound("sounds/Alarm.ogg",1);
BRtools.cacheSound/Sprite (PATH) loads a sound/sprite into memory. Example BRtools.cacheSprite("sprites/spacebar.png");
BRtools.loadSparrowFrames (PATH) Loads and returns a FlxAtlasFrames object, can be used to replace the frames of an object if desired.
Example: OBJECT.frames = BRtools.loadSparrowFrames("sprites/object")
BRTools.getPath (PATH) (0.6.0+) Returns the hscript's path with the path provided concatenated
BRTools.loadGraphic (PATH) (0.6.0+) Returns a FlxGraphic
BRTools.loadText (PATH) (0.6.0+) Returns a string containing the file's contents
BRTools.unloadSprite/Sound/Text/Xml (PATH) (0.6.0+) Removes object from the objects array
Clone this wiki locally