Add Call/Return script commands

This commit is contained in:
Ryan Shepherd 2018-10-11 15:45:35 -04:00
parent 15ae3dafdb
commit 3af5ced1cd
2 changed files with 38 additions and 11 deletions

View File

@ -26,7 +26,10 @@ my %script_commands = (
'Define' => {'sub' => \&DefGameVar, 'wait' => 0},
'ExitGame' => {'sub' => \&PerlRPG::Game::ExitGame, 'wait' => 1},
'Jump' => {'sub' => \&PerlRPG::Script::RunScript, 'wait' => 0},
'Jump' => {'sub' => \&RunScript, 'wait' => 0},
'Call' => {'sub' => \&Call, 'wait' => 0},
'Return' => {'sub' => \&Return, 'wait' => 0},
'Show' => {'sub' => \&PerlRPG::Drawing::ShowSprite, 'wait' => 0},
'Hide' => {'sub' => \&PerlRPG::Drawing::HideSprite, 'wait' => 0},
@ -41,9 +44,29 @@ my %script_commands = (
my %sayers = ();
my $lastsayer=undef;
my @CallStack;
%game_vars = ();
sub Call {
my($label)=@_;
my @pos = ($current_file, $current_line+1);
if(RunScript($label)) {
push @CallStack, \@pos;
} else {
LogData(ERROR, "%s Unable to call '$label': Undefined label.", GetScriptPosition());
}
}
sub Return {
if(!@CallStack) {
LogData(ERROR, "%s Call stack underrun.", GetScriptPosition());
return;
}
my $ref = pop(@CallStack);
($current_file, $current_line) = @$ref;
}
sub GetGameVar {
my $key = shift(@_);
if(exists $game_vars{$key}) {
@ -112,9 +135,10 @@ sub RunScript {
if(exists $labels{$label}) {
$current_file = $labels{$label}{'File'};
$current_line = $labels{$label}{'Line'};
LogData(DEBUG, "RunScript($label) moving to $current_file:$current_line");
return 1;
} else {
LogData(ERROR, "RunScript($label) unknown label");
return 0;
}
}

View File

@ -6,7 +6,7 @@ drawroom:
SetBackground 0 0 0 255
SetAssetOption spritesheet.png Animated
AddSayer h "Hermione" aka01.png 255 0 0 255
AddSayer h2 "Hermione2" aka05.png 32 32 255 255 left flip
#AddSayer h2 "Hermione2" aka05.png 32 32 255 255 left flip
SpeechBorderSize = 3
SpeechBorderColor = "128 128 128 255"
@ -21,19 +21,22 @@ drawroom:
Show candler candle.png 400 100 11 flip
Show candlel candle.png 240 100 11
Show fireplacea fireplace_fire.vs 575 147 12
Show candlera fire.vs 400 95 12 flip
Show candlela fire.vs 240 95 12
#Show fireplacea fireplace_fire.vs 575 147 12
#Show candlera fire.vs 400 95 12 flip
#Show candlela fire.vs 240 95 12
Show desk 11_genie_00.png 230 220 13
Show hermione spritesheet.png 450 310 14 reverse ticks=4
#Show hermione spritesheet.png 450 310 14 reverse ticks=4
convo:
Wait
h "Continue..."
Wait
h2 "Continue2..."
Call subtest
RecompileScripts drawroom
Jump convo
subtest:
Define TestVar 1
h "Loop [TestVar]..."
TestVar = TestVar + 1
Return