Using commands with specific objects

Hi there. I am making a game in Quest using the online tool. I have very little programming experience and am using the interface to do everything.

I have a keyhole and I want you to be able to put a long hair pin into it and for it to display a message. However if you try putting anything else into the key hole I want a different message displayed. How is the best way to do this? I have tried making the keyhole a container, but can't seem to find a way to have one message if the hair pin is put in it and another if anything is put in it.

I thought another way would be to make a custom command - "put #object# in keyhole" but then I'd want to have a script IF the objects typed in instead of #object# is the hair pin it displays one thing, and if it is anything else then a different message is displayed, but I can't see a way to do this with the IF script.

Can anyone please help with this, bearing in mind that I don't know how to code.

Thanks very much.


I have tried making the keyhole a container, but can't seem to find a way to have one message if the hair pin is put in it and another if anything is put in it.

In the container tab, there's a space to enter a script to run when the player attempts to add an object. You'd want something like:

if (object = hairpin) {
  // do something here
}
else {
  msg (CapFirst(object.article) + " won't fit in the keyhole.")
}

(Within this script, the variable object will be whatever the player is trying to put in)


Thank you for your reply. I tried that. I opened the "Script to run when trying to add an object:" code view and pasted the code, with my text added. I got this error when I tried to "put hairpin in keyhole"

put long hairpin in keyhole
Error running script: Error compiling expression 'object = hairpin': Unknown object or variable 'hairpin'

Here's a screenshot of the GUI once I had put the code into the code view:
https://ibb.co/6wrjy0h

Here's what I put into the code view:
https://ibb.co/9sZNWhS

Am I doing it correctly? Thanks again for your help.


Unknown object or variable 'hairpin'

I should probably have mentioned it in the previous post, but in that code I assumed that the hairpin object's name is hairpin.

The error message implies that it isn't. You'll need to change hairpin in the code to be the name of the object.

If the object's name and alias are different, remember that the player's command ("put hairpin in keyhole") includes the alias of the object; while the script expression ("object = hairpin") uses the name of the object.


I would also point out that "As you put the hairpin" (etc) is not code. You will want to replace that with another "Print message" (or msg in code view) command to print the message.


Amazing. Thank you so much. That sorted it. I hadn't realised the hairpin was actually called long hairpin 🤦🏼‍♀️. All seems to be working now. Changed the name and added the print message and it seem to work perfectly 👍


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

Support

Forums