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
function cTelephone_Talk()
{
cHank.Walk(132, 140, eBlock, eWalkableAreas);
dDialog0.Start();
}
Door Script
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
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:
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
}
}
Thanks for the quick reply.
I tried some stuff. Here's what I got.
I put this at top of GlobalScript.
bool Phone = false;
This in cTelephone Talk
function cTelephone_Talk()
{
bool (Phone == true)
cHank.Walk(132, 140, eBlock, eWalkableAreas);
dDialog0.Start();
}
and this in cDoor Interact.
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
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
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
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");
}
}
YOUR A LEGEND!!!!!:grin:
Thanks so much. I owe you one.
-A