From c0c5b6cf2cadf7d1554d0c08c5f29f39a37e8edd Mon Sep 17 00:00:00 2001 From: silverwizard Date: Fri, 23 Aug 2019 23:58:04 -0400 Subject: [PATCH] Fixed the table function to not suck --- Cyberpunk.pl | 53 ++++++---------------------------------------------- 1 file changed, 6 insertions(+), 47 deletions(-) diff --git a/Cyberpunk.pl b/Cyberpunk.pl index 26252d7..955245a 100755 --- a/Cyberpunk.pl +++ b/Cyberpunk.pl @@ -338,56 +338,15 @@ sub name{ sub table{ my $return; - $return = $_[10] . ": "; - my $var = roll(10,1); - SWITCH: { - $var == 1 && do { - $return = $return . $_[0]; - last SWITCH; - }; - $var == 2 && do { - $return = $return . $_[1]; - last SWITCH; - }; - $var == 3 && do { - $return = $return . $_[2]; - last SWITCH; - }; - $var == 4 && do { - $return = $return . $_[3]; - last SWITCH; - }; - $var == 5 && do { - $return = $return . $_[4]; - last SWITCH; - }; - $var == 6 && do { - $return = $return . $_[5]; - last SWITCH; - }; - $var == 7 && do { - $return = $return . $_[6]; - last SWITCH; - }; - $var == 8 && do { - $return = $return . $_[7]; - last SWITCH; - }; - $var == 9 && do { - $return = $return . $_[8]; - last SWITCH; - }; - $var == 10 && do { - $return = $return . $_[9]; - last SWITCH; - }; - } - $return = $return . "\n\n"; + my $length = scalar @_; + $return = $_[$length-1] . ": "; + my $var = roll($length-2,1); + $return = $return . $_[$var] . "\n\n"; return $return; } sub win{ my $return; - $return = $return . "You had a big win!\n\n"; + $return = "You had a big win!\n\n"; my $win = roll(10,1); SWITCH: { $win == 1 && do { @@ -446,7 +405,7 @@ sub win{ } sub romance{ - my $return; + my $return = ""; my $workedout = roll(10,1); if($workedout <= 4){ $return = $return . "You had a happy love affair, it worked out well\n\n";