curiousdannii / ifvms.js

The Interactive Fiction Virtual Machines Suite - in Javascript
MIT License
91 stars 22 forks source link

examples for using ifvms.js (client side + maybe server side too?) #10

Closed jedi4ever closed 11 years ago

jedi4ever commented 11 years ago

Hi @curiousdannii , over the last weekend I've taken a great interest in Interactive Fiction.

I'm building a work situation simulator and would love to use ifvms.js or other javascript framework to 'play' these kind of situation.

1) From the code, it's hard to understand how to embed/use ifvms.js in your own code. It would be great if you have some examples to load it

2) I could not tell if the code only works inside a browser environment or you could also use it in a nodejs backend process that emit events that could be visualised through socket.io on the browser.

I've seen you have some tests, but from what I can judge the are running inside the browser? My idea is to :

3) I also like to integrate 'real' events , inside the game. Could the backend play/capture events and execute some stuff and give back some results? Like a bot command on irc or so.

Any hints you can provide here are greatly appreciated!

curiousdannii commented 11 years ago

Only got time for a quick answer right now, sorry! Take a look at https://github.com/curiousdannii/ifvms.js/blob/master/dist/bootstrap.js to see ZVM being used in node.js. https://github.com/curiousdannii/parchment/blob/master/src/structio/runner.js is used in Parchment on the web.

It's designed to be used with Web Workers (though it isn't yet...), so everything happens with two functions: ZVM.inputEvent() and ZVM.outputEvent().

jedi4ever commented 11 years ago

awesome! thanks for the pointers. this looks really promising!

jedi4ever commented 11 years ago

vm = ifvms.bootstrap.zvm('a.z5',['one', 'two']);  
// This seems to work for a few of the examples provided but not for my inform7-> down compile z5 code
console.log(vm.output); 

// Now how do I continue on this thread?
vm.inputEvent({ code: 'read' , response: 'three' });
curiousdannii commented 11 years ago

You'll want to write your own event handler... the bootstrap one is very simple because I know what events it will produce. runner.js (in Parchment) handles quite a few more, as does api.js in the same folder.

The read event needs a number of other properties, which is why I add the response text on to the original event object and then give it back to the engine. Which now that I think about it is a really poor design... you should be able to just send back the response text by itself. I'll get around to changing that, eventually.

jedi4ever commented 11 years ago

We can close it here - I've started to work something out -

See https://github.com/jedi4ever/ifplayer.js , still could use your guidance obviously!

curiousdannii commented 11 years ago

Sure thing, ask anytime. The parchment Google group is probably the best place. Oh, and keep a lookout for changes to the API, it's quite unstable at the moment. If you have any suggestions for improvements to it I'd be happy to hear them.