Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Laura Hunt on Sat 26/10/2019 14:31:48

Title: Changing descriptions of hotspots and objects at runtime
Post by: Laura Hunt on Sat 26/10/2019 14:31:48
Hey everybody, here I am going crazy again over something that maybe is simpler than I think but I can't for the life of me make it work.

OK, so in the "Properties" panel, objects and hotspots have Names (oObject1, hHotspot1) and Descriptions ("Porcelain vase", "Blood stain").

I have a GUI at the bottom of the screen that displays in a label the description of any hotspot or object when you move your mouse over it:

(in my global script's repeatedly_execute)
Code (ags) Select
lblDescription.Text = Game.GetLocationName(mouse.x, mouse.y);

This works perfectly, no issues whatsoever (although it's confusing that the function is called GetLocationName when the value it's taking is not the Name but the Description.)

Now my problem is that I want to change this descriptive text for some objects at certain points in the game.

Imagine a greek bust that is covered with a sheet at first but later on in the game, the sheet is removed. Instead of using two different objects, I would simply like to change the graphic and the description text of the object, so that when it's covered (oBust.Graphic = 100), moving the mouse over it would display something like "Mysterious object", and when it's uncovered (oBust.Graphic = 101), moving the mouse over it would display e.g., "Greek bust".

Is this possible at all? I know the manual says that it's not possible to change the name of a hotspot or object at runtime, but like I said, I don't want to change the Name, I want to change the Description. Or is it basically the same situation? Do I have to use a custom property instead of the built-in "Description" property?


Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: Crimson Wizard on Sat 26/10/2019 14:58:16
AGS does not support that atm for some reason (this was in feature requests for years), so you could use custom properties instead. But in that case you can no longer rely on Game.GetLocationName, and would have to write your own function that finds an object under coordinates and reads from data custom properties.
Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: eri0o on Sat 26/10/2019 15:04:02
Code (ags) Select
String GetObjOvertext(int x, int y){
  Object * obj = Object.GetAtScreenXY(x, y);
  if(obj==null){
    return ""; 
  }
 
  if(String.IsNullOrEmpty(obj.GetTextProperty("aName"))){
    return "";
  } else {
    return obj.GetTextProperty("aName");
  }
  return "";
}


I use something like above for objects, my custom property is aName.
Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: Laura Hunt on Sat 26/10/2019 15:16:51
Crimson Wizard yeah that's what I thought :~(

Thanks for the code, eri0o! Unfortunately, changing my mouse-over function would mean going over ALL of Act 1 and adding a custom property/description to every. single. object. I'd rather just use a brand new object when I need to update a description, and roll with that.

Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: eri0o on Sat 26/10/2019 15:20:06
Sorry, I noticed my code actually is used for other things but you could do it with a change so that when aName is empty it returns the "Name" (description) itself instead.

(One other thing for me to modularize, my game initial systems were built very monolithically and I am now modularizing each piece to be easier to change and I haven't yet passed on my long complicated overtext system)
Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: Laura Hunt on Sat 26/10/2019 15:33:34
Quote from: eri0o on Sat 26/10/2019 15:20:06
Sorry, I noticed my code actually is used for other things but you could do it with a change so that when aName is empty it returns the "Name" (description) itself instead.

Hmmmm alright, might give it a try then! (emphasis on "might"!)
Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: Crimson Wizard on Sat 26/10/2019 15:49:03
I've seen an alternate solution when people were using a simple array of strings in script to speed things up instead of custom properties.
Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: Matti on Sat 26/10/2019 16:17:12
I'm using a workaround too. Using your example it would be:

Code (ags) Select
lblDescription.Text = Game.GetLocationName(mouse.x, mouse.y);

if (lblDescription.Text == oBust.Name && oBust.Graphic == 101) lblDescription.Text = "Greek Bust";
// ..the "normal" description of oBust being "Mysterious Object"


It would indeed be a very convenient feature to change the descriptions at runtime.
Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: Laura Hunt on Sat 26/10/2019 17:33:21
Matti, that looks like a really convenient solution, thanks! It does look like the "default" description would appear for a brief fraction of a second before being updated to the new one, but it looks simple enough to give it a try and see if it works for me :)
Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: Crimson Wizard on Sat 26/10/2019 18:15:52
Quote from: Laura Hunt on Sat 26/10/2019 17:33:21It does look like the "default" description would appear for a brief fraction of a second before being updated to the new one, but it looks simple enough to give it a try and see if it works for me :)

It won't appear even for a fraction, because game does not redraw itself until function ends or you call Wait().
Title: Re: Changing descriptions of hotspots and objects at runtime
Post by: Laura Hunt on Sat 26/10/2019 20:38:14
Quote from: Crimson Wizard on Sat 26/10/2019 18:15:52
Quote from: Laura Hunt on Sat 26/10/2019 17:33:21It does look like the "default" description would appear for a brief fraction of a second before being updated to the new one, but it looks simple enough to give it a try and see if it works for me :)

It won't appear even for a fraction, because game does not redraw itself until function ends or you call Wait().

Thanks, good to keep in mind!