tag:blogger.com,1999:blog-6355249120999252418.post6243064176858179873..comments2023-05-13T03:10:47.276-07:00Comments on Writing JavaScript games in Haskell: The first interactive applicationNathan Hüskenhttp://www.blogger.com/profile/09614845657227846437noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-6355249120999252418.post-82536182499075487422013-08-25T04:27:24.170-07:002013-08-25T04:27:24.170-07:00For the lazy people (like me) here is small bash s...For the lazy people (like me) here is small bash script for doing the two insertions into the Main.html automatically after compiling: http://codepad.org/MdfhidlSDobihttp://daiw.denoreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-51805054218101018652012-12-02T00:03:43.824-08:002012-12-02T00:03:43.824-08:00You are absolutely right, using IORefs is imho a b...You are absolutely right, using IORefs is imho a better way of doing this. At the time of writing this posts, I was not aware. But if you look at the next post, I will use IORefs.<br /><br />I edited this post, mentioning IORefs as an alternative.<br /><br />Thanks for your comment! Nathan Hüskenhttps://www.blogger.com/profile/09614845657227846437noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-1599435941595027582012-12-01T16:58:39.927-08:002012-12-01T16:58:39.927-08:00"In haskell we do not have a mechanism such a..."In haskell we do not have a mechanism such as global variables (at least non that I am aware of)"<br /><br />Sure there is, you can use create an `IORef a` using `newIORef :: a -> IORef a`, and then use `readIORef`, `modifyIORef` etc.<br /><br />My drawing callback is `drawStuff :: IORef St -> IO ()` and bind the state when setting the initial interval callback to the IO action `drawStuff $ newIORef initialState`. Then `drawStuff` updates the state inside the IORef.<br /><br />Works in hastec, didn't try UHC. Great posts btw!Robinhttps://www.blogger.com/profile/08240995047820390813noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-66009924003759195642012-09-27T02:45:54.988-07:002012-09-27T02:45:54.988-07:00fixed, thanks.fixed, thanks.Nathan Hüskenhttps://www.blogger.com/profile/09614845657227846437noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-36865703545542996402012-09-27T02:39:39.187-07:002012-09-27T02:39:39.187-07:00In the "Letting callbacks communicate" s...In the "Letting callbacks communicate" section, "UHC" subsection, in the javascript code, the name of the JS function should be "jsSave<b>Global</b>Object", and not just "jsSaveObject". And similarly for "jsLoadObject".<br /><br />ഫിലിപ്പ്https://www.blogger.com/profile/08631069935697865263noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-6743103171235776332012-09-26T03:37:46.950-07:002012-09-26T03:37:46.950-07:00No problem, and thank you! It works as advertised ...No problem, and thank you! It works as advertised now. Time to actually read the post figure out how things work :) .ഫിലിപ്പ്https://www.blogger.com/profile/08631069935697865263noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-27468125969884813332012-09-26T03:31:48.169-07:002012-09-26T03:31:48.169-07:00Sorry, the links were pointing to old versions of ...Sorry, the links were pointing to old versions of JavaScript.hs and helpers.js (at that point I did not prefix the javascript functions with js). I updated the links, hope it works now!<br /><br />If not, do not hesitate to ask again.Nathan Hüskenhttps://www.blogger.com/profile/09614845657227846437noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-60456459867921395602012-09-26T02:52:19.931-07:002012-09-26T02:52:19.931-07:00I compiled successfully (yeah!) and copy-pasted th...I compiled successfully (yeah!) and copy-pasted the two lines to head and body, respectively, of Main.html. When I open Main.html in a browser (Chrome or FF), nothing shows. The JS error console shows the following error:<br /><br /><br /><i>Error: ReferenceError: jsSaveGlobalObject is not defined<br />Source File: file:///Users/dumbo/Haskell/javascript/JavaScript.mjs<br />Line: 57</i><br /><br />And the referenced line 57 looks like:<br /><br /><i>$JavaScript.$jsSaveGlobalObject=<br /> new _F_(function($__,$__2,$__3)<br /> {var $__4=<br /> _e_($__);<br /> var $__5=<br /> _e_($__2);<br /> var $__6=<br /> <b>_e_(jsSaveGlobalObject($__4,$__5));</b><br /> var $__7=<br /> _e_([]);<br /> return [$__3,$__7];});</i><br /><br />I grepped for jsSaveGlobalObject in the folder in which all of this happens, and this is what I got:<br /><br /><i>Binary file JavaScript.core matches<br />Binary file JavaScript.hi matches<br />JavaScript.hs:83:foreign import ccall jsSaveGlobalObject :: JSString -> a -> IO ()<br />JavaScript.hs:87:saveGlobalObject name obj = jsSaveGlobalObject (toJS name) obj<br />JavaScript.mjs:50:$JavaScript.$jsSaveGlobalObject=<br />JavaScript.mjs:57: _e_(jsSaveGlobalObject($__4,$__5));<br />JavaScript.mjs:194: return new _A_($JavaScript.$jsSaveGlobalObject,[$__]);});</i><br /><br />What could be wrong?<br />ഫിലിപ്പ്https://www.blogger.com/profile/08631069935697865263noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-2057517556757221092012-09-26T02:28:13.885-07:002012-09-26T02:28:13.885-07:00Doh! I got the helper files for Haste instead of u...Doh! I got the helper files for Haste instead of uhc. Ignore all of the above! Compiling works fine now.ഫിലിപ്പ്https://www.blogger.com/profile/08631069935697865263noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-60291941158520996272012-09-26T02:24:47.943-07:002012-09-26T02:24:47.943-07:00Nevermind. I was an idiot and did a right-click an...Nevermind. I was an idiot and did a right-click and "save file as" instead of following the link and copying the code. I did wonder why the "haskell" file started off with <DOCTYPE ...<br /><br />Now that I have the correct files in place, compiling is a snap and I get the following error:<br /><br />File not found:<br /> file name : Haste<br /> searched locations: " (directory)"<br /> " (package database)"ഫിലിപ്പ്https://www.blogger.com/profile/08631069935697865263noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-59407363894491405262012-09-26T02:16:59.444-07:002012-09-26T02:16:59.444-07:00I am trying to compile this using uhc. Following y...I am trying to compile this using uhc. Following your instructions, uhc -tjs Main.hs seems to be stuck at "[1/2] Compiling Haskell JavaScript (JavaScript.hs)" for ever.<br /><br />Does this file take long to compile for you as well? How long? ഫിലിപ്പ്https://www.blogger.com/profile/08631069935697865263noreply@blogger.comtag:blogger.com,1999:blog-6355249120999252418.post-46781363204663555962012-07-22T10:14:39.807-07:002012-07-22T10:14:39.807-07:00In the future you may want to consider replacing s...In the future you may want to consider replacing setInterval with a solution using requestAnimationFrame. That may make your animation smoother.Anonymousnoreply@blogger.com