How to create an event that only happens the second time you walk into a room?

Started by gracefully-gauche, Wed 09/05/2018 16:48:31

Previous topic - Next topic

gracefully-gauche

Hey, I had an idea for my game where I'd like a character to appear and block off a doorway, but only the second time you walk into a room. The character can be "defeated" (thus unblocking off the door and allowing for you to leave) by giving them three objects that you can pick up. I was thinking of triggering the character with a hotspot, but I know that if I do that, the character will appear every time you try to leave the room when I only want it to appear once. Is there a way for me to create a one-time event like this? Thanks!

ManicMatt

One way would be global variables. I'm not very good at explaining things, but if you look in the AGS manual, it should explain it.

But basically its a way of telling AGS if something should happen or not, in most cases.

Deep Dark Fears

I think that you could something like this using a variables.

Let's write that you have: a closed door (hotspot), a blocking person (character) and inventory items.

First you need to add a bool variable like IsThisSecondVisitInThisRoom. If it is, then you set ClosedDoor.Visible = true and same for character and also you could disable change room function. Second you add a variable for giving items like ItemAlreadyGiven or ItemCollected. When the player give first item to character, the value of variable is changed to one and when second item is given is two and so on. If the value is three then you set ClosedDorr.Visible = false and for character and re enabled change room function.

As for bool variable I think you can operate using room_Leave() funtion.


Code: ags

function room_Load()
{
    if((IsThisSecondVisitInThisRoom == true) && (IsCharacterDefeated == false))
    {
    //here you put code where you block door and a blocking character appears
    }
}

room_Leave()
{
if (IsThisSecondVisitInThisRoom == false) IsThisSecondVisitInThisRoom = true; //first leave
}


This is my idea for your question but remember that you could do different.

Matti

When leaving the room you can place the character in front of the door using Game.DoOnceOnly. This way he won't show up again after being defeated.

Duckbutcher

Create a global variable, let's call it “defeated” as per your description, but you can call it whatever you want. Set its default value to 0.


In “player enters room”, put

defeated+=1;

This will add one digit to the variable whenever the player enters. So when you enter the second time the variable will be 2.

Above this, also in player enters room, put

if (defeated==2){

and then what you want to happen. Important - after you've done what you want to happen, make sure to add another value to the variable, eg

defeated=3;
}

This will ensure the action isn't repeated.

Apologies for lack of code formatting, on my phone :)

Khris

If the value starts out being 0, and you check == 2 before increasing it, it won't be true until the third visit to the room.

Duckbutcher

Yeah, you got me Khris, apologies. Same as I said but check ==1 before rather than ==2 should work. Checking ==2 would work if you were doing your action in rep ex. Live n learn.

SMF spam blocked by CleanTalk