Cannot figure out how to give
wariodude128
05 Jan 2022, 04:21So I've set it up so an object can be given to another object while said object is in my inventory, but when I play the game to test it nothing happens. Even when I add Give to the inventory verbs on the Object tab. In the Use/Give tab for the first object, I have Handle objects individually for Give this to (other object) and a thing to happen. In the Use/Give tab for the second object, I have Handle object individually for Give (other object) to this. I thought one of those should have caused me to give the object to the other, but nope. Even specified which object it should be given to and what object is being given. What am I missing?
mrangel
05 Jan 2022, 12:51In the Use/Give tab for the first object, I have Handle objects individually for Give this to (other object) and a thing to happen. In the Use/Give tab for the second object, I have Handle object individually for Give (other object) to this.
So is the thing not happening?
Is the code you've put in there not working as expected? Is it giving an error message? Is it just doing nothing?
You have two scripts there. One of them should be running. If it isn't, I think we'll need to see your game to work out why not.
wariodude128
05 Jan 2022, 15:27Well, when I click on give this to when running the game, what comes out is the game thinking I'm giving the object in my inventory to the object in my inventory. Obviously that should not be happening.
mrangel
05 Jan 2022, 21:32I'm sorry, that description isn't helpful. You say "the game thinking I'm giving the object in my inventory to the object in my inventory" - how do you know that? Have you got a script set to run in this case?
It would be much easier to solve this problem if you could share the game in question (or just the code for the relevant objects).
I assume that for the inventory object, the option for "Give (on its own)" is set to "Default behaviour", and you have ticked the box for "Display menu of objects this can be given to". Is that right?
Does it display a menu of objects to choose from, or does it give the wrong response right away?
wariodude128
05 Jan 2022, 22:53Well, that was silly of me. I didn't realize I had to checkmark a thing saying to display menu of objects this can be given to. Played the game and now I have a new problem: It lists objects other than the one it can be given to despite writing in the menu caption which object it should work on. Is there a way to make it so only the object I want to have it used on shows up as a hyperlink?
mrangel
06 Jan 2022, 01:00The menu shows all objects that the player can see. So the player can attempt to give it to the wrong object, and then get a message telling them they did it wrong.
If you want them to only have one option, why not change the behaviour to "Run script" and make it do whatever the thing is.
You could have a script like:
if (ContainsReachable (game.pov.parent, object_you_can_give_it_to)) {
msg ("You give it to the {object:object_you_can_give_it_to}.")
HandleGiveTo (this, object_you_can_give_it_to)
}
else {
msg ("The guy you can give it to isn't here.")
}
That will mean that when the player types "give thing" when they are in the same place as the other object, it will show a message and then act the same as "give thing to other object".
If you want to display a menu even when there's only one object you can give it to, you could make the "Give single" script something like:
candidates = NewObjectList()
// Add a line here for any other objects the player can try to give it to
list add (candidates, object_you_can_give_it_to)
not_accessible = ListExclude (candidates, ScopeReachable())
candidates = ListExclude (candidates, not_accessible)
if (ListCount(candidates) = 0) {
msg (Template("NoObjectsAvailable"))
}
else {
game.pov.givemenuobject = this
if (HasString(this, "givemenuprompt")) {
menucaption = this.givemenuprompt
}
else {
menucaption = Template("GiveToMenu")
}
ShowMenu (menucaption, candidates, true) {
if (result <> null) {
HandleGiveTo (game.pov.givemenuobject, GetObject(result))
game.pov.givemenuobject = null
}
}
}
(This is just a copy of the "Default behaviour" script, with the way it generates the list changed)
wariodude128
06 Jan 2022, 01:21Is there a way to do that without looking at code? The tutorial made it seem like you could do almost everything by using the interface alone.
mrangel
06 Jan 2022, 10:20You can enter all that using the point-and-click UI; but it will be quite time consuming.
One big advantage of code view is that you can paste in a chunk of code somebody gave you and then switch back to whichever editing mode you prefer.
wariodude128
06 Jan 2022, 14:52I think I'm just going to deal with it, seems like too much of a hassle. Point is, I figured out how to give. Now I just need to figure out how to make it so an image appears after setting a flag on an object. One appears originally and when you give an object like a ball to it another image appears when you look at it along with a new description. Did it with with an "if" command for the first one, now I just need to figure out how to use "else if" to do the other.