diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 708d3bd0e1..9efc9b9a4b 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2288,7 +2288,7 @@ unit.emanate.description = Builds structures to defend the Acropolis core. Repai lst.read = Read a number from a linked memory cell. lst.write = Write a number to a linked memory cell. lst.print = Add text to the print buffer.\nDoes not display anything until [accent]Print Flush[] is used. -lst.format = Replace next placeholder ("[accent]@[]") in text buffer with a value.\nExample:\n[accent]print "test @"\nformat "example" +lst.format = Replace next placeholder in text buffer with a value.\nDoes not do anything if placeholder pattern is invalid.\nPlaceholder pattern: "{[accent]number 0-9[]}"\nExample:\n[accent]print "test {0}"\nformat "example" lst.draw = Add an operation to the drawing buffer.\nDoes not display anything until [accent]Draw Flush[] is used. lst.drawflush = Flush queued [accent]Draw[] operations to a display. lst.printflush = Flush queued [accent]Print[] operations to a message block. diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 253d452b0c..01e5266fea 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -1113,7 +1113,21 @@ public class LExecutor{ if(exec.textBuffer.length() >= maxTextBuffer) return; - int placeholderIndex = exec.textBuffer.indexOf("@"); + int placeholderIndex = -1; + int placeholderNumber = 10; + + for(int i = 0; i < exec.textBuffer.length(); i++){ + if(exec.textBuffer.charAt(i) == '{' && exec.textBuffer.length() - i > 2){ + char numChar = exec.textBuffer.charAt(i + 1); + + if(numChar >= '0' && numChar <= '9' && exec.textBuffer.charAt(i + 2) == '}'){ + if(numChar - '0' < placeholderNumber){ + placeholderNumber = numChar - '0'; + placeholderIndex = i; + } + } + } + } if(placeholderIndex == -1) return; @@ -1122,13 +1136,13 @@ public class LExecutor{ if(v.isobj && value != 0){ String strValue = PrintI.toString(v.objval); - exec.textBuffer.replace(placeholderIndex, placeholderIndex + 1, strValue); + exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, strValue); }else{ //display integer version when possible if(Math.abs(v.numval - (long)v.numval) < 0.00001){ - exec.textBuffer.replace(placeholderIndex, placeholderIndex + 1, (long)v.numval + ""); + exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, (long)v.numval + ""); }else{ - exec.textBuffer.replace(placeholderIndex, placeholderIndex + 1, v.numval + ""); + exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, v.numval + ""); } } }