Code question: making a command that executes other commands

I feel like I’m probably missing something super obvious, so feel free to point me to a relevant tutorial or even keywords to google if so.

I’d like to make a few commands that simplify things for players/admin by doing some of the commands for them automatically.

For example, something like a request command that puts a standardized title in place and then adds the appropriate category.

Or a command that both changes your stance and equips a certain weapon.

Is this possible? What should I be looking at?

1 Like

In general I would avoid trying to “trigger” other commands (to use a Penn/Tiny term) and look instead to leveraging or creating shared helper methods.

For example… lots of different commands can result in creating a job like what you’re describing. They don’t do it by triggering the request command, they do so by calling a shared helper:

 Jobs.create_job(category, title, description, author)

Same for poses - all of the various say/pose/emit commands leverage a pair of helpers (the first to translate things like :waves into Faraday waves, the second to actually emit):

 message = PoseFormatter.format(enactor_name, pose)
 Scenes.emit(enactor, message)

Stringing together helper methods is more efficient and cleaner than trying to directly execute other commands.

Excellent. That’s actually more how I’d go about it in Penn, too, but I’m still at that place where vocabulary is sort of hanging me up.

So in general, I should be looking in the helpers folder for things things that can be leveraged for this sort of thing?

Thanks so much for the reply!

Some of them will be in internal helper files like aresmush/plugins/scenes/helpers.rb and others will be in public API files like aresmush/plugins/scenes/public/scenes_api.rb.

The difference between internal helpers and public APIs is mostly semantic; you can use either one in your code. The public APIs are primarily called out to highlight intended links between plugins.
You can use the public ones with more certainty that they’re not going to change out from under you in a future release (once beta is complete).

Excellent, thank you! I have successfully used the Jobs.create_job helper, which is more exciting than it probably should be. :wink:

1 Like

Just wanted to say thanks again - today I managed to find almost all the helpers I needed AND make them work AND set up a config file system to use configurable variables. Thanks so much for all your documentation and tutorials. They have made a world of difference in figuring this out.

1 Like

Excellent! I’m glad someone was able to make heads-or-tails out of the code :slight_smile: