Change hotspot or object description in script (or workaround)

Started by skicamel, Tue 07/12/2010 00:17:32

Previous topic - Next topic

skicamel

I've got the standard floating @OVERHOTSPOT@ gui for mousing over objects/hotspots, etc.  I keep running into places I would prefer the text to change after observation or interaction.  Ex.  "Wobbly Mound" becomes "Sharpei" after closer observation.  I ran into one Feature Request post for hotspot.SetDescription which would be ideal (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=41245.0).  The workaround on that post was pretty messy and requires setting a separate label, bypassing @OVERHOTPSOT@.  I looked at setting an  "afterdesc" custom property, but those are also not writable by script.

I know others have had to work around this.  Looking for possible approaches.  Thoughts, ideas?

Khris

Here's something I wrote recently:

Code: ags
String OtherName(String desc) {
  int ro = player.Room;
  int mx = mouse.x;
  int my = mouse.y;
  
  int c = -1, h = -1, o = -1;
  
  int lt = GetLocationType(mx, my);
  if (lt == eLocationCharacter) {
    Character*cp = Character.GetAtScreenXY(mx, my);
    if (cp != null) c = cp.ID;
  }
  if (lt == eLocationHotspot) {
    Hotspot*hp = Hotspot.GetAtScreenXY(mx, my);
    if (hp.ID > 0) h = hp.ID;
  }
  if (lt == eLocationObject) {
    Object*op = Object.GetAtScreenXY(mx, my);
    if (op != null) o = op.ID;
  }
  
  // room 2
  if (ro == 2) {
    // hotspot 1
    if (h == 1 && mound_looked_at) desc = "Sharpei";
  }
  
  return desc;
}


You'd use it like this:
  // inside repeatedly_execute
  lblHotspotDesc = OtherName(Game.GetLocationName(mouse.x, mouse.y));

You could also store the description in a global variable and put the handling into the room scripts to avoid having all the game's alternative names bundled together in one place.

skicamel

Thanks, Khris.  I meant to post back sooner.  Definitely works well.  A lot of work, though, in what's turning into a hefty game.  I'd whine about the lack of a setDescription function, but I still remember my early attempts at writing simple games without a tool like AGS that already does most of the heavy lifting.  Counting my blessings.

subspark

Still, I and many others believe this feature is a logical fit for the standard AGS scripting language and should be included in a future release.

Cheers,
Sparky.

Calin Leafshade

This could be done quite easily in a module.

- On game_start create an array of strings with size Room_count * 30 (max number of hotspots)

- On room_first_load dump all the hotspot names to the array

- Make 2 extender functions for hotspots. One which gets the hotspots description and one that sets it.

subspark

Oh yeah, of course. I've managed to do it a number of ways, but I still think it belongs in the standard scripting language that comes pretty much as it is.

EDIT: Btw, what the hell happened to your name, Calin?  :=

Wyz

Life is like an adventure without the pixel hunts.

SMF spam blocked by CleanTalk