I've got some trouble working with Package scripts now. When I run all my singles, plurals, and the stage through the normal menu everything works as intended. However, when I launch the game through the package script, something strange happens.
Whenever I hit "Retry from Beginning" in my pause script which returns RESULT_RETRY, it keeps the game paused, and a new instance of the game opens up in the same window while the previous instance remains paused. At this point, there will be a paused instance of the stage and a running instance of the stage, and only the running instance detects key inputs. If I repeatedly select retry, more instances of the stage will open in the same way.
If I hit "Return to Title" for RESULT_END, the currently running instance of the stage will close because of TerminateStageScene(), and the most recent previous instance of the game will render and begin accepting key inputs. This will continue until all instances of the stage are closed, at which point, the package will close.
The code for my package script is below.
EDIT: I found out what the problem was. I was restarting the stage from the pause menu, meaning I couldn't finalize the stage scene. I moved the recursive TStageScene call to a point after calling FinalizeStageScene and now it works.
#TouhouDanmakufu[Package]
#Title["Touhou ~ Forlorn Souls of Wicked Past"]
#Text["-NL"]
#System["./system/Default_System.dnh"]
#Player["./player/player_reimu.dnh"]
@Initialize{
TStageScene(GetCurrentScriptDirectory ~ "x1/stage1.dnh", GetCurrentScriptDirectory ~ "player/player_reimu.dnh", "");
}
@MainLoop{
yield;
}
@Finalize{}
// STAGE SCENE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
task TStageScene(let stagePath, let playerPath, let replayPath){
ClearCommonData;
// Prepare the Stage Scene ------------------------------
InitializeStageScene();
// If a replay was called ------------------------------
if(length(replayPath) > 0){
SetStageReplayFile(replayPath);
}
let indexStage = 1;
SetStageIndex(indexStage);
SetStageMainScript(stagePath);
SetStagePlayerScript(playerPath);
StartStageScene();
loop{
// Hitting the pause key
if(GetVirtualKeyState(VK_PAUSE) == KEY_PUSH){
let resPause = RunPauseScene();
alternative(resPause)
case(RESULT_RETRY){
if(!IsReplay()){
TerminateStageScene();
TStageScene(stagePath, playerPath, replayPath);
ClearCommonData;
}
}
case(RESULT_END){
TerminateStageScene();
// ClosePackage();
}
}
let stgSceneState = GetStageSceneState();
if(stgSceneState == STAGE_STATE_FINISHED){
let stageResult = GetStageSceneResult();
alternative(stageResult)
case(STAGE_RESULT_CLEARED){
TEndScene();
break;
}
case(STAGE_RESULT_PLAYER_DOWN){
TEndScene();
break;
}
case(STAGE_RESULT_BREAK_OFF){
// TTitleScene();
TEndScene();
// ClosePackage();
break;
}
}
yield;
}
}
// PAUSE SCENE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function RunPauseScene{
RenderSceneToTransitionTexture();
PauseStageScene(true);
let pathScript = GetCurrentScriptDirectory ~ "system/New_Pause.dnh";
let idScript = LoadScript(pathScript);
StartScript(idScript);
while(!IsCloseScript(idScript)){
yield;
}
PauseStageScene(false);
let res = GetScriptResult(idScript);
return res;
}
// END SCENE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
task TEndScene{
if(IsReplay){
// TTitleScene();
return;
}
FinalizeStageScene();
while(GetVirtualKeyState(VK_OK) != KEY_FREE){yield;}
let dirModule = GetModuleDirectory();
let pathScript = GetCurrentScriptDirectory ~ "system/New_EndScene.dnh";
let idScript = LoadScript(pathScript);
StartScript(idScript);
while(!IsCloseScript(idScript)){
yield;
}
let result = GetScriptResult(idScript);
alternative(result)
case(RESULT_SAVE_REPLAY){
TReplaySaveScene();
}
case(RESULT_END){
// TTitleScene();
ClosePackage();
}
case(RESULT_RETRY){
TStageScene("","","");
}
}
// REPLAY SAVE SCENE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
task TReplaySaveScene{
let dirModule = GetModuleDirectory();
let pathScript = GetCurrentScriptDirectory ~ "system/New_ReplaySaveScene.dnh";
let idScript = LoadScript(pathScript);
StartScript(idScript);
while(!IsCloseScript(idScript)){
yield;
}
// TTitleScene();
ClosePackage();
}
function RenderSceneToTransitionTexture{
let textureName = GetTransitionRenderTargetName();
RenderToTextureA1(textureName, 0, 100, true);
}