ainslec / adventuron-issue-tracker

Adventuron Issues Tracker
4 stars 0 forks source link

[FEATURE] allow the target of a connection to be a parameterless subroutine #326

Open nww02 opened 3 years ago

nww02 commented 3 years ago

There are quite a few cases where I'd like to put some logic in about moving, but I either have to override a verb, or allow the player to go to a location and then change their location again, or set up a complex block with code and dynamic variables... It'd be SOOOO much simpler if I could set the target of a direction to be a subroutine name.

If "done;" isn't called at the end of the subroutine, the player's location is set back to where they were before the move, so (in effect) nothing happens. if :done is called, the player's location is not put back, and instead left with how the subroutine has set it (allowing the player to be moved programmatically).

It is assumed that the subroutine could be parameterless, so long as within the routine the developer can access the movement verb and current location, so they can decide what to do.

So, as an example, you could handle a conditional death / respawn case like so:-

  connections {
   from, direction, to = [    cliff_top, "jump", cliff_top_death(),
                                        cliff_top, "fly", cliff_top_death()   ]
  }

  subroutines {
     cliff_top_death : subroutine { 

          :if (verb_is "fly") { :print "As icarus found, the human body does falling well, and flying badly.";}

          :print "You were a very silly boy, you died on the rocks.";
           :ask_bool "rewind time?"  { var = should_rewind   }
           :if (!should_rewind)  {   :game_lose();   }
     }
 }

Note the use of "verb_is" to pick up which movemement verb was used... In this case to print a sassy message if the user tries to fly off the cliff rather than jump.

Or you could use it as a soft-block, as an alternative to barriers, where the barrier logic is opaque..... Like trying to move in a direction that's a conditional block:-

  connections {
   from, direction, to = [    pit, "climb", slide_back_down()   ]
  }

  subroutines {
     slide_back_down: subroutine { 
          :if (!is_wearing "gloves"){
            :print "You slide straight back down the slippery rope.";
          }
          :else {:print "you made it!";  :goto "well_house"; done;}
     }
 }

or you could use it as a randomizer for a maze:-

  connections {
             from, direction, to = [    twisty_passages1,      n, random_maze(),  
                                        twisty_passages1,      s, random_maze(),
                                        twisty_passages1,      e, random_maze(),
                                        twisty_passages1,    nw, random_maze(),
                                        twisty_passages2,      s, random_maze(),
                                        twisty_passages2,      e, random_maze(),
                                        twisty_passages2,    sw, random_maze(),
                                        twisty_passages3,      n, random_maze(),  
                                        twisty_passages3,      e, random_maze(),
                                        twisty_passages3,      w, random_maze(),
                                        twisty_passages_exit,  s, random_maze(),
                                        twisty_passages_exit, ne, random_maze(),
                                        twisty_passages_exit,  w, random_maze(),
                                        twisty_passages_exit,  u, surface,  
]
  }

  subroutines {

     random_maze: subroutine { 
            :execute_one_at_random{
              :goto "twisty_passages1";
              :goto "twisty_passages2";
              :goto "twisty_passages3";
              :goto "twisty_passages4";
              :goto "twisty_passages_exit";
            }
           :done;
     }
 }
ainslec commented 3 years ago

Again, just avoiding work here perhaps, but you could create a psuedo-location for dispatching logic based on connections:

start_at = lake

game_settings {
   enable_standard_all_behaviour = false
}

booleans {
   is_sunny : boolean;
}

locations {
   lake : location "You are by the side of a lake.\nIt is {is_sunny ? `<SUNNY<14>>` : `<NOT SUNNY<9>>`}\nType <SUNNY<13>> to change the weather.";
   forest : location "You are in a <sunny forest<14>>." ;
   lost_in_forest : location "You are lost in the <dark forest<9>>." ;

   subroutine_north_from_lake : location "" {
      on_pre_describe {
         : if (is_sunny) { : goto "forest" ; }
         : else { : goto "lost_in_forest" ; }
         : redescribe;
      }
   }
}

connections {
   from, direction, to = [
      lake, north_oneway, subroutine_north_from_lake, 
      lost_in_forest, south_oneway, lake, 
      forest, south_oneway, lake, 
   ]
}

on_command {
   : match "sunny _"  {
       : toggle "is_sunny" ;
       : print {("It is now " + (is_sunny ? "<sunny<14>>." : "<NOT sunny<9>>."))}

   }
}
nww02 commented 3 years ago

Yes, that was how I had it originally. I had a "cliff death" location and a "pit death" location and a "waterfall death" location... and so on and so on... and I thought to myself that it involves some tricksy overriding of descriptions to do the bouncing around. It also creates some interesting coding tangles when you need to rubber-band back where you came from, or kill off the player. It's a perfectly serviceable way of doing it, but it's less user friendly than it could be I guess 🙂


From: Chris Ainsley notifications@github.com Sent: 09 March 2021 14:49 To: ainslec/adventuron-issue-tracker adventuron-issue-tracker@noreply.github.com Cc: nww02 nww02@hotmail.com; Author author@noreply.github.com Subject: Re: [ainslec/adventuron-issue-tracker] [FEATURE] allow the target of a connection to be a parameterless subroutine (#326)

Again, just avoiding work here perhaps, but you could create a psuedo-location for dispatching logic based on connections:

locations { maze_going_north : location "" { : on_pre_describe { : if (some_condition) { : goto "somewhere_else";redescribe; } : else { : goto "back"; : print "You can't do that"; redescribe;} } } }

connections { from, direction, to = [ twisty_passages1, north, maze_going_north, ] }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ainslec/adventuron-issue-tracker/issues/326#issuecomment-793994945, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALFCUOKA37NRFRTBDG7LZ5DTCYYODANCNFSM4YZISNNA.

ainslec commented 3 years ago

Goto "back" should work for rubber banding.

On Tue, Mar 9, 2021, 15:35 nww02 notifications@github.com wrote:

Yes, that was how I had it originally.. and I thought to myself that it involves some tricksy overriding of descriptions to do the bouncing around. It also creates some interesting problems when you need to rubber-band back where you came from, or kill off the player. It's a perfectly serviceable way of doing it, but it's less user friendly than it could be I guess 🙂


From: Chris Ainsley notifications@github.com Sent: 09 March 2021 14:49 To: ainslec/adventuron-issue-tracker < adventuron-issue-tracker@noreply.github.com> Cc: nww02 nww02@hotmail.com; Author author@noreply.github.com Subject: Re: [ainslec/adventuron-issue-tracker] [FEATURE] allow the target of a connection to be a parameterless subroutine (#326)

Again, just avoiding work here perhaps, but you could create a psuedo-location for dispatching logic based on connections:

locations { maze_going_north : location "" { : on_pre_describe { : if (some_condition) { : goto "somewhere_else";redescribe; } : else { : goto "back"; : print "You can't do that"; redescribe;} } } }

connections { from, direction, to = [ twisty_passages1, north, maze_going_north, ] }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub< https://github.com/ainslec/adventuron-issue-tracker/issues/326#issuecomment-793994945>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ALFCUOKA37NRFRTBDG7LZ5DTCYYODANCNFSM4YZISNNA>.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ainslec/adventuron-issue-tracker/issues/326#issuecomment-794055277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABRJDSOBBSQDAAOGCVKXIDTCY52LANCNFSM4YZISNNA .

nww02 commented 3 years ago

Aye. As I put in #325, I'd like to do some more complex things when bouncing back than just setting location. The use of a load of dummy locations and overriding on_pre_describe is basically the same as calling a subroutine, but wrapping a location around it, except with the changing of location you'd have a load of other triggers firing.

So you'd have to be careful about graphics changing, themes, light/darkness, monsters following you and the screen refreshing as you go in and out of the locations. Bouncing back might also trigger the on_entry triggers for the previous location when you don't want to, so you'd need to write handlers to detect if you're arriving back after a bounce.... Lots of potential code burden on the developer. It'd be much easier to effectively keep the room the same, but just call a subroutine when you execute a movement verb.

Just a thought though.. I'll try to do it with the dummy logic locations and see how far I get..


From: Chris Ainsley notifications@github.com Sent: 09 March 2021 15:39 To: ainslec/adventuron-issue-tracker adventuron-issue-tracker@noreply.github.com Cc: nww02 nww02@hotmail.com; Author author@noreply.github.com Subject: Re: [ainslec/adventuron-issue-tracker] [FEATURE] allow the target of a connection to be a parameterless subroutine (#326)

Goto "back" should work for rubber banding.

On Tue, Mar 9, 2021, 15:35 nww02 notifications@github.com wrote:

Yes, that was how I had it originally.. and I thought to myself that it involves some tricksy overriding of descriptions to do the bouncing around. It also creates some interesting problems when you need to rubber-band back where you came from, or kill off the player. It's a perfectly serviceable way of doing it, but it's less user friendly than it could be I guess 🙂


From: Chris Ainsley notifications@github.com Sent: 09 March 2021 14:49 To: ainslec/adventuron-issue-tracker < adventuron-issue-tracker@noreply.github.com> Cc: nww02 nww02@hotmail.com; Author author@noreply.github.com Subject: Re: [ainslec/adventuron-issue-tracker] [FEATURE] allow the target of a connection to be a parameterless subroutine (#326)

Again, just avoiding work here perhaps, but you could create a psuedo-location for dispatching logic based on connections:

locations { maze_going_north : location "" { : on_pre_describe { : if (some_condition) { : goto "somewhere_else";redescribe; } : else { : goto "back"; : print "You can't do that"; redescribe;} } } }

connections { from, direction, to = [ twisty_passages1, north, maze_going_north, ] }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub< https://github.com/ainslec/adventuron-issue-tracker/issues/326#issuecomment-793994945>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ALFCUOKA37NRFRTBDG7LZ5DTCYYODANCNFSM4YZISNNA>.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ainslec/adventuron-issue-tracker/issues/326#issuecomment-794055277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABRJDSOBBSQDAAOGCVKXIDTCY52LANCNFSM4YZISNNA .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ainslec/adventuron-issue-tracker/issues/326#issuecomment-794060981, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALFCUOJRDQ2UPPBZF5GEEW3TCY6LXANCNFSM4YZISNNA.