Inspiration Pad for JavaScript

No, you're not reading that wrong!

I finally was able to get around to doing something I've always wanted to try. I used the Pas2JS transpiler to compile the Inspiration Pad engine to JavaScript. Not only did it compile, by golly it works! So, this means IPP generators can be run within a web page without a server-side script.

Check it out for yourself:
https://www.nbos.com/lab/ippjs/ippjs.html

Paste the full text of a generator in the box on the left (delete the sample table that's there now), and press go. That's it. Note that because this is running in-browser, the generators need to be fully self contained, and can't use any "Uses:" statements to bring in other files. Use File-Export from the menu in Inspiration Pad Pro to save a fully self contained generator file.

I've attached one of the more complex generators I've made, and it seems to run perfectly. Try pasting the contents of that into the left box and test it out!

The IP for JS API itself is very simple, its just a single function:

RunTable( sTable, nReps)

where sTable is the full text of the generator and nReps is the number of reps. It returns an array of results.

Let me know if you want to use the library for your own projects.

Comments

  • That's very cool. I assume it could be embedded in a website without showing the generator itself. I would love to embed some game-specific generators on our website.

    Do you think it would be possible to support prompts?

  • If you pull the generator off a server, you'd never have to make the generator itself visible to people viewing the site. Prompts I think would be possible. Of course the GUI for them would be completely up to the web site maker. Alternatively, since you'd have the full table text, you can also inject variables right into the the table text before running it by pre-pending the table with 'Set' commands.

  • Btw, everyone is welcome to grab the .js file from source of the above page and use it in their own projects.

  • So maybe prompts could be passed to the API as additional parameters? Dynamically altering the generator is an interesting option though. I'll have to play around with it.

  • Yes, I was thinking they could be passed as the 3rd parameter. But I have to review how that's done now, and check to see how the array could be passed because there's funky compatibility issues between Javascript and Delphi that have to be adjusted for. Astro also does something like that, but it populates arbitrary variables. so I think I can just send in a key/value list of variables and values : "prompt1" = "A", "prompt2" = "B", "var3" = "C".

  • If you're emulating prompts, they would always be prompt1, prompt2, prompt3, prompt4, so that part is redundant.

    That said, the idea of dynamically altering the generator gets around the limit of 4 prompts, so maybe there's something to be said for making the number arbitrary even if the variable names are fixed.

  • edited October 17

    Prompts and variables are added! You can look at the javascript on this page to see how they are added in:

    https://nbos.com/lab/ippjs/ippprompts.html

    If you want to set up GUI prompts based on the prompt entries in the generator file, you'll have to manually parse the the Prompt: lines in it. That that shouldn't be too complex. Also, I increased the Max number of prompts to 100.

Leave a Comment