Jibble

Author Topic: Changing descriptions of hotspots and objects at runtime  (Read 980 times)

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: Adventure Game Studio
  1. 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?



Re: Changing descriptions of hotspots and objects at runtime
« Reply #1 on: 26 Oct 2019, 14:58 »
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.

eri0o

Re: Changing descriptions of hotspots and objects at runtime
« Reply #2 on: 26 Oct 2019, 15:04 »
Code: Adventure Game Studio
  1. String GetObjOvertext(int x, int y){
  2.   Object * obj = Object.GetAtScreenXY(x, y);
  3.   if(obj==null){
  4.     return "";  
  5.   }
  6.  
  7.   if(String.IsNullOrEmpty(obj.GetTextProperty("aName"))){
  8.     return "";
  9.   } else {
  10.     return obj.GetTextProperty("aName");
  11.   }
  12.   return "";
  13. }

I use something like above for objects, my custom property is aName.

Re: Changing descriptions of hotspots and objects at runtime
« Reply #3 on: 26 Oct 2019, 15:16 »
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.


eri0o

Re: Changing descriptions of hotspots and objects at runtime
« Reply #4 on: 26 Oct 2019, 15:20 »
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)
« Last Edit: 26 Oct 2019, 15:21 by eri0o »

Re: Changing descriptions of hotspots and objects at runtime
« Reply #5 on: 26 Oct 2019, 15:33 »
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"!)

Re: Changing descriptions of hotspots and objects at runtime
« Reply #6 on: 26 Oct 2019, 15:49 »
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.

Matti

Re: Changing descriptions of hotspots and objects at runtime
« Reply #7 on: 26 Oct 2019, 16:17 »
I'm using a workaround too. Using your example it would be:

Code: Adventure Game Studio
  1. lblDescription.Text = Game.GetLocationName(mouse.x, mouse.y);
  2.  
  3. if (lblDescription.Text == oBust.Name && oBust.Graphic == 101) lblDescription.Text = "Greek Bust";
  4. // ..the "normal" description of oBust being "Mysterious Object"

It would indeed be a very convenient feature to change the descriptions at runtime.
« Last Edit: 26 Oct 2019, 16:20 by Matti »

Re: Changing descriptions of hotspots and objects at runtime
« Reply #8 on: 26 Oct 2019, 17:33 »
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 :)

Re: Changing descriptions of hotspots and objects at runtime
« Reply #9 on: 26 Oct 2019, 18:15 »
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 :)

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

Re: Changing descriptions of hotspots and objects at runtime
« Reply #10 on: 26 Oct 2019, 20:38 »
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 :)

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!