Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DEPRECATED! See notes in code and in first comment. (Bitsy engine mod: dialog function to exit to another room)
/*
************************************************************************
THIS GIST IS OUTDATED
There's a new version published in the bitsy-hacks repo, which changes
syntax to use parentheses instead of curly braces so the editor
doesn't eat your function calls! Go check out the new script and see
all the new stuff in the header comments.
bitsy-hacks repo at: https://github.com/seleb/bitsy-hacks
Direct link to the exit mod:
https://raw.githubusercontent.com/seleb/bitsy-hacks/master/exit-from-dialog.js
************************************************************************
===================================
DIALOG EXIT FUNCTION MOD (mildmojo)
===================================
Usage: {exit "<room name>,<x>,<y>"}
Example: {exit "FinalRoom,8,4"}
WARNING: In exit coordinates, the top left tile is (0,0). In sprite coordinates,
the BOTTOM left tile is (0,0). Make sure you use EXIT coordinates for X
and Y.
Installation:
1. Paste all this code at the bottom of your exported game's HTML file,
right BEFORE the last /script> tag.
2. Search the HTML file for "functionMap.set" and paste this line after all
the other ones:
functionMap.set("exit", exitFunc);
NOTE: For full editor integration, you'd also need to paste this code at the
end of the editor's `bitsy.js` file and add the `functionMap` line above
to the editor's `script.js`. If you'd rather use the vanilla editor,
just make sure not to edit dialog with {exit} calls in the dialog window.
Always edit them in the dialog textbox of the sprite/item window.
Editing a sprite or item's dialog in the dialog window will replace your
`{exit "room,5,6"}` with `{}` and you probably won't notice.
License: WTFPL (do WTF you want with it)
*/
// Global variable to store data from the exit function encountered in dialog.
var queuedDialogExit = null;
// Hook into the game reset and make sure exit data gets cleared.
var _clearGameData = clearGameData;
clearGameData = function() {
_clearGameData.apply(this, arguments);
queuedDialogExit = null;
};
// Hook into the dialog finish event; if there was an {exit}, travel there now.
var _onExitDialog = onExitDialog;
onExitDialog = function() {
_onExitDialog.apply(this, arguments);
if (queuedDialogExit) {
doPlayerExit(queuedDialogExit);
queuedDialogExit = null;
}
};
// Implement the {exit} dialog function. It saves the room name and destination
// X/Y coordinates so we can travel there after the dialog is over.
function exitFunc(environment, parameters, onReturn) {
parameters = parameters[0].split(',');
var roomName = parameters[0];
var x = parameters[1];
var y = parameters[2];
var roomId = names.room.get(roomName);
if (!roomName || x === undefined || y === undefined) {
console.warn('{exit} was missing parameters! Usage: {exit "roomname,x,y"}');
}
if (roomId === undefined) {
console.warn("Bad {exit} parameter: Room '" + roomName + "' not found!");
} else {
queuedDialogExit = {
room: roomId,
x: Number(x),
y: Number(y)
};
}
onReturn(null);
}
// `dest` looks like {room: roomId, x: Int, y: Int}
function doPlayerExit(dest) {
player().room = dest.room;
player().x = dest.x;
player().y = dest.y;
curRoom = dest.room;
}
@mildmojo

This comment has been minimized.

Copy link
Owner Author

@mildmojo mildmojo commented Feb 21, 2018

THIS GIST IS OUTDATED

There's a new version published in the bitsy-hacks repo, which changes
syntax to use parentheses instead of curly braces so the editor
doesn't eat your function calls! Go check out the new script and see
all the new stuff in the header comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.