r/Tf2Scripts • u/prolvlwhale • Jul 23 '22
Script I wrote a brainfuck interpreter in console
This is my first high-level script so it probably isn’t that good. However, it allows brainfuck programs to run in the console, which I think is really cool.
Feel free to tell me any optimizations or tips on documentation, or if you want to know how any of the code works. It’s a little hack-y, but it works!
18
Upvotes
2
u/Auran64 Jul 23 '22
actually pretty interesting... any practical usecase as far as you're aware?
2
u/KatenGaas Jul 23 '22
:)
2
u/Exponential_Rhythm Jul 23 '22
Now, this is what I like to see.
1
u/just_a_random_dood Jul 23 '22
this is wicked impressive lmao
nice job :)
1
u/JarateKing Jul 26 '22
Impressive work!
Am I right that the
alias c<x> "inc; airgap; c<x+1>"format is just to support loops (instead of something likeinc;inc;ptr+;where the commands are just in direct sequence)? And are theairgaps there to ensure that things can infinite loop without crashing the game? Or is there something more I'm missing about themJust looking at it, I'm wondering if something like this would be possible:
So that you could write programs like:
I remember working on a brainfuck interpreter a long while back. It was in the
inc;inc;ptr+;style though. My approach to looping was to force the user to put it in a file, and then re-exec that file whenever it needed to loop, ignoring anything until the desired[was encountered (I kept track of this via a counter, where no commands would work until the counter was at 0, decrementing each time it encountered a[). The re-exec was the only point I threw in await. There was some logic error in it that I never figured out though, and it didn't work in more complicated cases.I wonder if you could write it in the style of
inc;inc;ptr+;and then, behind the scenes, each time a command is run it fills it into a buffer. This way we build upalias c0 "inc",alias c1 "inc",alias c2 "ptr+"without needing to write it that way yourself -- instead you'd just writeincand then that'dalias c0 inc_real(and then set up the next command to bealias c1 inc_realand so on) without needing to do so manually. Best of both worlds kinda approach -- writes like one but has the functionality of the other.2
u/[deleted] Aug 03 '22
bros bout to release TF3 as a sub game in TF2 before valve even manages to fix the bots
x)
1
u/r3t4r0 Jul 24 '22
r/madlads