Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: johanvepa on Wed 21/09/2016 22:44:24

Title: Region is not an array?? Question about GetRoomAtXY - SOLVED
Post by: johanvepa on Wed 21/09/2016 22:44:24

I am doing a function that checks if the mouse hovers over a region. If it does, and the cursor is not PickUp, then it should change to PickUp.

I am doing this:
Code (ags) Select




function room_RepExec()
{
  if (Region.GetAtRoomXY(mouse.x, mouse.y) == Region[1])
  {
    if (mouse.Mode != eModePickup)
    {
      mouse.Mode = eModePickup;
    }
  }


since the manual told me this is a correct example:
if (Region.GetAtRoomXY(player.x, player.y) == region[0])
  Display("The player is not currently standing on a region.");

But AGS tells me that Region is not an array. What is wrong here?
Title: Re: Region is not an array?? Question about GetRoomAtXY
Post by: Crimson Wizard on Wed 21/09/2016 22:49:17
Small-case region is an array. Capital-case Region is a type.

AGS script is case sensitive. You need to make sure you are using correct letter case in your script.
Title: Re: Region is not an array?? Question about GetRoomAtXY
Post by: johanvepa on Wed 21/09/2016 23:19:55
Checked case settings. Thanks (laugh)
Title: Re: Region is not an array?? Question about GetRoomAtXY - SOLVED
Post by: Khris on Thu 22/09/2016 12:04:39
Also note that this code will break as soon as you add a scrolling room.

Use this:
  if (Region.GetAtRoomXY(mouse.x + GetViewportX(), mouse.y + GetViewportY()) == Region[1])
Title: Re: Region is not an array?? Question about GetRoomAtXY - SOLVED
Post by: dayowlron on Thu 22/09/2016 15:14:18
It is not a big deal either but it is not necessary to check to see if mouse mode is not eModePickUp before setting it to be that.

What I mean is:
    if (mouse.Mode != eModePickup)
    {
      mouse.Mode = eModePickup;
    }

could have been just written as:
    mouse.Mode = eModePickup;

since if it is already set then setting it again is not going to change things.

If you have animated cursor that would be the only reason to check first.
Title: Re: Region is not an array?? Question about GetRoomAtXY - SOLVED
Post by: johanvepa on Thu 22/09/2016 19:50:08
I might want to use animated cursors, that is why I check mouse.Mode
Title: Re: Region is not an array?? Question about GetRoomAtXY - SOLVED
Post by: johanvepa on Thu 22/09/2016 19:51:54
Quote from: Khris on Thu 22/09/2016 12:04:39
Also note that this code will break as soon as you add a scrolling room.

Use this:
  if (Region.GetAtRoomXY(mouse.x + GetViewportX(), mouse.y + GetViewportY()) == Region[1])

That was exactly the issue in this thread (http://www.adventuregamestudio.co.uk/forums/index.php?topic=53947.0).