RegEx Logic - Counter

    Joined
    Sep 9, 2013
    Messages
    68
    Reaction score
    10
    • Legacy Citizen 3
    So I was looking for cool things to do with regex and display modules.
    Here's one really cool thing i've found so far.

    A counter,
    It takes 2 steps to do it, but still, really awesome:

    [REPLACEALL]\b([0-9]+)\b[WITH]0$1~01234567890
    [REPLACEALL]\b0(?!9*~)|([0-9])(?=9*~[0-9]*?\1([0-9]))|~[0-9]*[WITH]$2

    Then just put a number to be incremented in another display block, and run these 2 display-block replacements. I connected 1 button to the next button to do the steps simultaneously. And now I can make any sort of counter I want.

    Want logic to activate every 2000 seconds? Just put a sensor compare, and reset the number :). Want to log how many times a logic-door got opened? EzPz
    Really not sure what else do with it- so far i've just used it as long delays, and just a general ship-uptime clock

    Anyone have other cool uses for this? Let me know! :)
    - If you're having trouble using this, I could upload some examples or explain more detail.

    Cheers!



    Credit to the Regex source:
    Is it possible to increment numbers using regex substitution?
     
    • Like
    Reactions: nightrune
    Joined
    Sep 11, 2015
    Messages
    59
    Reaction score
    19
    • Purchased!
    Nice! I wondered earlier if it's possible to do counters, as I could think many purposes for them =)
     
    Joined
    Jul 20, 2013
    Messages
    62
    Reaction score
    10
    can you use this to modify output of a display block based on a variable such as [sector]?
     
    Joined
    Sep 9, 2013
    Messages
    68
    Reaction score
    10
    • Legacy Citizen 3
    No, unfortunately the displayblock's are viewed much like the sensor blocks views them when doing a [REPLACEALL].
    That was actually solution #2 I proposed in your topic. Though, after some thought I don't think it would be for the best. - I feel like a middle-man like the [PARSE] suggestion would maintain the greatest amount of power. And then also apply your suggestion of the sensor block comparing the parsed results - I still can't see any argument against that. - but I digress.

    Tomssuli Do let me know if you find some good uses for it; I haven't really figured out much to do with it, besides look at it and say "Cool!".
    - I used it to have my ship rotate between red-alert every 30 seconds, just to evaluate the look of both modes while building. :D.
     
    Joined
    Jul 20, 2013
    Messages
    62
    Reaction score
    10
    yah i have a hard time coming up with anything but awesome things for it to do like logic jumpdrive autopilot or emergency jump out of a sector when shields hit 5%
     
    Joined
    Sep 11, 2015
    Messages
    59
    Reaction score
    19
    • Purchased!
    I'm thinking doing an on-ship swimming minigame (one that I saw on someones youtube-video) and thought it should have a lap-counter... and then a monitor telling announcing which player reached a certain amount of laps first: "Player [x] Wins!"

    EDIT: I already did it once, using "O":s as round indicators, but I scrapped it. Numbers would be nicer =)
     
    Joined
    Jan 25, 2015
    Messages
    964
    Reaction score
    225
    • Wired for Logic
    • Councillor 2 Gold
    • Legacy Citizen 5
    I got a thing that can convert 4 logic signals into 4 bits on a display. So give high, low, low, high and the display will say 1001.
    and also made a thing that can convert 4 bits on a display to 4 logic signals.
    It's not very impressive and uses 4-6 (can't remember) regexi (is that the plural word for regex right?) per direction but I could make it 8 bits with a bit of extra work like, 30-60 minutes for logic to display and another 30-60 for display to logic, maybe even less.
    The cool part is that you could, with smart placement, use it for better/compacter memory storage.

    ps: reading 4 bits takes 1 logic tick (so is pretty much instant)
     
    Joined
    Sep 9, 2013
    Messages
    68
    Reaction score
    10
    • Legacy Citizen 3
    Endal Yeah... - I'm working on the problem now. - Two big things stand in my way though; - I'm sick, and... I don't know regex :D.

    I've gotten this far:
    [REPLACEALL]\b([0-9]+)\b[WITH]$1~09876543210
    [REPLACEALL]\b0|([0-9])(?=0*~[0-9]*?\1([0-9]))|~[0-9]*[WITH]$2

    It actually works pretty well.. The problem is 10, 100, 1000, etc. It changes 100 to 099, and 10, 09. - This is actually corrected in the next reduction, where 09 becomes 8.
    Maybe someone smarter than me can fix it before I can.

    Edit: - Spent like 5 hours on this, and gave up. - The solution is simple, add a 3rd step; repeat the 2nd step... (just the \b0 part is important for the 3rd replacement)
     
    Last edited:
    • Like
    Reactions: Endal

    Olxinos

    French fry. Caution: very salty!
    Joined
    May 7, 2015
    Messages
    151
    Reaction score
    88
    I'm a bit (lot?) late, and someone certainly did it already... but wouldn't an additional "\b0*1(?=0+~)|" solve the problem?
    i.e. "\b0*1(?=0+~)|\b0|([0-9])(?=0*~[0-9]*?\1([0-9]))|~[0-9]*"
    (basically, let's match such annoying '1's and replace them with nothing instead of a '0')
    ...and while we're at it, let's replace "\b0" by "\b0+" so that 000 gives nothing instead of 99, 0020 gives 19 instead of 019, and 001 gives 0 instead of 00, that's slightly cleaner although not that useful (I think)
    i.e. "\b0*1(?=0+~)|\b0+|([0-9])(?=0*~[0-9]*?\1([0-9]))|~[0-9]*"

    Regex101 - online regex editor and debugger

    Unless I'm missing something important?
     
    • Like
    Reactions: Jaaskinal
    Joined
    Sep 9, 2013
    Messages
    68
    Reaction score
    10
    • Legacy Citizen 3
    No you're right. As I stated:
    Edit: - Spent like 5 hours on this, and gave up. - The solution is simple, add a 3rd step; repeat the 2nd step... (just the \b0 part is important for the 3rd replacement)
    Just cleaning up prefixing 0's.