How do I retrieve a custom property value?

Started by HandsFree, Wed 24/08/2011 22:05:13

Previous topic - Next topic

HandsFree

I'm trying to find the boolean custom property value of a hotspot/object in the on_mouse_click function in the global script.
Something like:
if GetProperty("UsesText") == true do something first;
else do something else;
ProcessClick(mouse.x, mouse.y, mouse.Mode );


The manual gives this example:

if (hotspot[1].GetProperty("Value") > 200)
  Display("Hotspot 1's value is over 200!");


But how do I find the [1] then?

thanks

skuttleman

I think you need something like this (untested)

Code: ags

  Hotspot* mouseoverhotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  Object* mouseoverobject = Object.GetAtScreenXY(mouse.x, mouse.y);
  if (mouseoverhotspot != null)
  {
    if (mouseoverhotspot.GetProperty("UsesText") == 1)
    {
      // do something first
    }
    else
    {
      // do something else
    }
    ProcessClick(mouse.x, mouse.y, Mouse.Mode);
  }
  else if (mouseoverobject != null)
  {
    if (mouseoverobject.GetProperty("UsesText") == 1)
    {
      // do something first
    }
    else
    {
      // do something else
    }
    ProcessClick(mouse.x, mouse.y, Mouse.Mode);
  }


I hope that helps.

Khris

Small correction: the area outside hotspots is hotspot[0] so it should be:

Code: ags
  if (mouseoverhotspot != hotspot[0]) ...


It might be better to check for objects first because if the mouse is over an object that's itself over a hotspot, Hotspot.GetAtScreenXY() should still return the hotspot and thus the player clicks through the object.

I'd do:

Code: ags
  int mx = mouse.x, my = mouse.y;
  int lt = GetLocationType(mx, my);

  if (lt == eLocationHotspot) {
    Hotspot*h = Hotspot.GetAtScreenXY(mx, my);
    if (h.GetProperty("UsesText")) ...


SMF spam blocked by CleanTalk