From 3af5ced1cd55e6db978bb8812be5e4f2f6162712 Mon Sep 17 00:00:00 2001 From: Ryan Shepherd Date: Thu, 11 Oct 2018 15:45:35 -0400 Subject: [PATCH] Add Call/Return script commands --- PerlRPG/Script.pm | 28 ++++++++++++++++++++++++++-- Resources/script.gs | 21 ++++++++++++--------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/PerlRPG/Script.pm b/PerlRPG/Script.pm index 0f180b4..c49d784 100644 --- a/PerlRPG/Script.pm +++ b/PerlRPG/Script.pm @@ -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; } } diff --git a/Resources/script.gs b/Resources/script.gs index 50afcda..53eb76f 100644 --- a/Resources/script.gs +++ b/Resources/script.gs @@ -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