Skip to content

Using the REPL

Travis Thieman edited this page Jan 12, 2014 · 3 revisions

By default, Korhal runs an nREPL server on port 7777. Using an nREPL client, such as Cider in Emacs, you can jack in to the running Korhal process, issue commands to your units, and experiment with the Clojure API.

Connecting

  1. Make sure you can access port 7777 on the machine running Korhal. If you are using a VM, make sure you forwarded the port from the guest to the host OS as described in VM Setup.

  2. Tell your nREPL client to connect to the Korhal machine on port 7777. That's it! You'll probably want to go into a Korhal namespace to do things, for example by running (ns korhal.core). Additionally, you can put the AI entirely in control of your REPL instance by pressing r inside the game or by executing (repl-control! true).

REPL commands

There are a few special commands you'll need to use in the REPL.

(ns korhal.core)

; to disable the AI engines, giving you full control over your units
(repl-control! true)

; the cmd macro is analogous to with-api, but it will evaluate its result
; synchronously in the gameUpdate loop and print it back to you
(cmd (move (first (my-scvs)) 500 500)) 
=> true

; note that the following will still not work! the REPL runs in its own thread
; you have to use cmd to run unit commands in the gameUpdate loop
(move (first (my-scvs)) 500 500)
=> true ; but it's lying to you!
Clone this wiki locally