Using a variable (Not an integer) in [Enable/Disable]Hotspot (SOLVED)

Started by Colxfile, Tue 05/04/2005 22:29:29

Previous topic - Next topic

Colxfile

Hi,

Before my room fades in I have the following code

Code: ags

Ã,  // 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?
Always carry a UV marker pen with you. When you go to a shop or a friend's house, if you see something you like, put your name and postcode on it. If it gets stolen and subsequently recovered, the police will get in touch with you so that they can 'return' it.

Ashen

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:
Code: ags

int which = 1;

would do the same as:
Code: ags

int which;
which = 1;

(ints are 0 by default, so you don't need to include the '= 0')
I know what you're thinking ... Don't think that.

Colxfile

That's brilliant!  ;D I've tried it and it works. Thankyou!
Always carry a UV marker pen with you. When you go to a shop or a friend's house, if you see something you like, put your name and postcode on it. If it gets stolen and subsequently recovered, the police will get in touch with you so that they can 'return' it.

SMF spam blocked by CleanTalk