@bitsy/hecks
Version:
a collection of re-usable scripts for bitsy game maker
53 lines (43 loc) ⢠1.77 kB
JavaScript
/**
ā
@file javascript dialog
@summary execute arbitrary javascript from dialog
@license MIT
@version 3.2.2
@requires Bitsy Version: 4.5, 4.6
@author Sean S. LeBlanc
@description
Lets you execute arbitrary JavaScript from dialog (including inside conditionals).
If you're familiar with the Bitsy source, this will let you write one-shot hacks
for a wide variety of situations.
Usage:
(js "<JavaScript code to evaluate after dialog is closed>")
(jsNow "<JavaScript code to evaluate immediately>")
Examples:
move a sprite:
(js "sprite['a'].x = 10;")
edit palette colour:
(js "getPal(curPal())[0] = [255,0,0];renderImages();")
place an item next to player:
(js "room[curRoom].items.push({id:'0',x:player().x+1,y:player().y});")
verbose facimile of exit-from-dialog:
(js "var _onExitDialog=onExitDialog;onExitDialog=function(){player().room=curRoom='3';_onExitDialog.apply(this,arguments);onExitDialog=_onExitDialog;};")
HOW TO USE:
1. Copy-paste into a script tag after the bitsy source
2. Add (js "<code>") to your dialog as needed
NOTE: This uses parentheses "()" instead of curly braces "{}" around function
calls because the Bitsy editor's fancy dialog window strips unrecognized
curly-brace functions from dialog text. To keep from losing data, write
these function calls with parentheses like the examples above.
For full editor integration, you'd *probably* also need to paste this
code at the end of the editor's `bitsy.js` file. Untested.
*/
;
import {
addDualDialogTag
} from "./helpers/kitsy-script-toolkit";
var indirectEval = eval;
function executeJs(environment, parameters) {
indirectEval(parameters[0]);
}
addDualDialogTag('js', executeJs);