Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MaHusemoen on Thu 09/07/2020 13:59:36

Title: Problem with making objects in room non-interactable
Post by: MaHusemoen on Thu 09/07/2020 13:59:36
I have made a custom dialogue tree, and I have problems with it. The type of dialogue tree is a icon based one, and I am having problems with making objects not clickable when this tree appears.

The tree appears when you interact with characters, and replaces the inventory.
This is the code I used.
Code (ags) Select

cDerek.FaceCharacter(cAgraj, eBlock);
cDerek.Say("Um, sir?");
cAgraj.Say("What is it?");
cAgraj.Clickable = false;
RemoveWalkableArea(1);
gInventory.Visible = false;
gDialogueTreeAgraj.Visible = true;
Title: Re: Problem with making objects in room non-interactable
Post by: Crimson Wizard on Thu 09/07/2020 14:32:45
Please elaborate, which objects you are trying to disable, and what does not work or does not work like you expected?
Title: Re: Problem with making objects in room non-interactable
Post by: MaHusemoen on Thu 09/07/2020 14:55:59
Quote from: Crimson Wizard on Thu 09/07/2020 14:32:45
Please elaborate, which objects you are trying to disable, and what does not work or does not work like you expected?

I'm currently just testing in one room,  but I'm trying to make one object, the painting, not clickable while talking. I have tried to find a way to make the objects in the room not clickable, but I haven't found a way to code object in the global script.
I already tried a code but it didn't work
Code (ags) Select

object.clickable = false
Title: Re: Problem with making objects in room non-interactable
Post by: Khris on Thu 09/07/2020 15:02:14
You can try setting the GUI's PopUpStyle to "pause game when shown", but that might have unintended consequences.
You can also make gDialogueTreeAgraj cover the entire screen and make part of the GUI's background image transparent, that should also catch room clicks.
A third way is to use eModePointer as mouse.Mode when the dialog GUI is open and modify on_mouse_click etc. so they ignore eModePointer clicks.
Title: Re: Problem with making objects in room non-interactable
Post by: Laura Hunt on Thu 09/07/2020 15:11:44
If you only want to make one or two specific objects in one specific room not clickable, you can use their IDs:

Code (ags) Select
object[x].Clickable = false;  // where x is the object's ID, found in the room's Properties panel

If you want to turn all objects in the room unclickable, you can always do

Code (ags) Select
for (int i = 0; i < 30; i++) {  // rooms can have a maximum of 30 objects I think? Or was it 40?
   object[i].Clickable = false;
}


(and then you would do the opposite to make them clickable again)

Or you can make gDialogueTreeAgraj cover the whole screen, like Khris says, or you can create a black GUI at 99% transparency that covers the whole screen, and place it right behind gDialogueTreeAgraj so it catches any clicks in the room.

Title: Re: Problem with making objects in room non-interactable
Post by: Crimson Wizard on Thu 09/07/2020 15:13:36
Quote from: Laura Hunt on Thu 09/07/2020 15:11:44
Code (ags) Select
for (int i = 0; i < 30; i++) {  // rooms can have a maximum of 30 objects I think? Or was it 40?
   object[i].Clickable = false;
}


You must not do this IIRC, because object[ i ] can return null or cause "index out of array bounds" error if it does not exist. The proper way is to compare to Room.ObjectCount:
Code (ags) Select

for (int i = 0; i < Room.ObjectCount; i++) {
   object[i].Clickable = false;
}



Title: Re: Problem with making objects in room non-interactable
Post by: Laura Hunt on Thu 09/07/2020 15:15:02
Quote from: Crimson Wizard on Thu 09/07/2020 15:13:36
Quote from: Laura Hunt on Thu 09/07/2020 15:11:44
Code (ags) Select
for (int i = 0; i < 30; i++) {  // rooms can have a maximum of 30 objects I think? Or was it 40?
   object[i].Clickable = false;
}


You must not do this IIRC, because object[ i ] can return null or cause "index out of array bounds" error if it does not exist. The proper way is to compare to Room.ObjectCount:
Code (ags) Select

for (int i = 0; i < Room.ObjectCount; i++) {
   object[i].Clickable = false;
}


I totally forgot Room.ObjectCount existed. Thanks for the correction!