Salam,
I applied the following script to have my cursor change from walk icon to interact icon on mouse over. Thing is it works fine for characters, but when I apply to objects it just doesn't work.
function room_RepExec()
{
if (Object.GetAtScreenXY(mouse.x, mouse.y) == oPaper)
{
Mouse.Mode = eModeInteract;
}
else Mouse.Mode = eModeWalkto;
This was added under room script.
A few things to consider:
- You forgot to not rape the indentation that the editor provides.
- Did you add the room_RepExec method to the room script manually, or did you add it by clicking the "..." button in the room properties?
- You're probably going to be checking more than just one Object, so you may want to consider storing the result in an Object*. You should never call Object.GetAtScreenXY (or similar methods) multiple times in the same function unless you're checking different coordinates or there is reasonable probability that the result may have changed.
- You're using the Mouse structure statically. You should never do this. It functions for everything except mouse.x and mouse.y, but unless those properties are made static, all you're doing is creating inconsistencies in your code. You can still access the static members using the mouse instance.
- You're missing a closing brace. Even if this was just a sample snippet, it's still best practice to always include the right braces. You can still omit any non-relevant code in-between.
- Is the method being called? This ties into whether the function is properly linked through the editor, but you can test using a status label, a Display statement, or even AbortGame.
- You mentioned using something similar for characters. Without seeing that code also, it seems likely the two could be interfering with each other.
- On that note, it seems like you may even want this to apply to all Objects, not just oPaper. If that's the case, you could just test that the returned Object* is non-null.
- Also, are you implementing a BASS-style two-mode interface? If that's the case then cursor modes aren't really even necessary and you could just handle everything just-in-time in on_mouse_click. Separate cursor modes really only matter if you're using a multi-cursor interface like Sierra or LucasArts.
Exactly, never implement global game mechanisms on a per-item or per-room basis. Never, ever.
An easy way of doing what you want is to add this inside repeatedly_execute in GlobalScript.asc:
if (mouse.Mode != eModeUseinv) {
int lt = GetLocationType(mouse.x, mouse.y);
int new_mode = eModeWalkto;
if (lt == eLocationCharacter) new_mode = eModeTalkto;
if (lt == eLocationObject || lt == eLocationHotspot) new_mode = eModeInteract;
if (mouse.Mode != new_mode) mouse.Mode = new_mode;
}
All points taken into account, thanks guys.
Quote- You forgot to not rape the indentation that the editor provides.
..wat?
Don't feed the troll. :)
Quote from: Dictionary.com (http://dictionary.reference.com/browse/rape)rape
verb (used with object)
7. to plunder (a place); despoil.
8. to seize, take, or carry off by force.
The act of destroying the indentation that the AGS script editor automatically provides is an act of violence and despoilment. Forcibly taking away a thing of such immense value is reprehensible. And I won't apologize for using a word in a valid context just because the connotation doesn't apply.
Since the word 'rape' isn't applied to any living thing, let alone human beings. I'm unable to comprehend why the fuck would someone get offended by this.
I wasn't offended, English is not my native language so I got a bit perplexed. No need to be hostile about it.