how to make an action in one room affects another room

Started by Bryan_abos, Wed 30/08/2017 04:12:15

Previous topic - Next topic

Bryan_abos

i'm making a game using the Monkey Island style gui. In my game, the player is on a room (room 1) where there is a computer.
For the interface of the computer I made another room (room 2) and put the icons as hotspots.

What I want to do is that when the character cliks on an icon from the computer (room 2), an object appears on room 1.
is there a way to do something similar? is it clear my explanation????

Slasher

Use a Variable Boolean.

Open up the Global Variable node in the Editor Tree.

Right click and add new variable; give it a Name, set Type to Boolean and set value to false.

When you click on the icon from the computer set the Boolean to true.

Code: ags

function Icon_Interact() // Name of Object / Hotspot
{
 computerIcon=true; // Name of Boolean set to True
}




In room 2, make an if statement to set object to visible.

Code: ags

function room_Load()
{
 if(computerIcon==true) // Name of Boolean
 thisobject.Visible=true; // object Name / ID
}








Bryan_abos

EDIT 2:: i named the hotspot in the script with the wrong name... now it works perfectly.. THANK YOU MAN!!

EDIT 1::

I created the bool and set it false. Then I put the following in both rooms.
Room 1 script:

Code: ags

function room_Load()
{
  oSound.Visible=false;
  if(vFinder==true) {    //bool set true
    {
    oSound.Visible=true; //makes object appear
    }
  }
}


Room 2 script:

Code: ags

function hFinder_AnyClick() // Name of Object / Hotspot
{
  if(player.HasInventory(iCelu)) {
  vFinder=false; //if the character has that object the bool stays the same
  }
  else
  {
  vFinder=true; // Name of Boolean set to True
  }
}


I used click any insted of interact because it is what i was using before and worked. when I click the hotspot hFinder (icon that makes the object appear) an error is displayed and the game crashes. Am I doing something wrong?

Snarky

Quote from: Bryan_abos on Wed 30/08/2017 05:31:12an error is displayed and the game crashes. Am I doing something wrong?

Yes, clearly. Telling us what the error is would help us help you.

Monsieur OUXX

Did you really create your "global boolean" using the "global variables" thingy in the Editor's GUI, or did you just create a boolean variable in the script, called vFinder? I suspect that's what you did. And there are variable scope tricks to overcome -- you must do it properly with the import/export keywords.
 

Khris

It's a runtime crash, but nothing about that code is suspicious. Maybe the "any click on hotspot" event is linked to a non-existent function? Anyway, why not tell us the error message? Why do we have to ask for that? An error message is supposed to help fix the problem, it's not something you simply click away without reading and/or using it. (wrong)

SMF spam blocked by CleanTalk