[SOLVED] How do I do this: Call "Hotspot.GetAtScreenXY" from a module script.

Started by mode7, Mon 28/02/2011 15:46:50

Previous topic - Next topic

mode7

Hey Guys!
I have this code I want to call from a module script:
Ultimately I want to have a bool that checks for a hotspot and returns true or false to avoid redundant and messy code in my room script
Code: ags
if (Hotspot.GetAtScreenXY(player.x-GetViewportX(), player.y-GetViewportY()) == hHotspot0)


When I compile I get an undefined symbol error. This is even what I expected cause I guess hotspots aren't global. So is there another way to check this?

Monsieur OUXX

Quote from: mode7 on Mon 28/02/2011 15:46:50
Hey Guys!
I have this code I want to call from a module script:
Ultimately I want to have a bool that checks for a hotspot and returns true or false to avoid redundant and messy code in my room script
Code: ags
if (Hotspot.GetAtScreenXY(player.x-GetViewportX(), player.y-GetViewportY()) == hHotspot0)


When I compile I get an undefined symbol error. This is even what I expected cause I guess hotspots aren't global. So is there another way to check this?

The first thing to do would be to double-check what symbol is undefined. (you didn't mention it so I assume AGS doesn't tell you -- it's always good to be sure to avoid investigatin gin the wrong place)
You can do this by splitting your code :

Code: ags

int x1= player.x;
int x2= GetViewportX();
int y1=player.y;
int y2=GetViewportY());
int myHotspot = Hotspot.GetAtScreenXY(x1-x2, y1-y2);

if (myHotspot == hHotspot0)
...


Assuming the undefined symbol is "hHotspot0"... How did you define this?
I'm not sure, but if I recall, the hotsposts are stored in the "hotspot" array.
Something like this could do it (still assuming the "hotspot" array exists)
Code: ags

if (myHotspot == hotspot[0])
 

Khris

Yes, the same is true for objects which outside room scripts can only be accessed using the object[] array.

mode7

Thanks the hotspot array did the trick.
Just out of couriosity: Where's the difference between the Hotspot* struct and the hotspot array? Because I here I had to use the array here but AGS is fine with me putting the data back into the struct. This is what I did:

Code: ags
 
 CurrentHotspot = Hotspot.GetAtScreenXY(player.x-GetViewportX(), player.y-GetViewportY());
 if (CurrentHotspot == hotspot[0]) DestroyHotspot();
 else if (CurrentHotspot != hotspot[0]) CreateHotspot (CurrentHotspot.Name);







Monsieur OUXX

Quote from: mode7 on Mon 28/02/2011 16:42:43
Where's the difference between the Hotspot* struct and the hotspot array?

I assume you mean: "WHAT is the difference"?
- Well, Hotspot* is a pointer to ONE hotspot.
- The "hotspot" array is an array of SEVERAL objects/structs of type Hotspot (or Hotspot*, I'm not sure anymore).


Quote from: mode7 on Mon 28/02/2011 16:42:43
Because I here I had to use the array here but AGS is fine with me putting the data back into the struct.

I'm not sure what you mean and I don't understand the link with the example below.



Quote from: mode7 on Mon 28/02/2011 16:42:43
This is what I did:
Code: ags
 
 CurrentHotspot = Hotspot.GetAtScreenXY(player.x-GetViewportX(), player.y-GetViewportY());
 if (CurrentHotspot == hotspot[0]) DestroyHotspot();
 else if (CurrentHotspot != hotspot[0]) CreateHotspot (CurrentHotspot.Name);


As I said I don't understand what you're trying to achieve, however I can point this out (not related) : you don't need to to the "else if" test. If the test on "==" fails, then the test on "!=" always succeeds.
So all you need is :
Code: ags
 
 CurrentHotspot = Hotspot.GetAtScreenXY(player.x-GetViewportX(), player.y-GetViewportY());
 if (CurrentHotspot == hotspot[0])
     DestroyHotspot();
 else
     CreateHotspot (CurrentHotspot.Name);

 

mode7

Quote from: Ouxxey_games on Mon 28/02/2011 16:48:55
I assume you mean: "WHAT is the difference"?
- Well, Hotspot* is a pointer to ONE hotspot.
- The "hotspot" array is an array of SEVERAL objects/structs of type Hotspot (or Hotspot*, I'm not sure anymore).

Yeah that was my question. It clears this up a bit.
Thanks for the code you're right looks much better this way.

monkey0506

As Ouxxey said, the hotspot array is an array of Hotspot*s. This array is updated any time you change to a new room so that it always holds Hotspot*s relevant to the current room. The size of the array is always AGS_MAX_HOTSPOTS, so valid indices are always 0 to (AGS_MAX_HOTSPOTS - 1).

There is also the object array which deals with Object*s. For this array though, I wouldn't recommend using the AGS_MAX_OBJECTS constant as your upper limit, since there is the Room.ObjectCount, which will most likely be typically smaller. If you're ever doing something with each object in the room this could save you some needless iterations. I believe that the array from Room.ObjectCount to (AGS_MAX_OBJECTS - 1) would just hold null pointers, so it wouldn't do you any good to deal with them anyway.

As I said, both of these are updated when you change the room, and gives you access to every hotspot and object in the current room, whereas a single Hotspot*, such as the one returned from Hotspot.GetAtScreenXY only gives you access to that individual item.

mode7

Thanks monkey - thats a good thing to know - I always thought the object array at least was global for all rooms.
Well I guess I'm finished here. Thanks everyone for the help.

SMF spam blocked by CleanTalk