Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: DarkMoe on Sat 13/01/2018 14:48:46

Title: How to disable all hotspots in a room ?
Post by: DarkMoe on Sat 13/01/2018 14:48:46
After years and years of reading these forums, I started my first game finally.

I have a narrator, which uses sayBackground function, so I can still walk with the character. The idea though, is that while he is speaking, you can't interact with the rest of the room.

So, I tried something like hotspot.Enabled = false;  .. which of course didn't work because it's an array.

Is there a way to select all hotspots at once and change a property ? Or at least the ones in the current room ?

I also tried this pseudo Java code but didn't work:

for(int i=0;hotspot.GetProperty("length");i++) {
   hotspot.Enabled = false;
}

Thanks,
Title: Re: How to disable all hotspots in a room ?
Post by: Snarky on Sat 13/01/2018 15:16:30
The basic idea of that second approach is good, it's just the syntax that's a little different:

Code (ags) Select
// The max number of hotspots per room is 50 before AGS 3.4, 256 afterwards
#ifver 3.4
  #define MAX_HOTSPOTS 256
#endif
#ifnver 3.4
  #define MAX_HOTSPOTS 50
#endif

function someFunction()
{
  // hotspot[0] is the "no hotspot", so skip that
  for(int i=1; i < MAX_HOTSPOTS; i++)
  {
    hotspot[i].Enabled = false;
  }
}


I don't think AGS keeps track of how many of the available hotspots are actually used, but I think it's OK to access the properties of unused hotspots.
Title: Re: How to disable all hotspots in a room ?
Post by: Crimson Wizard on Sat 13/01/2018 15:34:07
Snarky, hotspots are still limited to 50. You are probably referring to the old experimental version that allowed 256 of them, but that was never actually released.

Also, the peculiarity of AGS script is that you cannot declare variable in "for", you need to do:
Code (ags) Select

int i; // first declare it
for (i = 0; ... etc


@DarkMoe, sadly, AGS script does not provide a means to extract length of array, whether static or dynamically created one. This is one of major scripting issues, but something that we have to deal with. Usually length is stored in another variable (for example Game.AudioClips is an array and Game.AudioClipCount is that array's length) or in macros, like in Snarky's example.
Title: Re: How to disable all hotspots in a room ?
Post by: DarkMoe on Sat 13/01/2018 15:36:05
Thank you very much ! Very quick replies
Title: Re: How to disable all hotspots in a room ?
Post by: Snarky on Sat 13/01/2018 16:02:14
Quote from: Crimson Wizard on Sat 13/01/2018 15:34:07
Snarky, hotspots are still limited to 50. You are probably referring to the old experimental version that allowed 256 of them, but that was never actually released.

Yeah, I did a forum search for 'hotspot limit' and trusted the first result I found. Should have looked more closely...

Quote from: Crimson Wizard on Sat 13/01/2018 15:34:07Also, the peculiarity of AGS script is that you cannot declare variable in "for", you need to do:
Code (ags) Select

int i; // first declare it
for (i = 0; ... etc

That can't be true. I use it all the time.
Title: Re: How to disable all hotspots in a room ?
Post by: Khris on Sat 13/01/2018 16:09:25
Indeed, declaring a variable inside for () is perfectly possible.

DarkMoe:
It sounds to me like a better approach would be to disable all room interactions?
// add this to GlobalScript.ash
import void Narration(String text);

// add to top of GlobalScript.asc
Overlay *narratorSpeech;

void Narration(String text) {
  narratorSpeech = cNarrator.SayBackground(text);
}

// the following at the start of on_mouse_click()
  if (narratorSpeech != null && narratorSpeech.Valid && mouse.Mode != eModeWalkto) return;


To have your narrator say something, simply use Narration("Some text");
This will disable all clicks except WalkTo ones. You might have to change things up slightly if you're using a module or template.
Title: Re: How to disable all hotspots in a room ?
Post by: Crimson Wizard on Sat 13/01/2018 16:39:24
Quote from: Khris on Sat 13/01/2018 16:09:25
Indeed, declaring a variable inside for () is perfectly possible.

That's the weirdest thing, I could swear it caused syntax errors for me, but now when I tried it worked.
Maybe that was random bug...