diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 1fbe963c59..bd06b9eefd 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -49,6 +49,7 @@ public class LExecutor{ public Var[] vars = {}; public Var counter; public int[] binds; + public boolean yield; public int iptIndex = -1; public LongSeq graphicsBuffer = new LongSeq(); @@ -1128,6 +1129,7 @@ public class LExecutor{ }else{ //skip back to self. exec.var(varCounter).numval --; + exec.yield = true; } if(state.updateId != frameId){ @@ -1143,6 +1145,7 @@ public class LExecutor{ public void run(LExecutor exec){ //skip back to self. exec.var(varCounter).numval --; + exec.yield = true; } } @@ -1539,11 +1542,12 @@ public class LExecutor{ public static class FlushMessageI implements LInstruction{ public MessageType type = MessageType.announce; - public int duration; + public int duration, outSuccess; - public FlushMessageI(MessageType type, int duration){ + public FlushMessageI(MessageType type, int duration, int outSuccess){ this.type = type; this.duration = duration; + this.outSuccess = outSuccess; } public FlushMessageI(){ @@ -1551,16 +1555,20 @@ public class LExecutor{ @Override public void run(LExecutor exec){ - if(headless && type != MessageType.mission) return; + //set default to succes + exec.setnum(outSuccess, 1); + if(headless && type != MessageType.mission) { + exec.textBuffer.setLength(0); + return; + } - //skip back to self until possible - //TODO this is guaranteed desync on servers - I don't see a good solution if( type == MessageType.announce && ui.hasAnnouncement() || type == MessageType.notify && ui.hudfrag.hasToast() || type == MessageType.toast && ui.hasAnnouncement() ){ - exec.var(varCounter).numval --; + //set outSuccess=false to let user retry. + exec.setnum(outSuccess, 0); return; } diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index f839a14e9e..3806254550 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -1425,7 +1425,7 @@ public class LStatements{ @RegisterStatement("message") public static class FlushMessageStatement extends LStatement{ public MessageType type = MessageType.announce; - public String duration = "3"; + public String duration = "3", outSuccess = "success"; @Override public void build(Table table){ @@ -1444,12 +1444,14 @@ public class LStatements{ }, Styles.logict, () -> {}).size(160f, 40f).padLeft(2).color(table.color); switch(type){ - case announce, toast -> { + case announce, toast -> { table.add(" for "); fields(table, duration, str -> duration = str); table.add(" secs "); } } + table.add(" success "); + fields(table, outSuccess, str -> outSuccess = str); } @Override @@ -1459,7 +1461,7 @@ public class LStatements{ @Override public LInstruction build(LAssembler builder){ - return new FlushMessageI(type, builder.var(duration)); + return new FlushMessageI(type, builder.var(duration), builder.var(outSuccess)); } @Override diff --git a/core/src/mindustry/world/blocks/logic/LogicBlock.java b/core/src/mindustry/world/blocks/logic/LogicBlock.java index 7805e6830b..18093949ab 100644 --- a/core/src/mindustry/world/blocks/logic/LogicBlock.java +++ b/core/src/mindustry/world/blocks/logic/LogicBlock.java @@ -514,6 +514,10 @@ public class LogicBlock extends Block{ for(int i = 0; i < (int)accumulator; i++){ executor.runOnce(); accumulator --; + if(executor.yield){ + executor.yield = false; + break; + } } } }