Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: milostnik on Mon 05/05/2014 09:25:19

Title: Making an object enabled and disabled for interaction???
Post by: milostnik on Mon 05/05/2014 09:25:19
Hey guys.

first time poster here.

I started making a P&C game for my major of uni and have enjoyed it so much.
I'm pretty terrible with coding but have found it quite easy in AGS compared to the other programs.

I've been stumped lately on the option to interact with a door only after you have completed a interaction with another object.
I've found some other things on this in the forums but I'm pretty new and dont understand the idea of creating a variable from scratch.

Run down: I have a main character (cHank) in Room 1. I want to talk to someone over the phone (cTelephone) before he is allowed to interact/open the door (cDoor) out of the office and into the cutscene room. Here are some of the basic codes I have already.

Telephone Script
Code (ags) Select

function cTelephone_Talk()
{
  cHank.Walk(132, 140, eBlock, eWalkableAreas);
  dDialog0.Start();
}


Door Script
Code (ags) Select

function cDoor_Interact()
{
  cHank.Walk(47, 154, eBlock, eWalkableAreas);
  player.ChangeRoom(3, 157, 146);
  aCarsBit.Stop(); 
}

So instead of just clicking the option to interact with the door and skip the phone conversation completely, is there a way to restrict that option and make sure cHank talks on the phone first, then the door unlocks?

Kind Regards

-A
Title: Re: Making an object enabled and disabled for interaction???
Post by: Slasher on Mon 05/05/2014 10:18:47
Hi,

you could use a Boolean. You can make one in the Global Pane or top of Room script (bool phone=false;).

Let's call the Boolean Name: Phone and set it to false.

You can set it to true either in dDialog0 or when using the telephone.

Then when interacting with door:

Code (ags) Select

function cDoor_Interact()
{
if(phone==true){
  cHank.Walk(47, 154, eBlock, eWalkableAreas);
  player.ChangeRoom(3, 157, 146);
  aCarsBit.Stop(); 
}
else // If phone is set to false
{
// Do this... like "I should answer the phone first before I leave" etc
}
}


Title: Re: Making an object enabled and disabled for interaction???
Post by: milostnik on Mon 05/05/2014 10:34:40
Thanks for the quick reply.

I tried some stuff. Here's what I got.

I put this at top of GlobalScript.
Code (ags) Select
bool Phone = false;

This in cTelephone Talk
Code (ags) Select
function cTelephone_Talk()
{
  bool (Phone == true)
  cHank.Walk(132, 140, eBlock, eWalkableAreas);
  dDialog0.Start();
}


and this in cDoor Interact.
Code (ags) Select
function cDoor_Interact()
{
  {
  if(Phone==true)
  cHank.Walk(47, 154, eBlock, eWalkableAreas);
  player.ChangeRoom(3, 157, 146);
  aCarsBit.Stop(); 
  }
  else
    {
      Display("I should call check the phone first and see if I got any messages");
    }
}


and it comes up with "GlobalScript.asc(546): Error (line 546): Variable '(' is already defined" (which is bool (Phone == true))

Sorry if this is a bit basic for you. I'm just a bit terrible with coding.

Thanks for the help.

-A
Title: Re: Making an object enabled and disabled for interaction???
Post by: Slasher on Mon 05/05/2014 12:17:41
Hi,

QuoteI put this at top of GlobalScript: bool Phone = false;
Global variables can be used throughout the game whereas room variables only apply to the room they are in.

Put it at the very top (header) of the ROOM script not Global if just for the one room.

Also
Code (ags) Select
bool (Phone == true) // you don't need to use the word bool, brackets or ==.

//Instead
phone=true; // this will turn phone boolean to true.

// so should be:

bool phone=false; // at the top of the ROOM script

//  Then do this function

function cTelephone_Talk()
{
  Phone = true;
  cHank.Walk(132, 140, eBlock, eWalkableAreas);
  dDialog0.Start();



Also

Code (ags) Select

function cDoor_Interact()
{
  { // bracket too many so delete this one.

  if(Phone==true) { //  I added this missed bracket
  cHank.Walk(47, 154, eBlock, eWalkableAreas);
  player.ChangeRoom(3, 157, 146);
  aCarsBit.Stop(); 
  }
  else
    {
      Display("I should call check the phone first and see if I got any messages");
    }
}


Title: Re: Making an object enabled and disabled for interaction???
Post by: milostnik on Mon 05/05/2014 14:00:30
YOUR A LEGEND!!!!!:grin:

Thanks so much. I owe you one.

-A