Author Topic: How to disable all hotspots in a room ?  (Read 306 times)

How to disable all hotspots in a room ?
« on: 13 Jan 2018, 14:48 »
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,

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: How to disable all hotspots in a room ?
« Reply #1 on: 13 Jan 2018, 15:16 »
The basic idea of that second approach is good, it's just the syntax that's a little different:

Code: Adventure Game Studio
  1. // The max number of hotspots per room is 50 before AGS 3.4, 256 afterwards
  2. #ifver 3.4
  3.   #define MAX_HOTSPOTS 256
  4. #endif
  5. #ifnver 3.4
  6.   #define MAX_HOTSPOTS 50
  7. #endif
  8.  
  9. function someFunction()
  10. {
  11.   // hotspot[0] is the "no hotspot", so skip that
  12.   for(int i=1; i < MAX_HOTSPOTS; i++)
  13.   {
  14.     hotspot[i].Enabled = false;
  15.   }
  16. }

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.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: How to disable all hotspots in a room ?
« Reply #2 on: 13 Jan 2018, 15:34 »
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: Adventure Game Studio
  1. int i; // first declare it
  2. for (i = 0; ... etc
  3.  

@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.

Re: How to disable all hotspots in a room ?
« Reply #3 on: 13 Jan 2018, 15:36 »
Thank you very much ! Very quick replies

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: How to disable all hotspots in a room ?
« Reply #4 on: 13 Jan 2018, 16:02 »
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...

Also, the peculiarity of AGS script is that you cannot declare variable in "for", you need to do:
Code: Adventure Game Studio
  1. int i; // first declare it
  2. for (i = 0; ... etc
  3.  

That can't be true. I use it all the time.

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: How to disable all hotspots in a room ?
« Reply #5 on: 13 Jan 2018, 16:09 »
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?
Code: Adventure Game Studio
  1. // add this to GlobalScript.ash
  2. import void Narration(String text);
  3.  
  4. // add to top of GlobalScript.asc
  5. Overlay *narratorSpeech;
  6.  
  7. void Narration(String text) {
  8.   narratorSpeech = cNarrator.SayBackground(text);
  9. }
  10.  
  11. // the following at the start of on_mouse_click()
  12.   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.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: How to disable all hotspots in a room ?
« Reply #6 on: 13 Jan 2018, 16:39 »
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...