Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Cpt Ezz on Tue 06/05/2008 09:22:28

Title: Buttons
Post by: Cpt Ezz on Tue 06/05/2008 09:22:28
 :P
This may have been answered soom were but i cant find it  (By the way i'm a new person to AGS)

i'm making a sci-fi game and i want to push a button in the engine and make a "force field" turn of in another room
how do i do it???

Thankz Cpt Ezz
Title: Re: Buttons
Post by: Matti on Tue 06/05/2008 09:37:46
Your character needs to interact with a hotspot. The forcefield could be an object/variable that is turned off after interacting..

But you really should read the tutorial before we can help you..
Title: Re: Buttons
Post by: Khris on Tue 06/05/2008 10:45:44
Search for the OtherRoom module or use variables.

Other room thread count is now at 234'326.
Title: Re: Buttons
Post by: Matti on Tue 06/05/2008 13:25:45
Sorry, I didn't realize that your problem was accessing another room.

Like KhrisMUC said, you can use variables (if you don't want to use the module).

You can declare a variable in the main script header (like bool button=false) and export it to the two rooms, then import it in the two rooms. When the button is pressed, set the variable to true. Then, in the second room in the before_fadein-section check if the variable is set to true and have the forcefield disappear..
Title: Re: Buttons
Post by: Cpt Ezz on Wed 07/05/2008 07:51:34
thanks but could you you show me in script?(it would make more sense)
Title: Re: Buttons
Post by: Creator on Wed 07/05/2008 08:09:05
With the other room module:


OtherRoom.ObjectOff(3, 0);


This will make the forcefield (object 0) in room 3 turn off (considering your forcefield is and object and not a hotspot).

To use variables you could try:


SetGlobalInt(1, 1); //Turn forcefield off


and then in the room where the hotspot is (in player enters room before fadein):


if (GetGlobalInt(1) > 0) {
  oForcefield.Visible = false; //oForcefield is your object acting as a forcefield
}


For more on GlobalInts look in the manual.
Title: Re: Buttons
Post by: Cpt Ezz on Wed 07/05/2008 08:17:11
thank you a heaps guys
Title: Re: Buttons
Post by: Cpt Ezz on Wed 07/05/2008 08:28:20
i wrote it in and it says
Parse error unexpected 'if'
here i my code for it

room were object in

// room script file

function room_LeaveBottom()
{
player.ChangeRoom(2, 216, 8);
}
if (GetGlobalInt(1) > 0) {
  oforcefield.Visible = false;


code were hotspot(button) is on

function hbutton_Interact()
{
SetGlobalInt(1, 1);
}

what have i done wrong?
Title: Re: Buttons
Post by: monkey0506 on Wed 07/05/2008 11:41:23
You'll need to check your braces, and for future reference you can enclose your code in the [code][/code] tags.
// room script file

function room_LeaveBottom()
{
  player.ChangeRoom(2, 216, 8);
  // REMOVED BRACE CLOSING FUNCTION
  if (GetGlobalInt(1) > 0) {
    oforcefield.Visible = false;
  } // ADDED BRACE CLOSING CONDITIONAL
} // ADDED BRACE CLOSING FUNCTION
The corrected code (in the code tags):

function room_LeaveBotom()
{
  player.ChangeRoom(2, 216, 8);
  if (GetGlobalInt(1) > 0) {
    oforcefield.Visible = false;
  }
}


You should always be sure that your braces line up, and learning about indentation is a good way to do that. Also the editor does have a match-brace feature.
Title: Re: Buttons
Post by: Matti on Wed 07/05/2008 11:49:36
And your "If (GetGlobalInt(1) > 0) {}" has to be in the room_before_fadein-section of your room 2 like creator said.
Title: Re: Buttons
Post by: Khris on Wed 07/05/2008 12:41:27
Right, because following the logic behind the solution, the force field is supposed to turn (in)visible as soon as the player enters the room, but before the room is displayed.

"Captain" Ezz, please do the tutorial and also read the rest of the manual before asking trivial things having been asked and answered ten thousand times before.