You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, after pressing a playable song, a Null Object Reference appears. I don't know if it has to do with the song itself, or if there's something missing in the state. If anyone knows how to fix this, lemme know.
Here's the State: (Names of songs are changed to avoid leaks and stuff)
class CustomFreeplayState extends MusicBeatState {
public function new() {
super();
}
override public function create():Void {
super.create();
FlxG.mouse.visible = true;
// Add buttons or UI elements for selecting songs
// Create a "Back" button to return to the main menu
var backButton:FlxButton = new FlxButton(50, 50, "Back", onBackPressed);
add(backButton);
// Load Story Songs (Top)
var 1Button:FlxButton = new FlxButton(50, 150, "SONG1", onSONG1Pressed);
var 2Button:FlxButton = new FlxButton(50, 200, "SONG2", onSONG2Pressed);
var 3Button:FlxButton = new FlxButton(50, 250, "SONG3", onSONG3Pressed);
// Load Epilogue Songs (Bottom)
var 4Button:FlxButton = new FlxButton(50, 350, "SONG4", onSONG4Pressed);
var 5Button:FlxButton = new FlxButton(50, 400, "SONG5", onSONG5Pressed);
add(1Button);
add(2Button);
add(3Button);
add(4Button);
add(5Button);
}
// Button Press Handlers for Story Songs
private function onSONG1Pressed():Void {
if (songExists('song1')) {
FlxG.mouse.visible = false; // Hide the mouse
PlayState.SONG = Song.loadFromJson('song1-hard', 'song1');
LoadingState.loadAndSwitchState(new PlayState());
} else {
showSongNotFoundMessage('SONG1', 'assets/songs/SONG1/song1.json');
}
}
private function onSONG2Pressed():Void {
if (songExists('song2')) {
FlxG.mouse.visible = false; // Hide the mouse
PlayState.SONG = Song.loadFromJson('song2-hard', 'song2');
LoadingState.loadAndSwitchState(new PlayState());
} else {
showSongNotFoundMessage('SONG2', 'assets/songs/SONG2/song2.json');
}
}
private function onSONG3Pressed():Void {
if (songExists('song3')) {
FlxG.mouse.visible = false; // Hide the mouse
PlayState.SONG = Song.loadFromJson('song3-hard', 'song3');
LoadingState.loadAndSwitchState(new PlayState());
} else {
showSongNotFoundMessage('SONG3', 'assets/songs/SONG3/song3.json');
}
}
// Button Press Handlers for Epilogue Songs
private function onSONG4Pressed():Void {
if (songExists('song4')) {
FlxG.mouse.visible = false; // Hide the mouse
PlayState.SONG = Song.loadFromJson('song4-hard', 'song4');
LoadingState.loadAndSwitchState(new PlayState());
} else {
showSongNotFoundMessage('SONG4', 'assets/songs/SONG4/song4.json');
}
}
private function onSONG5Pressed():Void {
if (songExists('song5')) {
FlxG.mouse.visible = false; // Hide the mouse
PlayState.SONG = Song.loadFromJson('song5-hard', 'song5');
LoadingState.loadAndSwitchState(new PlayState());
} else {
showSongNotFoundMessage('SONG5', 'assets/songs/SONG5/song5.json');
}
}
// Back Button Handler
private function onBackPressed():Void {
FlxG.switchState(new MainMenuState());
}
// Check if the song folder and json file exist
private function songExists(songName:String):Bool {
var capitalizedSongName:String = songName.substr(0, 1).toUpperCase() + songName.substr(1);
var songFolder:String = 'assets/shared/data/' + capitalizedSongName; // Capitalize the first letter of songName
var songJsonFile:String = songFolder + '/' + songName.toLowerCase() + '.json'; // Make sure the JSON filename is lowercase
return FileSystem.exists(songJsonFile);
}
// Show a message if a song is missing
private function showSongNotFoundMessage(songName:String, songJsonFile:String):Void {
trace("Song '" + songName + "' not found. Please implement this song.");
trace("Path: '" + songJsonFile + "'. Check if correct!");
}
}
Are you modding a build from source or with Lua?
Source
What is your build target?
Windows x64
Did you edit anything in this build? If so, mention or summarize your changes.
I've created a new state to replace Freeplay, but the OG state is still there.
The text was updated successfully, but these errors were encountered:
Describe your problem here.
Sometimes, after pressing a playable song, a Null Object Reference appears. I don't know if it has to do with the song itself, or if there's something missing in the state. If anyone knows how to fix this, lemme know.
Here's the State: (Names of songs are changed to avoid leaks and stuff)
package states;
import flixel.FlxState;
import flixel.FlxG;
import flixel.ui.FlxButton;
import flixel.input.mouse.FlxMouseEvent;
import backend.Song;
import states.PlayState;
import backend.MusicBeatState;
import states.LoadingState;
import sys.FileSystem;
class CustomFreeplayState extends MusicBeatState {
}
Are you modding a build from source or with Lua?
Source
What is your build target?
Windows x64
Did you edit anything in this build? If so, mention or summarize your changes.
I've created a new state to replace Freeplay, but the OG state is still there.
The text was updated successfully, but these errors were encountered: