Mittens 2017 is likely to be in Iceland in July. Check out the thread for details!

Author Topic: help! how to use two different inventory items to trigger change in hotspot  (Read 96 times)  Share 

I'm making my very first game on AGS and I would like to use two inventory items on a flowerbed to trigger a change in the hotspot where the flowerbed grows flowers. I'm trying to use what I learned on the internet but when I try using the two items on the hotspot, the display below won't play. Keep in mind that the Display below isn't all of what I'm going to put there, it's just going to be there until the flowerbed_useinv action fully works.

Code: Adventure Game Studio
  1. function cFlowerbed_UseInv()
  2. {
  3. if ((player.ActiveInventory==iSeeds) &&    
  4.       (player.ActiveInventory==iWATERingcan) )
  5.       {
  6.     Display ("Suddenly, three small, beautiful flowers rise from the soil!");
  7. }
  8. else if(player.ActiveInventory==iSeeds){
  9. player.Walk(465, 465, eBlock);
  10. Display("You throw all the seeds into the soil.");
  11. player.LoseInventory(iSeeds);
  12. }
  13. else if(player.ActiveInventory==iWATERingcan){
  14. player.Walk(465, 465, eBlock);
  15. Display("You pour the water onto the soil.");
  16. player.LoseInventory(iWATERingcan);
  17. }
  18. else{
  19. Display("You don't feel like putting that into the soil.");
  20. }
  21. }
  22.  

Also, I'm thinking about causing the flowers to grow by making the flowerbed a character and making each change in the flowerbed it's own separate view(there will be 3 changes/views)(cFlowerbed.changeview). I'll do that unless there is a way I can put all the flowerbed changes into one whole view and having the flowerbed change frames at scheduled times.  Is the changeview option recommended and is there a way to do the frame changing trick I mentioned?

dayowlron

  • been programming computers since 1981
    • I can help with AGS tutoring
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
The problem is you can only have 1 Active Inventory at a time. You need to set up a couple of variables to show when you have completed that particular task.
Give me a sec and I will write the script based on what you have there with proper indention also.

Code: Adventure Game Studio
  1. bool SeedsPlanted=false;
  2. bool SoilWatered=false;
  3. bool FlowersMessageDisplayed=false;
  4.  
  5. function cFlowerbed_UseInv()
  6. {
  7.     if(player.ActiveInventory==iSeeds){
  8.         player.Walk(465, 465, eBlock);
  9.         Display("You throw all the seeds into the soil.");
  10.         player.LoseInventory(iSeeds);
  11.         SeedsPlanted=true;
  12.     }
  13.     else if(player.ActiveInventory==iWATERingcan){
  14.         player.Walk(465, 465, eBlock);
  15.         Display("You pour the water onto the soil.");
  16.         player.LoseInventory(iWATERingcan);
  17.         SoilWatered = true;
  18.     }
  19.     else{
  20.         Display("You don't feel like putting that into the soil.");
  21.     }
  22.     if (SeedsPlanted &&  SoilWatered && !FlowersMessageDisplayed )
  23.     {
  24.         Display ("Suddenly, three small, beautiful flowers rise from the soil!");
  25.         FlowersMessageDisplayed=true;
  26.     }
  27. }
  28.  
  29.  

Also added the variable FlowersMessageDisplayed because after you see that message you don't want to see that message again if they use something else on the flower bed. Try that code out and see how it works.
« Last Edit: 21 Mar 2017, 03:43 by dayowlron »

dayowlron

  • been programming computers since 1981
    • I can help with AGS tutoring
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
Doesn't look like you are getting any other replies so I will attempt to answer the other part of your question.
I wouldnt use a character for the flower bed but rather use an object. It can animate if you need it to but you can also just change the graphic at various times if "animation" is not needed. If each of the 3 changes/views is just a matter of changing the graphic then you can do that by just setting the Graphic property of the object, but if each time the flowerbed changes state and there is some animation then you can do that with an object as well. Unless the flowerbed is going to be walking around or talking to other characters then it is actually better as an object.

Kumpel

  • On the way to break new ground...
    • I can help with AGS tutoring
    •  
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with proof reading
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Only downside of objects is that you can't rename them. So if he wants to change the Flowerbed into Flowerbed with seeds or flowerbed with flowers etc. he needs to add a new object for each name change. A character is far more flexible on that part.
Another one is the limitation of objects in a room. If this one is crowded with these, using a character here could be useful.

About character.ChangeView: I wouldnt recommend this because it is linked to a view and the loops are activated by the direction the character is looking to (or where he walks). This means you have to combine changeview with a character.FaceDirection to get different sprites of your flowerbed. It's much easier to use character.LockViewFrame for your purpose. Maybe some code in room_Load is needed to keep the flowerbed in its current state if the player returns to the room, but that should be easy.
« Last Edit: 22 Mar 2017, 03:19 by Kumpel »

It worked! Thanks!;):wink: