hover text

Started by Sparky, Sat 18/11/2006 07:35:14

Previous topic - Next topic

Sparky

Thank you all for your help with my previous questions. I apologize again for any lack of knowledge on my part. I'm still new to AGS and greatly appreciate the patience of more seasoned users with well-meaning but naive beginners like myself.

I am working on a project with a Myst-stlye "one click does all" interface. There's a context sensitive text hint that tells the player what clicking on an object will do. For instance, the hint will say "open door" when the cursor is over a closed door, or "pick up stone" when the cursor passes over a stone.

I'm using a custom property to store this hint text. This works, but I've read that I can't change the value of this custom property at runtime. There are certain times I'd like to be able to do this; one example of this is a door whose hint changes from "open door" to "close door". Is there a workaround?

Candle


Sparky

Thanks for your module recommendation- I've downloaded it and am having fun trying to figure out how it all works. I'm also looking at the MI2 template by Proskrito.

For learning's sake, I'd like to do the necessary scripting myself instead of piggybacking someone else's work. I've got more or less everything working now, minus the few objects that need to switch their verbs (such as doors, which need to switch from "open" to "closed") I think I'll try having two objects in those cases- one with a default "open" verb, and one with a "close" verb. Clicking on either object will toggle the visibility of the two objects.

This feels like a dirty hack, but I haven't yet thought of a cleaner way to switch the verb in the text hint. Thanks again for your advice- any further comments or suggestions are also welcome.

monkey0506

#3
This sounds like a job for the Properties module!

You've probably read about custom properties in the manual, and know that they're read-only at run-time. Well, the Properties module can create custom properties that are fully editable at run-time.

If you have your interaction types set up in an enumeration (i.e., if you're using the mouse modes), you could set up a property like this:

Code: ags
// taken from the MonkeyTemplate module
// script header
import SetDefaultInteraction(LocationType loctype, int data, CursorMode Mode, int room=-1);
import GetDefaultInteraction(LocationType loctype, int data, int room=-1);

// game_start
Properties.CreateNumberProperty("DefaultInteraction", eModeWalkto);

// global script
void SetDefaultInteraction(LocationType loctype, int data, CursorMode Mode, int room) {
  // LOCTYPE is used to determine what you are setting the interaction for
  //   eLocationNothing is used for InventoryItems
  //   eLocationHotspot is used for Hotspots
  //   eLocationCharacter is used for Characters
  //   eLocationObject is used for Objects
  // DATA is the ID property of what you are setting the interaction for
  // MODE is the mode you want to be the default interaction mode
  // ROOM is ONLY used for Hotspots and Objects and is used to set the room which contains the Hotspot/Object
  //   if you don't pass the ROOM parameter (it is optional) the current room will be used
  if (data < 0) return;
  if (room < 0) room = player.Room;
  Properties.SetPropertyAsNumber(loctype, data, "DefaultInteraction", Mode, room);
  }

CursorMode GetDefaultInteraction(LocationType loctype, int data, int room) {
  // see SetDefaultInteraction above for parameter descriptions
  if (data < 0) return eModeWalkto;
  if (room < 0) room = player.Room;
  return Properties.GetPropertyAsNumber(loctype, data, "DefaultInteraction", room);
  }


Some examples of this code:

Code: ags
SetDefaultInteraction(eLocationCharacter, cDude.ID, eModePush); // change Character DUDE's default interaction to Push
SetDefaultInteraction(eLocationNothing, iKey.ID, eModeLookat); // change InventoryItem KEY's default interaction to Look at
if (GetDefaultInteraction(eLocationObject, 10, 7) == eModePickup) {
  // check if Object 10 in room 7's default interaction is Pick up
  }


You could also set up another function like this to get the appropriate verb (for the default interaction):

Code: ags
// script header
import String GetDefaultInteractionVerb(LocationType loctype, int data, int room=-1);

// global script
String GetDefaultInteractionVerb(LocationType loctype, int data, int room) {
  // see SetDefaultInteraction abover for parameter descriptions
  CursorMode defMode = GetDefaultInteraction(loctype, data, room);
  if (defMode == eModeWalkto) return "Walk to";
  else if (defMode == eModeLookat) return "Look at";
  else if (defMode == eModeTalkto) return "Talk to";
  // etc.
  }

Sparky

That's another good suggestion. I was somewhat stumped when I read in the manual that properties are read-only. The Properties module addresses this directly, and is a good fit here.

At this point I've got everything working, and have some neat new ideas to play with as well. Thank you both for your help.

SMF spam blocked by CleanTalk