Here is what I need:
When all the planets are aligned and the stars are just right (i.e. a bool named Alpha is true) then clicking on the left mouse button does something specific. Now this can't go in the global script because this event should only happen in a specific room.
The code might look something like this:
if ((Alpha) && (button == eMouseLeft)) {
...
}
However, that obviously wouldn't work in a room script.
The solution may be a simple one and i'm just way over thinking the matter or something ...
You can actually add the function on_mouse_click() to the room script. It behaves the same as the global one. You can also use Mouse.IsButtonDown() to check whether a button is being pressed in some particular time (e.g. check it in repeatedly_execute() ).
let me be a little more clear on what i'm doing.
I tried this and it's not working in the room script. The following code is at the top of room script:
function on_mouse_click(MouseButton button)
{
if ((Alpha) && (Button = eMouseLeft)) {
cNPC.Walk(mouse.x, mouse.y, eNoBlock, eWalkableAreas);
}
}
Quote from: DrewCCU on Mon 14/06/2010 06:17:54
let me be a little more clear on what i'm doing.
I tried this and it's not working in the room script. The following code is at the top of room script:
function on_mouse_click(MouseButton button)
{
if ((Alpha) && (Button = eMouseLeft)) {
cNPC.Walk(mouse.x, mouse.y, eNoBlock, eWalkableAreas);
}
}
Are you sure you copied this section of codes from your script or you just typed them here?
There're some errors.
1. Button or button?
2. Button == eMouseLeft
Also, make sure that Alpha could indeed be set to some non-zero value in the game.
also make sure that your global function is not overriding your room function.
There is a function something like ClaimMouseEvent() which stops the global script from running.. but i cant remember the exact function.
Gilbet,
I've corrected those issues and it works now ... well kind of.
While testing I noticed that if i click the mouse somewhere cNPC does walk somewhere ... but not to where i clicked. cNPC kind of goes in the opposite direction of where my mouse clicked. It's a little weird and unexplainable.
Does mouse.x and mouse.y get screen coordinates or room coordinates? I would imagine it would get screen coordinates but my room is larger than the screen resolution so if it IS getting room coordinates then this MIGHT be the issue. But it doesn't look that way to me.
mouse.x and mouse.y use screen coordinates for obvious reasons. So, if you use scrolling rooms, make sure you write the destination of Walk() as GetViewportX()+mouse.x and GetViewportY()+mouse.y .
Note that for functions triggered by the same condition (such as on_mouse_click() ) the one in the room script will be executed, and then the one in the Global Script, so if you want to have the room script one override the global one, put a ClaimEvent() in the room one, so that the global version won't be executed afterwards.
works perfectly Gilbet. Thanks so much.