Help with making a menu for using an item on another item?

I'm fairly new to Quest, and after having finished the tutorial I wanted to get a bit of practice by making a small one room escape puzzle. However, I'm running into some issues with how I want "using an item" to work.

So the basic idea for what I want is that if the player selects the "Use" option from the little drop down menu when clicking on a hyperlink for something that's in their inventory, I want the game to display a menu of all the potential objects they can use the item on. I know there's a built in box you can tick under the "Use/Give" tab, but I didn't like how disorganized it looked so I wanted to try and make my own instead, and make it easier to implement for each object by making it a function I could just call at anytime.

I've been testing this on the first item you can use in my game, which is a drawer from the table that the player can remove. Specifically the player has the option to reinsert the drawer into the table if they want to. The idea here is, if the player wants to, they can select "use" from the drop down table of the drawer's hyperlink, the game will prompt them with a menu/list of all the object in the room, they select "table", and they then "use" the drawer on the table by reinserting the former into the latter. The problem I'm having is with the function I'm making for the menu itself.

Here's what I have so far:

msg ("Use " +useditem.alias+ " on what?") //useditem is the only parameter for the function.
Nowhere.objectforuse = useditem 
roomobjectlist = NewObjectList() 
list add (roomobjectlist, table) // table is the only option to pick from the menu right now
ShowMenu ("Room:", roomobjectlist, true) {
  Nowhere.objectusedon = result
  msg ("" + Nowhere.objectusedon+ "." + Nowhere.objectforuse + ".")
  HandleUseOn (Nowhere.objectforuse, Nowhere.objectusedon)
}

The problem I'm running into is that the HandleUseOn function needs two objects for its parameters, but ShowMenu always returns a string no matter what I do. Is there any way to have ShowMenu return an object? Or at the very least is there a way for Quest to grab a specified object based on what the string is? I think it might be possible with a foreach loop or something, but I don't really understand how to use those yet.

Any help is greatly appreciated.


Hello.

This should handle it:

    msg ("Use " +useditem.alias+ " on what?")
    game.tempobject1 = useditem
    roomobjectlist = NewObjectList()
    list add (roomobjectlist, table)
    ShowMenu ("Room:", roomobjectlist, true) {
      object2 = GetObject(result)
      //msg ("object2: " + object2 + ". object1: " + game.tempobject1 + ".")
      HandleUseOn (game.tempobject1, object2)
      game.tempobject1 = null
    }

EDIT

Here it is with all the items and attributes your code is using:

msg ("Use " +useditem.alias+ " on what?")
Nowhere.objectforuse = useditem
roomobjectlist = NewObjectList()
list add (roomobjectlist, table)
ShowMenu ("Room:", roomobjectlist, true) {
  Nowhere.objectusedon = GetObject(result)
  msg ("" + Nowhere.objectusedon+ "." + Nowhere.objectforuse + ".")
  HandleUseOn (Nowhere.objectforuse, Nowhere.objectusedon)
}

From the documentation:

ShowMenu

As of Quest 5.7

ShowMenu will also take an object list, or a list of objects and strings. If the object has a link colour specified, this will be used. Note that result will always be a string, in the case of an object, it will be the object’s name.

ShowMenu ("Select", ScopeInventory(), true) {
  obj = GetObject(result)
  RemoveObject(obj)
  msg ("You smash the " + obj.name + " to bits.")
}

Ah, I should've known something like GetObject existed. I was over-complicating the whole process it seems. Thanks for your help; everything works perfectly now!


Log in to post a reply.

Support

Forums