Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: spook1 on Mon 16/02/2004 21:30:36

Title: Variable hotspot numbering?
Post by: spook1 on Mon 16/02/2004 21:30:36
In my game I call a function to place objects at certain hotspots.
For each hotspot I have to put in the code.
is there a way to program the sequence in a more legant way, using an if-then loop e.g.

Something like:

if (i =< 10) {


function hotspoti_a() {
//   script for hotspot1: Use inventory on hotspot
 if (character[EGO].activeinv == 1) {

   LoseInventory(character[EGO].activeinv);
   SetCursorMode(2);
   RawDrawImage (87, 89, 3);  //draws picture from slot 3 at coordinates 72,172
   R1 = 100;         // weerstand van 100 Ohm geplaatst;
   
 }

 if (character[EGO].activeinv ==2 ) {
   LoseInventory(character[EGO].activeinv);    
   SetCursorMode(2);      
   RawDrawImage (93, 90, 5);
   R1 = 0;         // Draad geplaatst geplaatst;
 }
DisableHotspot(i);
}

}

This would help me a lot in writing compact code, instead of repeating thsi code for each hotspot.

Kind regards,
Martijn
Title: Re:Variable hotspot numbering?
Post by: a-v-o on Mon 16/02/2004 22:40:01
I'm not completely sure what you mean.
1.) Do you want to execute that code for all hotspots at the same time?
2.) Or do you want to execute the same code when the inv item is used on the different hotspots?

In both cases the first part is the same:
Copy your function into the script above the hotspot functions and give it a different name:

function use_inv_on_hotspot (int hotspot_number)
{
if (character[EGO].activeinv == 1)
{
LoseInventory(character[EGO].activeinv);
SetCursorMode(2);
RawDrawImage (87, 89, 3); //draws picture from slot 3 at coordinates 72,172
R1 = 100;         // weerstand van 100 Ohm geplaatst;
}
if (character[EGO].activeinv ==2 ) {
LoseInventory(character[EGO].activeinv);
SetCursorMode(2);
RawDrawImage (93, 90, 5);
R1 = 0;         // Draad geplaatst geplaatst;
}
DisableHotspot(hotspot_number);
}


Then you call this function in one of the following 2 ways, depending on the effect that you want to realize:

1.) Loop
function ??? ()
{
int i = 1;
while (i <= 10)
{
use_inv_on_hotspot (i);
i++;
}
}

2.) Call this function from the hotspot function:

function hotspoti_a()
{
// script for hotspot1: Use inventory on hotspot
use_inv_on_hotspot (1);
}

function hotspoti_b()
{
// script for hotspot2: Use inventory on hotspot
use_inv_on_hotspot (2);
}
...
Title: Re:Variable hotspot numbering?
Post by: spook1 on Tue 17/02/2004 12:30:09
Thanks for answering.
My question was: Can I use one function on many hotspots by treating the hotspots as variables?
Function_hotspot_a,where a is a variable.
Your suggestion to copy the function onto all hotspotsindicates that i cannot use a loop to pass all hotspotsand see if thereis anything to do.
Kind regards,

Martijn