Stopping script/actions

Started by , Fri 13/01/2006 14:50:10

Previous topic - Next topic

BadBoyZ

Is there anyway to stop all user scripts/actions?
I have a room with an object which can be taken, but there is a gate in between. At the moment I'm using a region which will trigger when the player walks onto it and display "you can't get past the gate". What will happen is the "you can't get past the gate" message will be displayed after which the object will be taken in any case. I need to stop all interaction, not just in the current script so return doesn't help.

Any way to do this except for an if statement on each interactive object?

Khris

You have to intercept a left click.
You can do this in the global script, there's a function called on_mouse_click() which gets called everytime the player clicks somewhere on the screen.
By default, ProcessClick() is called after a left click.

default:
Code: ags
on_mouse_click(int button) {
...
Ã,  if (button==eMouseLeft) {
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, mouse.Mode);
Ã,  }
...
}


change it to:
Code: ags
on_mouse_click(int button) {
...
Ã,  if (button==eMouseLeft) {
Ã,  Ã,  if (player.Room==x && certain conditions are met e.g. gate is open) {Ã,  // <---- edit this line
Ã,  Ã,  Ã,  ProcessClick(mouse.x, mouse.y, mouse.Mode);
Ã,  Ã,  }
Ã,  Ã,  else {
Ã,  Ã,  Ã,  player.Say("Can't do that right now.");
Ã,  Ã,  }
Ã,  }
...
}


btw, did you read my answer in your other thread?

Ashen

#2
Changing on_mouse_click for this one thing seems a little excessive ... Why not just use variables? E.g. (pseudocode):
Code: ags

//Script for object - when player tries to take it
if (gate_is_open) {
  // Take object
}
else{
 // Do nothing
 Display ("The gate is in the way.");
}


How you'd check if the gate is open depends on how you've got it set up - either create a variable to check and change it when you open the gate, or if the gate is an object, you could base it on whether that object is visible or not, or whether the region is enabled, etc...

So, if .. else if statements for all objects, etc, is probably the best, simplest way (sorry, didn't see that bit ...) short of having two seperate rooms for gate open / gate closed.
I know what you're thinking ... Don't think that.

BadBoyZ

Quote from: khrismuc on Fri 13/01/2006 16:34:38
You have to intercept a left click.

This does seem a bit excessive, and then I'd still have to deal with actions which are allowed while the gate is closed (for example picking up something next to the character).

Quote from: khrismuc on Fri 13/01/2006 16:34:38
btw, did you read my answer in your other thread?

Yes, thanks for that. Initially I was looking for a way to turn off moveable sections, but couldn't find one (I blame this on my OO background and being unable to think of any other way than say moveable_section[0].disable()).

Khris

What the hell is a "movable section"? I've never heard of that in relation to AGS.

BadBoyZ

I meant walkable area, used to working with some outher proggies that have moveable sections.

Khris

Quote from: BadBoyZ on Sat 14/01/2006 14:26:31Initially I was looking for a way to turn off moveable sections, but couldn't find one (I blame this on my OO background and being unable to think of any other way than say moveable_section[0].disable()).
Well, as I wrote in the other thread, the commands you need are RemoveWalkableArea(); and RestoreWalkableArea();.

It isn't necessary to disable all script actions. Turn off the walkable area behind the gate in the first time player enters screen-Interaction of your room, then turn it back on as soon as the player gets the gate open.
I don't know what your PickUpObject-Code looks like, so you'd have to make sure that the player has successfully reached some walk-to-point before actually picking up the object. Otherwise the player would be unable to reach the object (due to the turned off WA) but still pick it up afterwards, in terms of the object disappearing from screen and getting added to the inventory.

SMF spam blocked by CleanTalk