One of the first tasks I decided to work on was maybe the most simple one of the game, which is for the character to go to the fridge, collect an uncooked sandwich, try and toast it, plug the toastie machine in, and successfully toast it. Right now I’ve go the collecting of the sandwich and putting it on the toastie machine sorted, so today I want to work out the mechanics of making the character have to plug in the toastie machine. The current code looks like this:
and it works as it should, but I still have to make the player lose the sandwich from their inventory after using it.
It was refreshingly and surprisingly easy, all it took was this command player.LoseInventory(iSandwich); in the oToastieOpen_UseInv bracket. Onwards to the plug socket.
It’s difficult, I knew it would be. As it currently stands, my code looks like this:
What this should be telling the game to do, is that if the toastie maker isn’t plugged in (oSocket.Visible = false), then the game should tell the player that the toastie machine isn’t working. To its credit, the game does do that, but immediately afterwards, it puts the toastie in the machine and makes the plug socket visible for some reason. I think I’m supposed to have an if/ else function here, but the else part kept on giving me parse errors. Maybe the visible socket thing isn’t a strong enough anchor for creating conditions that allow object interactions.
Okay, I had a look at the AGS forum, which has been incredibly helpful for getting answers to many of the things I have been struggling with, I went over this entry: https://www.adventuregamestudio.co.uk/forums/index.php?topic=51533.0, and it helped me a little bit. So now my code looks like this
but, it still doesn’t work the way I intend it to. Now what happens is that as long as the player has yet to interact with the plug, the toastie machine stays broken, however, once the player has completed the plug interaction, the game gets rid of the socket objects, and it still says the toastie machine is broken.
I think I might understand the issue though, so all is not lost. I believe that rather than using the visible commands as the basis for other actions, the code is just making them the actions. So it’s like I’m saying if ________ then make the sockets visible/invisible, when I really want to be saying if the socket is visible this thing happens, if the socket is invisible something else happens. Understanding the problem is the first step to fixing it I guess, so I’ll try and figure that one out.