ainslec / adventuron-issue-tracker

Adventuron Issues Tracker
4 stars 0 forks source link

[FEATURE] Calling "Done" during a "Mask" block to actually terminate the flow #460

Closed nww02 closed 2 years ago

nww02 commented 2 years ago

There are many cases where I want a subroutine to calculate something, and then decide whether to take an action or just let the default parser kick in. Unfortunately even the act of setting a variable will halt the flow in the match block, so I have to wrap anything "quiet" in a mask: However, what do I do if I really DO decide that I need to terminate the flow?

I need to put the :done; outside the mask. But that means I need to create a new variable , let's say "actually_done", and pass it outside the mask block:-


  some_sub : subroutine {
  :mask {
     :set_integer "some_calculation" {(1)};

     :if (some_calculation != 0) {
              :set_true "actually_done";
     }
     :else {
            :set_false "actually_done";
      }
}
 :if (actually_done) { :done;}
}

This would be cleaner if one could just :-

   some_sub : subroutine {
    :mask {
        :set_integer "some_calculation" {(1)};
         :if (some_calculation != 0){  :done;}
     }
    }

Calling 'done' from within a mask could probably be taken as a sign that the developer DOES want to affect the parse flow. There's "return" for non-interference options, after all, or simply just letting it fall through.

ainslec commented 2 years ago

Is the issue the "You can't do that"?

Sample code:

start_at = my_location

locations {
   my_location : location "You are in a room.";
}

on_command {

   : match "test _"  {
      : mask {
         : print "Should print";
         : done ;
      }
      : print "Should not print";
   }

   : match "test2 _"  {
      : mask {
         : print "Should print";
         : return ;
      }
      : print "Should not print";
   }

}

image

nww02 commented 2 years ago

Imagine having a bool to toggle whether the default handler should fire.

typing "true / false" should switch the behaviour when typing 'test'.


start_at = my_location

locations {

   my_location : location "You are in a room."
   {
      on_command {
         :match "true -" {
            :set_true "my_bool";
         }
         :match "false -" {
            :set_false "my_bool";
         }

         :match "test -" {
            :mask {
               :print  "Location Handler Fires.";
               :if (my_bool){
                  :done;
               }
            }
         }

      }
   }

}

on_command {
     :match "test -" {
            :mask {
               :print  "Global Handler Fires.";
               :done;
            }
         }
}

booleans {
   my_bool : boolean "false";
}

I've just checked 74m and it DOES seem to be allowing :done to terminate execution of the user-code handlers, but doesn't stop the main parser firing (So always getting "you can't do that").

image

ainslec commented 2 years ago

Fixed in beta 74r.

image