Hi,
Before my room fades in I have the following code
Ã, // script for room: Player enters screen (before fadein)
int which;
which=0;
SetBackgroundFrame(0);Ã,Â
if (GetGlobalInt(6)==1) {
Ã, EnableRegion(1);
Ã, SetBackgroundFrame(1);
Ã, while (which<8) {
Ã, Ã, EnableHotspot(which);
Ã, Ã, which++;
Ã, }
}
else {
Ã, DisableRegion(1);
Ã, while (which<8) {
Ã, Ã, DisableHotspot(which);
Ã, Ã, which++;
Ã, }Ã,Â
}
}
So: The plan is that if something has happened (Which would change GlobalInt 6 to 1), the background frame is something, and loads of hotspots are enabled. If not, then they are disabled and the background set to something else. And the programmer in me spots the chance to use a loop to save writing out 8 lines of code for each case. Simple.
But when the room is loaded, the game comes to an abrupt standstill before it fades in and I have the following message:
QuoteAn error has occured. Please contact the game author for support, as this
is likely to be a scripting error and not a bug in AGS.
(ACI version 2.62.772)
(Room 7 script line 42)
Error: DisableHotspot: invalid hotspot specified
I'm guessing this is because I can't use the variable "which" in enabling / disabling the hotspots meaning I would need 8 lines for my hotspots in each outcome. Is this the case?
No, you should be able to use that to disable hotspots.
I think the problem is Hotspot 0, which is usually the 'empty' parts of the screen. Since 'which' starts at 0, it tries to deactivate a non-existent (or invalid, hence the error) hotspot.
Try setting 'which' to 1 to start with (you may have to change it to if (which<= 8) as well), or increasing 'which (which ++;) before calling Enable/DisableHotspot(which);.
Also, ints can be set when you declare them, so:
int which = 1;
would do the same as:
int which;
which = 1;
(ints are 0 by default, so you don't need to include the '= 0')
That's brilliant! ;D I've tried it and it works. Thankyou!