[Solved] Quest 6 - "can't access property "onCreation", hash is undefined"

Hi,

I'm getting the error mentioned in the title whenever I try adding a custom template to my game (and adding an object that uses that template). I'm not entirely sure how to fix it, so here's what I've tried so far:

The original code:

const CYBERDECK = function(procslots, memslots, driveslots, jackslots) {
	const res = $.extend({}, TAKEABLE_DICTIONARY);
	res.procslots = procslots;
	res.memslots = memslots;
	res.driveslots = driveslots;
	res.jackslots = jackslots;
	
}

createItem("cyberdeck", TAKEABLE(), CYBERDECK(1,1,1,1), {
	loc:"coffee_table",
	examine: "Your cyberdeck. It has slots for one processor, one stick of RAM, an internal drive, and, of course, a neural jack.",
})

And the code after I tried to fix it myself:

const CYBERDECK = function(procslots, memslots, driveslots, jackslots) {
	const res = $.extend({}, TAKEABLE_DICTIONARY);
	res.procslots = procslots;
	res.memslots = memslots;
	res.driveslots = driveslots;
	res.jackslots = jackslots;
	
	res.onCreation = function(o) {
		if (!o.isAtLoc(game.player.name)) {
			list.push("Take")
		}
		else {
			list.push("Drop")
		}
	}
}

createItem("cyberdeck", TAKEABLE(), CYBERDECK(1,1,1,1), {
	loc:"coffee_table",
	examine: "Your cyberdeck. It has slots for one processor, one stick of RAM, an internal drive, and, of course, a neural jack.",
})

Hello.

You're going to be mad . . .

You have to return res at the end of your function. This works:

const CYBERDECK = function(procslots, memslots, driveslots, jackslots) {
	const res = $.extend({}, TAKEABLE_DICTIONARY);
	res.procslots = procslots;
	res.memslots = memslots;
	res.driveslots = driveslots;
	res.jackslots = jackslots;
	return res;
}

createItem("cyberdeck", TAKEABLE(), CYBERDECK(1,1,1,1), {
	loc:"coffee_table",
	examine: "Your cyberdeck. It has slots for one processor, one stick of RAM, an internal drive, and, of course, a neural jack.",
})

BUT, since you extended the TAKEABLE dictionary in the template, you can leave the TAKEABLE() out of createItem, like so:

createItem("cyberdeck", CYBERDECK(1,1,1,1), {
	loc:"coffee_table",
	examine: "Your cyberdeck. It has slots for one processor, one stick of RAM, an internal drive, and, of course, a neural jack.",
})

image


REFERENCE

https://github.com/ThePix/QuestJS/wiki/Custom-Templates


Ah, right. Thanks!


I would have suggested the same; it seemed odd to declare a local variable res and then discard it. But haven't seen the docs on this and wasn't sure how Quest 6 handles it.

Now I look at it, that seems an overly verbose way to create a template. To me, this seems both simpler and more intuitive:

const CYBERDECK = (procslots, memslots, driveslots, jackslots) => $.extend({},
	TAKEABLE_DICTIONARY, {
		procslots: procslots,
		memslots: memslots,
		driveslots: driveslots,
		jackslots: jackslots
	}
)

or even

const CYBERDECK = (procslots, memslots, driveslots, jackslots) => $.extend({
	procslots: procslots,
	memslots: memslots,
	driveslots: driveslots,
	jackslots: jackslots
}, TAKEABLE_DICTIONARY)

This topic is now closed. Topics are closed after 14 days of inactivity.

Support

Forums