Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Sun 24/04/2011 23:20:27

Title: How to do something after leaving a closeup? [solved]
Post by: HandsFree on Sun 24/04/2011 23:20:27
Hi again,

I have a letter in inventory and when you look at it you'll see a closeup. To do this I created a new room with the closeup of the letter and ShowPlayerCharacter set to false.
To 'leave' that screen I used ChangeRoom(character.PreviousRoom) because you can be anywhere when you look at the letter.

Now I want the character to comment after reading the letter, but if I put it in Room_Leave it will display while still in the closeup, and that looks messy.
So to display the comment after leaving the closeup, it looks like I have to put that code in every room (if character.PreviousRoom == CloseUp).
But I'm hoping there is an easier way to do that...

thanks
Title: Re: How to do something after leaving a closeup?
Post by: Matti on Sun 24/04/2011 23:56:04
Create a global variable (bool JustRead for example). Set the variable to true in the closeup room. Then put


if (JustRead){
  JustRead = false;
  player.Say ("Interesting...");
}


in the repeatedly execute function in the global script.
Title: Re: How to do something after leaving a closeup?
Post by: monkey0506 on Mon 25/04/2011 07:05:11
Actually, you don't even need a global variable for this. You could just use a script-wide variable (global within the scope of a given script, but local to that script, not accessible from other scripts). I'm thinking something along the lines of the global "after fade-in" event workaround (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=42404.msg562880#msg562880) that I concocted:

// GlobalScript.asc

bool JustRead = false;
// no need to export this, we're not using it in other scripts, only here!

function on_event(EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein)
  {
    if (player.PreviousRoom == LETTER_CLOSEUP_ROOM) JustRead = true;
  }
}

function repeatedly_execute()
{
  if ((JustRead) && (!IsGamePaused()) && (IsInterfaceEnabled()))
  {
    Display("Wow, what an interesting letter!");
    JustRead = false;
  }
}
Title: Re: How to do something after leaving a closeup?
Post by: Sephiroth on Mon 25/04/2011 09:01:38
Hello,

I don't know if there's a reason for using changeroom but I think you could use a gui the size of the screen, and use a button to display the letter or any other close up on it, so you just have something like:


//Global String CloseupDescription

function CloseUp(int sprite, String desc)
{
 PauseGame();
 CloseupDescription = desc;
 Button.NormalGraphic = sprite;
 CloseupGui.Visible = true;
}

//when a close up occurs

 CloseUp(10, "That letter was really intresting indeed.");

//when a close up is skipped

 UnPauseGame();
 CloseupGui.Visible = false;
 Display(CloseupDescription);



This could help if you're using more than one in the game and would simplify the Changeroom process. This is just an idea.
Title: Re: How to do something after leaving a closeup?
Post by: HandsFree on Mon 25/04/2011 22:47:40
I tried Matti's suggestion and it works. Thanks.
Monkey_05_06's code looks more complex at first sight. Is there a reason to do that? Will performance improve or something like that?

I'm just learning how AGS works and I'm using the RON template so I thought creating a GUI was a bit out of scope for now.
I used the changeroom because it says in the tutorial that ShowPlayerCharacter when checked (that should be 'when false' I assume) is "Useful for close-up displays of control panels and so forth".
How is using a GUI easier than ChangeRoom?

thanks
Title: Re: How to do something after leaving a closeup?
Post by: Sephiroth on Mon 25/04/2011 22:54:59
Will you have one room for each close up?

I don't know how the ron template works but the whole process of changing room and then having to split the code inside after_fadein etc is harder than actually creating a gui and a button which takes 3 clicks to accomplish.

I'm just suggesting what I think would be easier, if you get things working that's what counts ;)
Title: Re: How to do something after leaving a closeup?
Post by: HandsFree on Tue 26/04/2011 21:27:22
Yes, I thought I should have one room for each closeup. But I don't know how many closeups there will be or how many need a comment.
I'm not following an exact plan or anything, for now I'm just seeing how everything works.
When I'm more comfortable with the basics I'll probably look into the GUI thing.

thanks