Pull down a list of items to throw at

So I have a command called throw 2, with a pattern of Throw #object1# at #object2#. The code looks like this:

if (game.pov.parent = The Temple) {
  firsttime {
    msg ("You threw the Cookie Cat Fridge at the Centipeetle!<br/>Bzzzt!<br/>Centipeetle was shocked!<br/>Centipeetle was poofed!<br/>Centipeetle was defeated!")
    MoveObject (object1, object2)
    Centipeetle.dead = true
    RemoveObject (Centipeetle)
    game.Centipeetledefeat = true
    player.exp = player.exp + 20
    player.infight = false
    levelup
    msg ("Steven Universe gained 20 exp!")
    list add (game.rooms, Sea Spire)
  }
  otherwise {
    msg ("You can't do it twice!")
  }
}

I have the throw command on a cookie cat fridge that I want to throw at a Centipeetle. I want it so that when a player clicks throw on the verb, a list of items in the room is shown. How do I do this?


You'd presumably want to give the object a throw verb; something like:

targets = ScopeVisibleNotHeldNotScenery()
if (not Got (this)) {
  msg ("You can only throw it if you have it.")
}
else if (ListCount(targets) = 0) {
  msg ("There is nothing to throw it at.")
}
else {
  throw.projectile = this
  ShowMenu ("Throw it at what?", targets, true) {
    do (throw 2, "script", QuickParams ("object1", throw.projectile, "object2", GetObject(result)))
  }
}

Let me see if the code works...

It gave an error saying it didn't know what object or command throw 2 was.

Also when I play the game, it displays throw as a display verb, and even when I look back at it in edit view, there is no throw verb there.


It gave an error saying it didn't know what object or command throw 2 was.

You said you have a command called throw 2.
Check that the spelling/spacing/capitalisation is the same.

Also when I play the game, it displays throw as a display verb, and even when I look back at it in edit view, there is no throw verb there.

That's how automatically generated verb lists work.

If you'd rather have throw as a command, the script would work the same, just changing this to object. Or you could turn off the automatic verb list for that object.


You said you have a command called throw 2.
Check that the spelling/spacing/capitalisation is the same.

Alright, I'll do that.

If you'd rather have throw as a command, the script would work the same, just changing this to object. Or you could turn off the automatic verb list for that object.

Yes, I would like that.


Hey, I got it to work!

Just so we're clear, I also have a Toss command which works the same way. Will this work?

targets = ScopeVisibleNotHeldNotScenery()
if (not Got (this)) {
  msg ("You can only toss it if you have it.")
}
else if (ListCount(targets) = 0) {
  msg ("There is nothing to toss it at.")
}
else {
  toss.projectile = this
  ShowMenu ("Toss it at what?", targets, true) {
    do (Toss, "script", QuickParams ("object1", toss.projectile, "object2", GetObject(result)))
  }
}

So toss is the verb, and Toss is a command with an #object1# and #object2# in its pattern?
In that case it should work fine.


Okay, nevermind, now that I play it I keep getting errors.

turn off the automatic verb list for that object

Turning off the automatic verb list only makes it so the default verbs and the made verbs show up, even if I try adding a verb list in the interface script.

This is what I want:

  this.displayverbs = Split("Look at;Take", ";")
  this.inventoryverbs = Split("Look at;Throw")

An object has 3 verb lists:

  • this.displayverbs is shown when it's in the room - you can edit it on the "Object" tab
  • this.inventoryverbs is shown when it's in the inventory - you can edit it on the "Object" tab
  • this.generatedverbslist is a list that is generated the first time the player sees the object, containing the object's verbs (from the Verbs tab; or any verbs that have the same name as one of the object's attributes)

generatedverbslist appears whether the object is in the room or the inventory, so if you want a verb to only appear when it's in the inventory, you will either need to disable the generated verbs list (untick "Automatically generate object display verbs list" on the game's "Room Descriptions" tab; or for one object tick "Disable automatically generated display verb list for this object" on the object's Object tab), or you could give the object an initialisation script with:

this.generatedverbslist = NewStringList()

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

Support

Forums