Commands & Parser

These functions handle user input and core gameplay actions.

Core Commands

These functions are mapped to the parser and can be overridden or extended in your script via Booktasy.commands.

Command Function Description
go / move core_go(dir) Moves the player to the room in the specified direction exits.
look core_look(target) Describes current room if target is nil. Otherwise calls handle_command on entity or describes item.
talk core_talk(target) Calls handle_command("talk") on the target entity.
i / inventory core_inventory() Lists the names of items currently in Booktasy.INVENTORY.
take core_take(target) Handles taking items from the room or from an entity ("sword from guard").
give core_give(target) Transfers item from player to entity ("apple to king").
drop core_drop(target) Moves item from inventory to the current room.
save core_save(slot) Calls the native python_save (or JS equivalent) to write state to disk.
load core_load(slot) Loads state from disk and calls restore_state.
restart core_restart() Restores _INITIAL_STATE and re-runs Booktasy.init.

Parser Logic

Booktasy.parse_command(cmd)

Splits a raw input string into verb (first word) and target (rest of string).
Example:
" Look at Sword "verb = "look", target = "at sword".

Booktasy.ProcessCommand(cmd)

The main loop driver:

  1. Parses the command.
  2. Increments Booktasy.TURN_COUNT (unless the command is "free", like look or inventory).
  3. Looks up verb in Booktasy.commands.
  4. Executes the command function.
  5. Calls Booktasy.check_events() and Booktasy.update_timers().
  6. Checks if MAX_TURNS is reached.