Need to swap objects

In this case the player gets some fresh meat from the icebox. This starts a counter and after 10 turns the meat goes rotten.
I need a way of swapping the fresh meat for the rotten meat.
The problem is that during the 10 turns the player might drop the fresh meat in one of the locations, so where ever the meat is I need the fresh meat to be swapped with the rotten meat.

Can this be done in Quest?


(for simpler code, I assume that the names of your objects are fresh_meat and rotten_meat. Change the code smaples as appropriate)

Is the rotten meat stored outside player space somewhere until it's needed? In which case:

rotten_meat.parent = fresh_meat.parent
RemoveObject (fresh_meat)

Or if there's a location you want to put the fresh meat back in:

rotten_meat.parent = fresh_meat.parent
fresh_meat.parent = some_location

Or if you don't know where either of them will be but you want to swap them over:

temporary_variable = rotten_meat.parent
rotten_meat.parent = fresh_meat.parent
fresh_meat.parent = temporary_variable

In any case, if you want to notify the player only if they can still see the meat, you'd want to add some code like:

if (Contains (game.pov.parent, rotten_meat)) {
  msg ("You notice a faint smell of {object:rotten_meat}.")
}

(I used Contains rather than ScopeVisible and ListContains because I suspect that you'd smell rotting meat in the same room as you, even if it's inside a cupboard)


Thanks mrangel.

It looks like the command
rotten_meat.parent = fresh_meat.parent
moves the rotten meat to the same location as the fresh meat which is what I wanted.
Does this command also work if the player is carrying the meat?

Does this command
if (Contains (game.pov.parent, rotten_meat)) {
msg ("You notice a faint smell of {object:rotten_meat}.")
}
work if the player is carrying the rotten meat.

I'm going to use RandomChance(75) to remind player that something has a bad smell when the player is carrying the rotten meat or is in the same room as the rotten meat.

There are times when I need to type a command directly using the user interface so I'm wondering what I need to select in the drop down menu. At the moment I've select any command from the drop down command and then gone into the code view and have replaced the command. For example there is no drop down command for selecting the RandomChance so to type that in when using the user interface is there something that I can select from the drop down list.


Just tested both commands in a mock-up, and both work with the meat in the player's inventory on my end.

That last part about the RandomChance is a little confusing for me. Are you talking about adding in an if script command on the editor and looking for the RandomChance option to check with it?


For example there is no drop down command for selecting the RandomChance so to type that in when using the user interface is there something that I can select from the drop down list.

For most commands, as well as a list of different preconstructed parameters, there is an "Expression" option. This gives you a box in which you can type the code that goes between the brackets.

Once you've typed or pasted code in code view, you can usually go back to the GUI and it will show you how to enter that same code in GUI view (most often it involves typing a part of the code into the 'Expression' box)


Hi Whoreallycares

I didn't want the message that the rotten meat smells printed twice so I use a else if command, if the meat swaps from good to rotten then I want to message about the rotten smelling meat to be print, after that as long as the player has the rotten meat or is in the same room as the rotten mean then I need a 75% chance hint to the player that the meat is now rotten by displaying the smell message.


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

Support

Forums