Puzzle with scales (working with a group of multiple identical objects)
KFL
29 Apr 2020, 17:25I'm hoping to make a puzzle that requires the player to balance a scale by putting a certain number of different weights on one side to balance out one heavy weight on the other. The player finds a few different baskets filled with weights and needs to figure out how many of each to use.
How do I make it so they have to choose how MANY of a certain object to pick up/use? I could just make the "weights" a plural object and have the player put them as a collective unit on the scale, but that doesn't make for much of a puzzle. I'm assuming doing something with attributes is going to be involved but I haven't worked with them enough to know what I'm doing.
Any ideas?
Phadion
30 Apr 2020, 02:26I highly doubt this is the best way of going about this, and you should probably wait for a more experienced person to reply, but you could make different scenery objects for the different amount of weights. (naming them "weight", "2 weights", "3 weights", etc.) That way the player could input "pick up 3 weights" for example and have it do something different then if they picked up another number of weights.
mrangel
30 Apr 2020, 11:21In the past I've made a system which uses objects named "four weights", "three weights", "two weights", and "weight" stacked inside each other (and a script so that when they are placed in the same location, they automatically renumber). I'd make all except the highest number turn into scenery, so they can be accessed but don't show up in the room's list of objects.
The biggest problem is that you'd need to rewrite the "inventory" command to skip the extra objects; and alter the javascript to hide them. On the other hand, that shouldn't actually be too difficult now I've got a better understanding of how the Quest JS frontend works. In theory, I could change the object's listalias to something like [multiple:weight:3]
, hide all except the highest number, and then have a dropdown or spinner control appear next to the verb buttons when one is selected.
I posted this once before, but was told that I'm stupid, and should just make a single item that prompts the player to type a number after they drop it.
But here's a rough idea of how the system would work.
A weight's changedparent
script:
if (not GetBoolean (game, "movingstack") {
if (IsDefined ("oldvalue")) {
if (not oldvalue = null) {
game.movingstack = true
objects = FilterByAttribute (GetDirectChildren (oldvalue), "prototype", this.prototype)
for (count, 0, this.number-2) {
if (ListCount (objects) > count) {
obj = ListItem (objects, count)
obj.parent = this.parent
}
else {
CloneObject (this)
}
}
game.movingstack = false
CountStack (oldvalue, this.prototype)
}
}
CountStack (oldvalue, this.prototype)
}
And the function:
<function name="CountStack" parameters="location, type">
if (not location = null) {
number = 0
last = null
foreach (object, GetDirectChildren(location)) {
if (object.prototype = type) {
number = number + 1
last = object
object.scenery = true
object.alt = Split(object.pluralalias)
object.number = number
if (number = 1) {
object.alias = "one " + object.singlealias
list add (object.alt, "one " + object.singlealias")
list add (object.alt, "1 " + object.singlealias")
}
else {
object.alias = ToWords(number) + " " + object.pluralalias
list add (object.alt, ToString(number) + " " + object.pluralalias")
}
}
}
if (not last = null) {
last.scenery = false
if (number = 1) {
last.alias = last.singlealias
}
}
}
</function>
This means that you can create an object with attributes number
(initially 1), singlealias
("weight"), pluralalias
("weights"), and when multiple clones of it are put in the same place, they will automatically be numbered so that commands like "get four weights" and "drop 2 weights" will work as expected. "drop weight" will drop just one; and "get weights" will pop up a disambiguation menu asking how many (which the player can respond to by typing a number, because they'll be in numerical order).
Any verbs on those objects, or things like "use", should check the number of the object being used.
The additional objects become scenery, but I think any in the inventory list will still show up in the inventory pane if it's enabled. For more on how to resolve that, ask me when I'm not being called to lunch.
KFL
03 May 2020, 03:04Thank you!