For Ludum Dare 36
I decided to try a text based adventure game in coljure. It works, but I am getting a non-fatal error :
Exception in thread "main" java.lang.ClassCastException: seesaw.core.proxy$javax.swing.JPanel$Tag$fd407141 cannot be cast to clojure.lang.IFn, compiling:(/tmp/form-init2500875452880490300.clj:1:73)
(ns ludumdare36.core
(:gen-class :main true)
(:use seesaw.core))
(def story [
"Of all the most famous living rooms Transned's was the most famous"
"two"
"three"
"four"
"five"
"six"
"seven"
"eight"
"nine"
])
(def mainWindow (frame :title "Hello" :content "" :on-close :exit))
(defn draw
[items & args] (
(def mainWidget (vertical-panel :items items) )
(config! mainWidget :size [640 :by 480])
(config! mainWindow :content mainWidget)
(invoke-later(-> mainWindow pack! show!))))
(defn writeStory [text index & args]
(let [makeButton (fn mb [index text]
(button :text text :mnemonic \N :halign :center :listen [:action (partial writeStory (get story index) (inc index))]))
makeStoryNode (fn ms [text index]
(vector text (makeButton (inc index) "Yes") (makeButton (+ index 2 ) "No")))
]
(draw (makeStoryNode text index))))
(defn -main
[& args]
(writeStory (get story 0) 0))
The Ifn error is fairly well documented on stack, but I am not sure which function is causing the issue. Also not sure on the quality of my code. So feel free to post comments etc. How can I refactor to get rid of the Ifn error? What do I not understand?
(button ...)
at line 30? Without any possibility to run you code, this is the only suspect. Ifbutton
is a wrapper around a widget, you will get that kind of exception - it's in the head position. Otherwise, attach the stacktrace and original source, the project file is also useful. – Yuri Steinschreiber Sep 1 '16 at 18:14