Not sure if this would qualify as a "beginner question", given that other issues I've had turned out to be in fact quite advanced, but let's give this a try!
Rather than having an inventory for the game I'm working on, I would like to implement a "pick up object - use it on something else" system.
For example, say there's an empty glass on a table. If the player clicks on the object, the character will walk up to it (still not scripted in the example below) and the cursor will turn into the sprite of the glass while at the same time the object/sprite on the table is disabled:
Code: ags
Now with the glass as active inventory item / cursor, the player can use it on a hotspot on the wall and overhear a conversation.
So far, so good. Everything works as it should, except that when I hit right-click in order to deselect/release the active inventory item, I would like for the object to reappear in its original position.
The only way I have come up to do this would be to do a check for every single inventory item in the game to see which one the player is carrying and make the corresponding object visible. This code does the job nicely:
Code: ags
However, this only seems like a good idea because my game will have a very small number of items, but it doesn't seem like the most elegant or resource-optimized way to do this. Any suggestions for alternatives?
Rather than having an inventory for the game I'm working on, I would like to implement a "pick up object - use it on something else" system.
For example, say there's an empty glass on a table. If the player clicks on the object, the character will walk up to it (still not scripted in the example below) and the cursor will turn into the sprite of the glass while at the same time the object/sprite on the table is disabled:
function oGlass_Interact()
{
player.AddInventory(iGlass);
player.ActiveInventory = iGlass;
oGlass.Visible = false;
mouse.Mode = eModeUseinv;
}
Now with the glass as active inventory item / cursor, the player can use it on a hotspot on the wall and overhear a conversation.
So far, so good. Everything works as it should, except that when I hit right-click in order to deselect/release the active inventory item, I would like for the object to reappear in its original position.
The only way I have come up to do this would be to do a check for every single inventory item in the game to see which one the player is carrying and make the corresponding object visible. This code does the job nicely:
if (mouse.Mode == eModeUseinv && button == eMouseRight) {
if (player.ActiveInventory == iGlass) object[0].Visible = true;
// etc etc etc for every single inventory item!!
player.ActiveInventory = null;
}
However, this only seems like a good idea because my game will have a very small number of items, but it doesn't seem like the most elegant or resource-optimized way to do this. Any suggestions for alternatives?