Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OranShuster/41273d9e0b47125036a78ec32a298ff7 to your computer and use it in GitHub Desktop.
Save OranShuster/41273d9e0b47125036a78ec32a298ff7 to your computer and use it in GitHub Desktop.
Foundry VTT macro to calculate pythagorean distance
new Dialog({
title:'Example Dialog',
content:`
<form>
<div class="form-group">
<label>Distance</label>
<input type='text' name='distance'></input>
<label>Height</label>
<input type='text' name='height'></input>
</div>
</form>`,
buttons:{
yes: {
icon: "<i class='fas fa-check'></i>",
label: "Calculate"
}},
default:'yes',
close: html => {
let d = html.find('input[name=\'distance\']');
let h = html.find('input[name=\'height\']');
if (d.val()!== '' && h.val()!== '') {
let calc = Math.sqrt(Math.pow(parseInt(d.val()),2) + Math.pow(parseInt(h.val()),2));
let chatData = {
content: calc
};
ChatMessage.create(chatData, {});
}
}
}).render(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment