Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Problem with trying to add a clock/date system in Sugarcube

Hi, I'm making a game in Sugarcube that uses the inventory system, and I've tried to add a date/clock system that I've found on this site made by TheMadExile. For some reason once I add the required javascript for the clock it causes the inventory system to stop working, and it says that the macro <<initInv>> does not exist. This is how I have my javascript:
	window.getInv = function() {
  return state.active.variables.inventory;
}

macros.initInv = {
  handler: function(place, macroName, params, parser) {
    state.active.variables.inventory = [];
  }
};


macros.addToInv = {
  handler: function(place, macroName, params, parser) {
    if (params.length == 0) {
      throwError(place, "<<" + macroName + ">>: no parameters given");
      return;
    }
    if (state.active.variables.inventory.indexOf(params[0]) == -1) {
      state.active.variables.inventory.push(params[0]);
    }
  }
};


macros.removeFromInv = {
  handler: function(place, macroName, params, parser) {
    if (params.length == 0) {
      throwError(place, "<<" + macroName + ">>: no parameters given");
      return;
    }
    var index = state.active.variables.inventory.indexOf(params[0]);
    if (index != -1) {
      state.active.variables.inventory.splice(index, 1);
    }
  }
};


macros.inv = {
  handler: function(place, macroName, params, parser) {
    if (state.active.variables.inventory.length == 0) {
      new Wikifier(place, 'nothing');
    } else {
      new Wikifier(place, state.active.variables.inventory.join(','));
    }
  }
};

macros.invWithLinks = { 
  handler: function(place, macroName, params, parser) {
    if (state.active.variables.inventory.length == 0) {
      new Wikifier(place, 'nothing');
    } else {
      new Wikifier(place, '[[' + state.active.variables.inventory.join(']]<br>[[') + ']]');
    }
  }
};

macros.emptyInv = { 
  handler: function(place, macroName, params, parser) {
    state.active.variables.inventory = []
  }
};

var today = new Date();
var birthday = new Date('December 17, 1995 03:24:00');
var birthday = new Date('1995-12-17T03:24:00');
var birthday = new Date(1995, 11, 17);
var birthday = new Date(1995, 11, 17, 3, 24, 0);

var unixTimestamp = Date.now(); // in milliseconds

new Date();
new Date(value);
new Date(dateString);
new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

Could somebody take a look please?

Comments

  • Any errors in your Story Javascript area will cause all your javascript code to fail.

    The last three lines in your example are invalid Javascript, this is causing an error, and this is why you are getting the <<initInv>> does not exist error message.

    If you want/need to include information in your Story Javascript when you are working on code then you should wrap that text within a comment block /* */
    Replace the last three lines of your example with the following and it should work again:
    /*
    new Date(value);
    new Date(dateString);
    new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);
    */
    
  • Thanks so much!
Sign In or Register to comment.