Variable re-entrancy

In my big mayflower project, I've got thread safe script checked to prevent when I receive scripts from being triggered before completion


That has worked well over the years

But now I want to call some new scripts, but I want those ones to not be re-entrant safe.

Any ideas on how to proceed?

Couldn't you just use LAUNCH on them?

Wait, but launch only runs scripts while blocks under the launch blocks are running too

One sec I gotta test this out

Um it doesnt work for me.
(thread safe scripts, i mean)

It might but I'm just going to construct a simple example and see where it leads

So with default settings and as expected, tasks never complete

Enable Thread safe scripts and both tasks now run to completion before being triggered again

If I replace 2nd broadcast with a launch instead then I get this

which I think shows that task2 is being run several times in parallel (as it has task completion at 5,7,9 secs)
What I want task2 to do is what it did under the 1st condition of thread safe scripts being unticked


Background info as to why I'm after this
The wait 2 sec is simulating an incoming MQTT message event and I normally want anything triggered by that event to run to completion and ignore any other messages until that has happened. Which is why I enable Thread safe scripts

But now I want to be able to deal with a different event2, and not have that script run to completion unless the time between two successive event2 exceed the running time of the 2nd script

FYI I realise that I could stop all other scripts in sprite before launching each time but that approach only works if I only wanted to do this once

It wouldn't work if I wanted to launch another similar script in the same sprite

"Thread safe", run till completion, block reentry - with a variable "pending" as a semaphore
untitled script pic - 2022-05-21T231755.831

"Late to the party", abandon the pending, run the fresh one - if you can live with the clone as a semaphore & thread metaphore
untitled script pic - 2022-05-21T224759.965
Stage (28)

Of course custom "launch" blocks can be created.

I wanted to keep existing code the same and still use the Thread safe flag

But using a clone sprite - I think this is a workable solution as long as I don't try and trigger it every 1ms :slight_smile:
So this works the same as before


And when I adjust task2 repeat time to 6 secs it runs to completion

I've applied the when I start as a clone in my Mayflower project and it seems to be working lovely

Thanks for getting my brain working on it to find a solution :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.