Object's Script Name (NOT Description) -> or "Does It Have a Function?" [Solved]

Started by parmeisan, Fri 17/02/2012 22:30:10

Previous topic - Next topic

parmeisan

Hi,

I am trying to modify the verbcoin template for my game such that it only shows the verbs that are available (ie, have functions attached) for any given object.

I have the code that can grab the object into either a hotspot, object, or character variable.  (Let's assume hotspot for now; it's simpler).  I have some code which parses the executable for all the functions that exist (mostly).  However I have just now realized that htspt.Name does not use the script name, but the hotspot's description, which means I can only use this if I always give script names that are guessable from the description, but I'd like to not have to do that.  (Especially since I was planning on sharing this code).

I know this question was asked here, but it wasn't answered - the asker was given a different solution for his/her particular issue.

So: Can I get a hotspot's script name from the script?



If it helps to understand my question, here is the code I am currently using:

Code: ags

		String obj = "NONE";
		Hotspot*htspt=Hotspot.GetAtScreenXY(mx, my);
		Character*chr=Character.GetAtScreenXY(mx, my);
		Object*invobj=Object.GetAtScreenXY(mx, my);
		if (htspt != null) obj = htspt.Name;
		if (chr != null) obj = chr.Name;
		if (invobj != null) obj = invobj.Name;
		//Display(obj);
		if (obj == "NONE")
		{
			interact_button.Visible = false;
			look_button.Visible = false;
			custom_button1.Visible = false;
			talk_button.Visible = false;
		}
		else
		{
			interact_button.Visible = General.FunctionExists(obj, "Interact");
			look_button.Visible = General.FunctionExists(obj, "Look");
			custom_button1.Visible = General.FunctionExists(obj, "PickUp");
			talk_button.Visible = General.FunctionExists(obj, "Talk");
		}

parmeisan

Addendum: I cannot always give script names guessable from description, because that breaks something I have elsewhere where I need a oStick01, oStick02, oStick03, and oStick04 in one room.

PS. If I am missing a simple function somewhere that just lets you find out whether an object has a given function attached to it, I guess I wouldn't mind knowing that... I'll rename the thread if that comes up.

Khris

First of all, you wouldn't use the .Name; to check a property of whatever is under the mouse, the script object returned by the GetAtScreenXY function is already what you'd want. (One of the reasons, as you've seen, is that different objects might have identical names.)
So if there were a function like you describe, you'd pass htspt/chr/invobj, not something else.

However, the function you're looking for is IsInteractionAvailable().

Code: ags
  if (GetLocationType(mx, my) == eLocationNothing) {
    // turn off buttons / don't show verbcoin
  }
  else {
    interact_button.Visible = IsInteractionAvailable(mx, my, eModeInteract);
    ...
  }

parmeisan

Well, I feel silly and thank you for being so polite about this.  I really did look in the manual and google extensively for this - perhaps I should have given in and created a thread before I spent so much time trying to solve it on my own.

For some reason, GetLocationType is always returning eLocationNothing for me in this function, but that's not an issue because at this point, the Verbcoin functions have already determined that there's something of interest there.

I'm not sure what you're saying about htspt.Name - I didn't want the object, I wanted the name of it.  If it's not available, then it's not, but that is what I thought I was looking for.

Regardless of all of that, IsInteractionAvailable is working like a charm for my purposes.  Thank you very much.


EDIT: And for the sake of posterity, here is my full solution.  It's not very big, but may still be useful to somebody someday.

Khris

Quote from: parmeisan on Sat 18/02/2012 22:58:26I'm not sure what you're saying about htspt.Name - I didn't want the object, I wanted the name of it.  If it's not available, then it's not, but that is what I thought I was looking for.

Say the mouse is over an object. The script name of the object is oStick02. And its .Name property is a String with the value "stick". Realizing that this won't help you, I guess what you were looking for was something like a .ScriptName property that contains "oStick02". But, again, even if that existed, it would be absolutely useless. Because functions that do stuff to Objects don't expect Strings, they expect Objects. It's true that passing the script name as a String would allow for a single function to handle Characters, Objects and Hotspots, so I get why you were looking for it, but that's not the way AGS works.

There are some cases where one cannot avoid to handle Characters, Objects, Hotspots and Inventory Items separately.

parmeisan

Ahhhh.

But I had already written my own IsInteractionAvailable function, which I had called  General.FunctionExists and which did take a string, because it was doing it a really crazy way.  (ie, comparing to a list of all the valid functions, which I had gotten by parsing the executable).

So that's why we weren't on the same page with that.

Khris

:o

I should have read your initial post more careful. Alright. Parsing the executable. Well, at least it's pretty ingenious :)

SMF spam blocked by CleanTalk