string.RunInteraction

Started by Martyn, Thu 05/11/2015 20:49:20

Previous topic - Next topic

Martyn

Hey!

Is it possible to change "hotspot[0]" in to a string name?

Code: ags
hotspot[0].RunInteraction(eModeLookat);

to
Code: ags
stringname.RunInteraction(eModeLookat);


can't get it to work!

Snarky

#1
You mean call hotspot functions on a named Hotspot variable rather than an index? Sure! Try this:

Code: ags

  Hotspot* myHotspot;

  // We need to assign some value to myHotspot. For example:
  myHotspot = hotspot[0];                             // Set it to hotspot[0]
  myHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y) // ... or the hotspot under the mouse cursor

  myHotspot.RunInteraction(eModeLookat);


If you mean to use a string value (the hotspot's name, I assume), you can't do that so easily (though it is possible with a bit of work). Probably you're trying to do something the wrong way, so maybe explain what you're trying to achieve?

Edit: By the way, don't try to run any methods on the hotspot outside of the room it's in (e.g. by using myHotspot after you've left the room where you set it).

Martyn

crap, I know it was a hook! :tongue:

I want to pass the hotspot name or number, from the rom over to globalscript and back again to the rom!?
Right now i pick up the name like this in a string!

Is the solution to use import and export?

Code: ags
location = Game.GetLocationName(mouse.x, mouse.y);




MiteWiseacreLives!

From my limited experience you can run Snarky's code from the Global Script and it will grab the relevant room hotspot just fine.
In these situations I just get the hotspot/object number then use hotspot[int].RunInteraction(eModeLookat);
I would avoid the whole string thing altogether.  :)

Martyn

yes it works, but i must be right over the hotspot!
When i click the hotspot i have a gui that's popup and there's
mHotspot.RunInteraction(eModeLookat);
when i click here am i not over that hotspot! :confused:

Vincent

You are actually use
Code: ags

location = Game.GetLocationName(mouse.x, mouse.y); 

to get the name of whatever the mouse is over into the string variable.
If the co-ordinates are on a GUI, a blank string is returned.

I'm not sure if it will make a difference,
Try to create another gui with a label, then you rename the label text in the editor with @OVERHOTSPOT@
This special mark get the name of the hotspot which the cursor is over.

Martyn

Everything works, except that I can not pass my string from the room in to the Global Script.???
In the string i have the hotspot that's the mouse was over when i clict the hotspots in the room!
can i do that in a different way maybe?

Vincent

I think that the method you are using is just fine.
If you need to pass your String from a room in to the Global script you can easily create a Global String from the editor panel (Global variables) and add a new variable String that you can access everywhere :)

Snarky

Quote from: Martyn on Thu 05/11/2015 22:35:04
I want to pass the hotspot name or number, from the rom over to globalscript and back again to the rom!?
Right now i pick up the name like this in a string!

I'm still not clear on exactly what you're trying to achieve.

To identify a hotspot, you can use a pointer (Hotspot*) or an integer (hotspot[index], this number is identical to the Hotspot.ID property). If you want to pass a hotspot from one function to another, you should use one of these, not any kind of string.

Refer to the manual:
http://www.adventuregamestudio.co.uk/site/ags/tutorial/ags/3/
http://www.adventuregamestudio.co.uk/manual/ags65.htm#topic57

In your room code, if you want to refer to a specific hotspot, look up the Name or ID value of the hotspot (in the room view, under the hotspot properties). For example, if you've created a hotspot called hCloud with ID 3, and you want to call a globalscript function with this hotspot, you can do:

Code: ags
// Global script
void globalscriptFunction(Hotspot* hotspot)
{
  String hotspotName = hotspot.Name; // Same as @OVERHOTSPOT@ â€" if I remember correctly this is the "hotspot description" under the hotspot properties
  String propertyValue = hotspot.GetProperty("propertyName"); // Assuming you've defined a custom property with this name 
  // TODO: Do something with one of these strings ...
}

// PS: Don't forget to import this function in the header!


And then in the room script:

Code: ags
// Room script
  globalscriptFunction(hCloud);


or alternatively:

Code: ags
// Room script
  globalscriptFunction(hotspot[3]);

Khris

Martyn, please describe in a general, non-tech way the game mechanic you want to implement.
It's probably something quite simple, for which there exists a simple, well-known solution.

Martyn

Okay, nice! Thanks Vincent, thats was helping a bit :smiley:!

I realast now that i also misunderstand the Location Name thing!
I thought that it was like this "hotspot[0]"

Code: ags
myHotspot = Game.GetLocationName(mouse.x, mouse.y);

This works almost the way i want.
Code: ags
myHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);

This get error, can not convert hotspot* to int or string! ???

MiteWiseacreLives!

is myHotspot a String, Int or a Pointer  ??? ??? ???
Please explain what you are trying to accomplish, then someone could help you quite easily I'm sure.

Martyn

First problem was Global variables. :smiley:
And the second is Game.GetLocationName/Hotspot.GetAtScreenXY.
Have tried both String and Int. But the "Game.GetLocationName" works fine.
But i cant figure out why i cant get something out of Hotspot.GetAtScreenXY??

Thanks anyway! :smiley:





Snarky

#13
Oh FFS! For the nth time: Explain what you're trying to do, the goal your code is meant to accomplish, not just the steps you've tried! If we knew what your end-goal is, it would almost certainly be very simple to implement, but you keep just mentioning individual methods, leaving us to guess what you're actually doing and trying to do with them.

Actually, I think I have a pretty good idea what the problem is, but as long as you're not cooperating I don't see why I should keep trying to help.

Also: The manual. If you're having a problem with Hotspot.GetAtScreenXY(), go look it up.

Martyn

Wow, take it easy! :shocked:

Vince post fixt it, however I missed it at first, sorry!

QuoteI think that the method you are using is just fine.
If you need to pass your String from a room in to the Global script you can easily create a Global String from the editor panel (Global variables) and add a new variable String that you can access everywhere :)





Snarky

OK, well that's the last time I'll try to help you.

Vincent

#16
However as Snarky prompt before I would check the (Custom Properties) because are very handly :)
You can create a custom property for "Default event", for example, and then have some simple code in the global script to use the setting accordingly.
You'll notice that characters, objects, hotspots, rooms and inventory items all have a "Properties" option in their property grids.
Click the 'Edit Schema' button and choose "Add property".
You can set various options about the new property for example:

Type - this specifies what type of property you want. "Text" gives you a larger text box which can store a string.

To access the properties from the script, there are various script functions.
See their descriptions for how they work.
By the way, all that I have written is documented in the manual.


Quote from: MiteWiseacreLives! on Fri 06/11/2015 16:40:33
is myHotspot a String, Int or a Pointer  ??? ??? ???

Should not be that hard to guess :D
Formerly known as global function GetLocationName,
static String Game.GetLocationName(int x, int y)


Martyn

#17
Sorry if you feel that way Snarky! :sad:
I was trying to explain, but its not easy when I miss something from the the beginning!

Vincent, true! I read the manual all the time but sometimes, I don't know really where the problem lies,
especially when iam not so skilled. :smiley:






MiteWiseacreLives!

Quote from: Vincent on Fri 06/11/2015 18:30:02

Quote from: MiteWiseacreLives! on Fri 06/11/2015 16:40:33
is myHotspot a String, Int or a Pointer  ??? ??? ???

Should not be that hard to guess :D
Formerly known as global function GetLocationName,
static String Game.GetLocationName(int x, int y)
I asked this question because if he made it a String (which he keeps a close secret) myHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);  will make no sense, myHotspot would have to be a Hotspot pointer.
ie:
Code: ags
Hotspot *myHotspot;
myHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
String myString;
myString = myHotspot.Name;


Vincent your only encouraging bad behaviour, Should not be that hard to guess :D ....

Crimson Wizard

#19
I think what Martyn needs, is to store a pointer to Hotspot in global script, and them use that pointer to get hotspot properties in room script :).

Quote from: Martyn on Fri 06/11/2015 18:43:57
Sorry if you feel that way Snarky! :sad:
I was trying to explain, but its not easy when I miss something from the the beginning!
Martyn, I think there is a misunderstanding here. What Snarky (and others) were asking you to do, is to explain what you want to have in a more general way, not related to any script mechanics (global variables and such).

SMF spam blocked by CleanTalk