Blocking scripts

Started by AdamM, Mon 28/05/2007 00:00:51

Previous topic - Next topic

AdamM

I have a room where interacting with an object starts a script. The beginning of the script involves moving the player character over to the object. While doing so he passes over one or more regions. The regions are scripted to make things happen when the player passes over them. However, because the first interaction script is already running, the region script gets blocked and is only run once the interaction script is finished. This is not ideal, as the region script is meant to be run whenever the player passes over them. That said, I can live with the script not being run in this particular instance, as long as it is not run at the end of the interaction script.

So, what I'm looking for is either:
1) A way to tell the region script that the interaction script is running and it should therefore not run, or
2) Some kind of special function which I can place in my interaction script that can 'flush' the script threads and discard all queued-up blocked actions, thus preventing the region script from running.

(By the way, I hate repeatedly_execute and his sister _always with a passion, as I think this is the way out for the coward willing to accept a workaround. I'm not one of these.)

Thanks in advance!

GarageGothic

You can use the Region.Enabled property to turn off the regions at the start of the interaction, then turn them on again at the end of the interaction script.

AdamM

That sir is genius! Thank you!

...just in case, though, is there a way I can get my region script to run simultaneously without using repeatedly_execute_always?

GarageGothic

Your hatred of repeatedly_execute_always puzzles me, it's among my favorite functions and I certainly don't consider my scripting cowardly.

If you really do need to trigger events when the character walks through the region areas (after having turned the actual regions off), you could just break up the walking command into multiple parts, so the character walks to coordinates within the region, you run the region event (copy pasted into your interaction code), and then give him a new coordinate to walk to.

monkey0506

If you need a script run once every game loop, then the only way to get it done is by using repeatedly_execute[_always]. If you don't need to run the script every game loop, then there may be another method to solve your problem. This hardly makes the use of repeatedly_execute cowardly though.

An example of a script you may need to run every game loop would be a custom animation function (e.g., the functions I implemented in my GUIAnimation module). The purpose of the module was to provide animating backgrounds for GUIs. The only way to do this would be to set the background graphic, wait X game loops where X is the speed of that frame, change the background graphic, wait Y game loops where Y is the speed of the new frame, etc. To check if X/Y/Z/etc. game loops had passed, you would have to run a script from repeatedly_execute[_always]. There's simply no other means you could use to provide such an effect. So I wouldn't really call it cowardly.

Regarding the issue though, from your initial description I assumed you wanted the region interactions to be run, but as I read on, I gathered that you didn't want them to be run. Just in the event that it was the first, wouldn't the region script be run if the player.Walk command was passed as non-blocking?

The way you described the problem, I don't see a need for the walk to be blocking, but if you require it to be blocking for some other reason then you could try what GG said.

AdamM

The walk is part of a script, so if I switch the walk to eNoBlock, it immediately carries on before the character has reached his destination. Why, is there a way to check it before continuing with the script? if IsWalking==1... do what?

SMF spam blocked by CleanTalk