Declaring Variables in a Room Script [SOLVED]

Started by Recluse, Thu 02/08/2007 02:20:08

Previous topic - Next topic

Recluse

Alright... this one's bugging me.

I'm trying to declare two variables at the top of a room script... basically I see no reason to clutter up my Global Script when the Room is going to be the ONLY entity using the variable.

I really don't want to use GraphicalVariables... since those bother the heck out of me (Why use a function to get/set when there's perfectly good, simple code to use)

I've almost got it working... but for some reason the game hangs after the following script executes...

Code: ags

// room script file

bool terminalOn = true;
bool spectrometerOpen = false;

export terminalOn, spectrometerOpen;

#sectionstart room_b  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
  // script for Room: Player enters room (before fadein)
	oTerminal.SetView(10);
	if(terminalOn == false)
		oTerminal.SetView(10, 1);
	
	oScreen.SetView(10, 3);
	oDock.SetView(10, 7);
	oDoor01.SetView(11, 0);
	
	if(day1VisitedMeetingRoom == true)
	{
	  if(day1HasKeycard == true)
			oKeycard.Visible = false;
		cEgo.FaceLocation(cEgo.x + 10, cEgo.y);
	}
	else
		cEgo.FaceLocation(cEgo.x,  cEgo.y - 10);

}
#sectionend room_b  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for Room: First time player enters room  
  if(isChemist == true)
  {
		oTerminal.Animate(0, 10, eRepeat, eNoBlock);
		Wait(120);
		// *** Play the comlink sound ***
		String nameComeIn = ", come in.";
		cCaptain.SayAt(35, 90, 250, cEgo.Name.Append(nameComeIn));
		cEgo.FaceLocation(103, 173);
		cEgo.Say("Yes, Captain Jaggers?");
		cCaptain.SayAt(35, 90, 250, "What's your current status?");
		cEgo.Say("Good Captain, I'm just wrapping up my daily logs.");
		cCaptain.SayAt(35, 90, 250, "Good, meet me in the meeting room, I've got something important we need to discuss.");
		cEgo.Say("Yes sir.");
		cCaptain.SayAt(35, 90, 250, "I'll see you in five minutes.");
		cCaptain.SayAt(35, 90, 250, "Jaggers out.");
		Wait(20);
		cEgo.Say("I'm going to need to turn off my terminal and get my keycard from the desk before I head to the meeting room.");
	}  
}


Could someone help me out here? If I can't do this and I should just place them in the Global Script... can you tell me why?
All your verbcoin are belong to us.

Gilbert

Are you sure that part of the code is the cause? After a very quick glance I don't see any offending problem in it, also, I don't think it has anything to do with room variables either. Since you mentioned hangs after the following script executes, it can be problems in other part of the script, possibly some while loops, or in the repeatedly_execute[_always]() function.

Can you post the full script of the room?

Recluse

Sure! Here it is:

Code: ags

// room script file

bool terminalOn = true;
bool spectrometerOpen = false;

export terminalOn, spectrometerOpen;

#sectionstart room_b  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
  // script for Room: Player enters room (before fadein)
	oTerminal.SetView(10);
	if(terminalOn == false)
		oTerminal.SetView(10, 1);
	
	oScreen.SetView(10, 3);
	oDock.SetView(10, 7);
	oDoor01.SetView(11, 0);
	
	if(day1VisitedMeetingRoom == true)
	{
	  if(day1HasKeycard == true)
			oKeycard.Visible = false;
		cEgo.FaceLocation(cEgo.x + 10, cEgo.y);
	}
	else
		cEgo.FaceLocation(cEgo.x,  cEgo.y - 10);

}
#sectionend room_b  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for Room: First time player enters room  
  if(isChemist == true)
  {
		oTerminal.Animate(0, 10, eRepeat, eNoBlock);
		Wait(120);
		// *** Play the comlink sound ***
		String nameComeIn = ", come in.";
		cCaptain.SayAt(35, 90, 250, cEgo.Name.Append(nameComeIn));
		cEgo.FaceLocation(103, 173);
		cEgo.Say("Yes, Captain Jaggers?");
		cCaptain.SayAt(35, 90, 250, "What's your current status?");
		cEgo.Say("Good Captain, I'm just wrapping up my daily logs.");
		cCaptain.SayAt(35, 90, 250, "Good, meet me in the meeting room, I've got something important we need to discuss.");
		cEgo.Say("Yes sir.");
		cCaptain.SayAt(35, 90, 250, "I'll see you in five minutes.");
		cCaptain.SayAt(35, 90, 250, "Jaggers out.");
		Wait(20);
		cEgo.Say("I'm going to need to turn off my terminal and get my keycard from the desk before I head to the meeting room.");
	}  
}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_c  // DO NOT EDIT OR REMOVE THIS LINE
function room_c() {
  // script for Room: Player enters room (after fadein)
	if(terminalOn == true)
		oTerminal.Animate(0, 4, eRepeat);
	if(cEgo.PreviousRoom == 2)
	{
	  PlaySound(3);
		oDoor01.Animate(0, 2, eOnce, eBlock, eBackwards);
	}  
}
#sectionend room_c  // DO NOT EDIT OR REMOVE THIS LINE

// **************************************
// *** Interaction with Cabinet Shelf ***
// **************************************

#sectionstart hotspot1_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot1_a() {
  // script for Hotspot 1 (Cabinet): Look at hotspot
  cEgo.FaceLocation(cEgo.x, cEgo.y + 10, eBlock);
  cEgo.Say("It's a cabinet full of chemicals and equipment.");
	if(isChemist == true)
		cEgo.Say("I'm the only Imperial that has access");

}
#sectionend hotspot1_a  // DO NOT EDIT OR REMOVE THIS LINE

// ********************************
// *** Interaction with Cabinet ***
// ********************************


#sectionstart hotspot2_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot2_a() {
  // script for Hotspot 2 (Cabinet): Look at hotspot
  cEgo.FaceLocation(cEgo.x, cEgo.y + 10, eBlock);
  cEgo.Say("It's a cabinet full of chemicals and equipment.");
	if(isChemist == true)
		cEgo.Say("I'm the only Imperial that has access");
}
#sectionend hotspot2_a  // DO NOT EDIT OR REMOVE THIS LINE

// *********************************
// *** Interaction with Terminal ***
// *********************************

#sectionstart object0_a  // DO NOT EDIT OR REMOVE THIS LINE
function object0_a() {
  // script for Object 0 (Terminal): Interact object
  cEgo.Walk(102, 161, eBlock);
  cEgo.FaceLocation(cEgo.x, cEgo.y - 10, eBlock);
  if(isChemist == true)
	{
	  if(terminalOn == true)
		{
			cEgo.LockViewFrame(cEgo.View, 4, 1);
			Wait(10);
			cEgo.LockViewFrame(cEgo.View, 3, 0);
			cEgo.UnlockView();
			oTerminal.Animate(2, 1, eOnce, eBlock, eBackwards);
			oTerminal.SetView(10,1);
			terminalOn = false;
			if(day1LoggedOff == false)
				day1LoggedOff = true;
		}
		else
		{
		  if(day1VisitedMeetingRoom == true)
				Display("DUMMY STUB FOR CHEMIST INTERACTION");
			else
				cEgo.Say("There's no reason to turn the terminal back on now."); 
		}
	}
	else
	{
	  cEgo.FaceLocation(cEgo.x, cEgo.y + 10, eBlock);
		cEgo.Say("I don't have access.");
	}
}
#sectionend object0_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart object0_d  // DO NOT EDIT OR REMOVE THIS LINE
function object0_d() {
  // script for Object 0 (Terminal): Look at object
  cEgo.Walk(102, 161, eBlock);
  cEgo.FaceLocation(cEgo.x, cEgo.y + 10, eBlock);
  if(isChemist == true)
		cEgo.Say("It's the terminal I do most of my work on.");
	else
		cEgo.Say("It's a terminal I don't have access to.");
}
#sectionend object0_d  // DO NOT EDIT OR REMOVE THIS LINE

// ********************************************
// *** Interaction with Spectrometer Screen ***
// ********************************************

#sectionstart object1_a  // DO NOT EDIT OR REMOVE THIS LINE
function object1_a() {
  // script for Object 1 (Screen): Look at object
  cEgo.Walk(206, 156, eBlock);
  cEgo.FaceLocation(cEgo.x, cEgo.y + 10, eBlock);
  if(isChemist == true)
		cEgo.Say("It's the display for the Spectrometer.");
	else
		cEgo.Say("It's the display for something that's beyond my field of expertise.");
}
#sectionend object1_a  // DO NOT EDIT OR REMOVE THIS LINE

// *************************************
// *** Interaction with Spectrometer ***
// *************************************

#sectionstart hotspot8_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot8_a() {
  // script for Hotspot 8 (Spectrometer): Look at hotspot
  cEgo.FaceLocation(cEgo.x, cEgo.y + 10, eBlock);
  if(isChemist == true)
		cEgo.Say("It's the spectrometer, a device which identifies and analyzes unknown chemical compounds.");
	else
		cEgo.Say("It's a piece of equipment that's beyond my area of expertise.");
}
#sectionend hotspot8_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot8_b  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot8_b() {
  // script for Hotspot 8 (Spectrometer): Interact hotspot
  if(isChemist == true)
		Display("DUMMY STUB FOR CHEMIST INTERACTION");
	else
	{
	  cEgo.FaceLocation(cEgo.x, cEgo.y + 10, eBlock);
		cEgo.Say("I wouldn't know how to start.");
	}
}
#sectionend hotspot8_b  // DO NOT EDIT OR REMOVE THIS LINE

// **************************************
// *** Interaction with Material Dock ***
// **************************************

#sectionstart object2_a  // DO NOT EDIT OR REMOVE THIS LINE
function object2_a() {
  // script for Object 2: Look at object
  if(isChemist == true)
	{
		cEgo.Walk(165, 161, eBlock);
		cEgo.Say("It's the dock for the spectrometer.");
		if(spectrometerOpen == true)
			cEgo.Say("It's currently open.");
		else
			cEgo.Say("It's currently closed.");
	}
	else
		cEgo.Say("It's a piece of equipment that's beyond my area of expertise.");
}
#sectionend object2_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart object2_b  // DO NOT EDIT OR REMOVE THIS LINE
function object2_b() {
  // script for Object 2: Interact object
  if(isChemist == true)
	{
    cEgo.Walk(165, 161, eBlock);
    cEgo.FaceLocation(cEgo.x, cEgo.y - 10, eBlock);
		if(spectrometerOpen == false)
		{
		  oDock.Animate(7, 2, eOnce, eBlock);
			oDock.SetView(10, 8, 0);
			spectrometerOpen = true;
		}
		else
		{
			oDock.Animate(8, 2, eOnce, eBlock);
			oDock.SetView(10, 7, 0);
			spectrometerOpen = false;
		}
	}
	else
		cEgo.Say("I wouldn't know how to start.");
}
#sectionend object2_b  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart object2_d  // DO NOT EDIT OR REMOVE THIS LINE
function object2_d() {
  // script for Object 2: Use inventory on object
  if(isChemist == true)
  {
    Display("DUMMY STUB FOR CHEMIST INTERACTION");
	}
	else
		cEgo.Say(Game.GlobalMessages[982]);
}
#sectionend object2_d  // DO NOT EDIT OR REMOVE THIS LINE

// **********************************
// *** Interaction with Left Door ***
// **********************************

#sectionstart object3_a  // DO NOT EDIT OR REMOVE THIS LINE
function object3_a() {
  // script for Object 3: Look at object
  cEgo.Walk(45, 162, eBlock);
  cEgo.Say("It's a door.");
}
#sectionend object3_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart object3_b  // DO NOT EDIT OR REMOVE THIS LINE
function object3_b() {
  // script for Object 3: Interact object
  cEgo.Walk(45, 162, eBlock);
  if (day1LoggedOff == true && day1HasKeycard == true)
  {
		cEgo.FaceLocation(30, 162, eBlock);
		PlaySound(2);
		oDoor01.Animate(0, 2, eOnce, eBlock);
		cEgo.ChangeRoom(2, 888, 156);
	}
	else
	{
		if (day1LoggedOff == false)
			cEgo.Say("I need to log off of my terminal first.");
		if (day1HasKeycard == false)
			cEgo.Say("I'm not leaving without my keycard.");		
	}
}
#sectionend object3_b  // DO NOT EDIT OR REMOVE THIS LINE

// **************************************
// *** Interaction with Testtube Rack ***
// **************************************

#sectionstart hotspot4_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot4_a() {
  // script for Hotspot 4 (Testtube Rack): Look at hotspot
  cEgo.Say("A bunch of testtubes, all nice and clean and ready to be used.");
}
#sectionend hotspot4_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot4_b  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot4_b() {
  // script for Hotspot 4 (Testtube Rack): Interact hotspot
  if(isChemist == true)
	{
	  Display("CHEMIST INTERACTION DUMMY STUB");
	}
	else
		cEgo.Say("That's not mine to use.");
  
}
#sectionend hotspot4_b  // DO NOT EDIT OR REMOVE THIS LINE

// ********************************
// *** Interaction with Keycard ***
// ********************************

#sectionstart object4_a  // DO NOT EDIT OR REMOVE THIS LINE
function object4_a() {
  // script for Object 4: Look at object
  cEgo.Say("That's my keycard.");
}
#sectionend object4_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart object4_b  // DO NOT EDIT OR REMOVE THIS LINE
function object4_b() {
  // script for Object 4: Interact object
  cEgo.Walk(120, 161, eBlock);
  cEgo.FaceLocation(cEgo.x, cEgo.y - 10, eBlock);
	cEgo.LockViewFrame(cEgo.View, 4, 1);
	Wait(10);
	cEgo.LockViewFrame(cEgo.View, 3, 0);
	cEgo.UnlockView();
	cEgo.AddInventory(iKeycard);
	oKeycard.Visible = false;
	day1HasKeycard = true;
}
#sectionend object4_b  // DO NOT EDIT OR REMOVE THIS LINE

All your verbcoin are belong to us.

Recluse

#3
I seem to have found the offending line by trial and error

Code: ags

In Player Enters Room: After Fadein

if(terminalOn == true)
	oTerminal.Animate(0, 4, eRepeat);


Commenting out the Animate function seems to fix the problem.

Oh look... I didn't add an eNoBlock...


This isn't embarrassing at all...

:-[
All your verbcoin are belong to us.

Ashen

It's always seemed odd to me that Animate (for Objects and Characters) defaults to blocking. It's right there in the manual of course, it just feels backwards. I guess I just used more non-blocking animations while I was learning AGS.

Also, for future reference, you don't need the export line. That's only for variables you want to make global, so it serves no purpose here; it's not harmfull to have it, it's just pointless. It should only really be used in Global and Module scripts - I don't think you can import variables declared in rooms scripts.
I know what you're thinking ... Don't think that.

Recluse

Thanks, I think that bit about the import/export on room scripts should be in the BFAQ

Oh yeah, I should add it myself... DUH
All your verbcoin are belong to us.

SMF spam blocked by CleanTalk