hey folks,
I'm trying to use count.io to track how many people do specific actions in a game I'm working on. Ideally, at the end of the game, I'll be able to provide the player with a telltale-like list of how their decisions compare to the average distribution of decisions made by the playerbase.
I've written extensive JavaScript modifications to Twine 1.4.X games before, but I've never previously used APIs. This one is pretty easy, however, and I was able to successfully call it using Postman, but when I tried to write it up in a Javascript mod for Twine I started hitting some roadblocks.
Here's what I'm working with right now. This is a script in my game. I've replaced my token and the names of my counts with placeholder text to make it more readable:
try {
version.extensions['killbreen'] = {
major:1, minor:0, revision:0
};
macros['killbreen'] = {
handler: function(place, macroName, params, parser) {
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.count.io/1/count/[MY COUNT CATEGORY]/[COUNT I'M INCREMENTING]+", false);
xhr.setRequestHeader("Authorization", "[MY TOKEN GOES HERE]");
xhr.send();
new Wikifier(place, "You have killed it.");
}
};
} catch(e) {
throwError(place,"serveevent Setup Error: "+e.message);
}
Here's the error I'm getting. I also replaced the count/count group names here:
Error executing macro killbreen: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://api.count.io/1/count/[MY COUNT CATEGORY]/[THING I'M COUNTING]+'.
I bet this is a terrible javascript error I'm making because I really know very little about JavaScript. Any help would be appreciated, though!