Make so you can't leave room before doing specific thing

Started by Rocky_Johan, Tue 20/07/2021 02:55:25

Previous topic - Next topic

Rocky_Johan

Hi!
Total beginner here. Was looking trough the forum but couldn't find this specific thing.
I'm trying to do a room where a the character tries to buy some stuff from a store. Problem is he needs to pay the store clerk with money otherwise he isn't allowed to leave the store and has to return everything he has picked up.
How should i go about coding this?

Thanks!


newwaveburritos

Personally, I wouldn't make the player return everything they have picked up just for failing to pay.  That seems like a design choice that doesn't serve much purpose other than to annoy.  That they will learn that they need to pay without losing the items I think would be sufficient.  Also, it would be a lot easier since you wouldn't have to code that.  To make it so they can't leave before paying you need to make a variable and attach it to the exit event whether it's a room edge or a hotspot or whatever.

Code: ags

if (StoreClerkPaid == true){
  cStoreClerk.Say("Thanks for your purchase!");
  player.ChangeRoom(2);  //or whatever the next room is
}

else {
  cStoreClerk.Say("Hey you can't leave without paying, buddy!");
}


To make a variable you can put it into the Global Variables window and set its initial value to false then when you pay the Store Clerk you change its value to true.  If you don't need to use it again you can just declare it in the room script which will help you keep your Global Variables uncluttered but it's probably easier just to make a global variable for now until you get more comfortable coding stuff.


Add this to the paying the Store Clerk event:

Code: ags

StoreClerkPaid = true; //this assumes the global variable you created was a bool and called StoreClerkPaid


Also remember that once it's true it will always be true unless you put some code in there somewhere to make it false.  If that's the case you will need to set the variable each time the player goes back to the store and selects something that needs paid to be for like in the event for picking up the item in the first place.  That way they can enter the store and leave freely without the Store Clerk stopping them.

I would recommend watching Densming's AGS tutorials on YouTube.  You can really learn a lot from them.  https://www.youtube.com/watch?v=1Ml_DR76Cl4&list=PL21DB402CB4DAEAEF

Cassiebsg

That will work, if the player can only pickup and buy one thing (or one at a time).

I would probably use an int and call it something like valueToBePayed (or some other clever name). Start it at zero. Then just add the value of the item every time the player picks up at an item in the store, and decrees the same amount if the player places the item back in it's place (deciding he doesn't want it anyway). You can add this value as a custom property. This way you know exactly how much the player owns the store clerk and can even check if the player has enough money to pay for the item (and make him lose that amount when he's done paying).

Player can of course, only leave if (valueToBePayed == 0).  ;)
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk