Anuken / Mindustry-Suggestions

Repository for Mindustry suggestions and feedback
130 stars 58 forks source link

Support for proper programming languages in processors. #4296

Closed UltraBlackLinux closed 1 year ago

UltraBlackLinux commented 1 year ago

Describe the content or mechanics you are proposing.

(Related to https://github.com/Anuken/Mindustry-Suggestions/issues/3270, but I want to add some more arguments on top that hopefully work out better)

I really like that you are able to automate several tasks in this game using processors. It's very cool, that you can even program right from a text editor and "upload" that into the processor.

The issue is, that this programming language is very bare bones. Programming in-game is very slow and tedious, having to rearrange blocks like crazy, not having if statements and not being able to combine multiple lines into one by just writing an instruction into e.g. a boolean field. (See scratch)

My suggestion here is to provide ways to add more programming languages or even implement support for them directly.

Describe how you think this content will improve the game. If you're proposing new content, mention how it may add more gameplay options or how it will fill a new niche.

Now you might think "just get better at mlog". This is kind of true, but it doesn't solve the whole situation.

Let me say it, assembly is hard, and that's because of it's simplicity. I really think that a programming language like Lua is easier to understand and ultimately provides more features that don't have to be painstakingly implemented (like string comparison). It's further troublesome that mlog is a kind of unintuitive programming language that has even less features than assembly itself making working with it even more difficult as it's less extensible.

If there was a more user friendly logic system in-game, maybe there would be less issues with people forgetting to unbind constructs, just because it's way more accessible. There could be functions that can be called to run specific behaviour instead of having to use entire duplicated blocks just to call a few blocks in different contexts.

Bad "coding" practices just spread around the servers constantly because a processor implements a (working) feature that you would usually have to create yourself. The messy block style of the language, which does not even support comments (afaik, this might have changed) makes it really hard to build upon someone's work and maybe even improve it to a point where units maybe get unbound when they should.

TL;DR: My point is that mlog is hard to use, tedious to program in-game and has unintuitive operations that sometimes really limit the freedom of the person working with mlog. "Just" using a programming language that supports easier access to qOL features would certainty improve the situation of people using bad code they found because it's too hard to modify.

Edit: It just came to my mind that this game is the perfect basis to learn programming in general. Programming is all about automation and where better use it than where you really need it (in a factory environment)?

Edit 2: I'm not saying mlog should be replaced, for compatibility and newcomer friendlyness. I think it should be easier to program more advanced stuff.

Before making this issue, check the boxes below to confirm that you have acknowledged them.

Redo11 commented 1 year ago

After talking with the dumbass above, I have proposed a jump to block, which instead of jumping to hardcoded place, jumps to a variable, allowing creations of functions.

Pseudocode: 1 tell "hello" 2 set A = 4 3 jump to "5" 4 end 5 tell "woo hoo" 6 jump to A

TheEt1234 commented 1 year ago

just use an unofficial compiler (to mlog) like mlogjs

TheEt1234 commented 1 year ago

After talking with the dumbass above, I have proposed a jump to block, which instead of jumping to hardcoded place, jumps to a variable, allowing creations of functions.

Pseudocode: 1 tell "hello" 2 set A = 4 3 jump to "5" 4 end 5 tell "woo hoo" 6 jump to A

isnt that literally what @counter does??? you can modify it with the operation instruction

UltraBlackLinux commented 1 year ago

just use an unofficial compiler (to mlog) like mlogjs

This is not a solution. What you end up with is a codebase that needs to be very barebones, barely using the features of the programming language, just so that it can work with mlog. You are still limited by a very small feature set. You can not really use what the programming language provides.

I checked out all of these projects, but they all have this same problem.

Redo11 commented 1 year ago

🤓

UltraBlackLinux commented 1 year ago

I'm gonna try creating a mindustry addon for demonstration purposes later.

From what I've seen pretty much all issues that came to my mind can be dealt with easily: https://github.com/luaj/luaj/blob/master/examples/jse/SampleSandboxed.java (Only specific libs, instruction limit)

Edit: I'm giving up for now. Java is a neat language but it's compilers are all shit, the language servers are all broken and you basically cannot work on java without a language server.

The Resources I planned to use: https://github.com/luaj/luaj/blob/master/examples/lua/samplesandboxed.lua https://github.com/luaj/luaj/blob/master/examples/jse/SampleSandboxed.java https://mindustrygame.github.io/docs/mindustry/world/blocks/logic/package-summary.html https://mindustrygame.github.io/docs/mindustry/world/blocks/package-summary.html https://mindustrygame.github.io/wiki/Modding%20Classes/LogicBlock/ https://mindustrygame.github.io/wiki/blocks/400-micro-processor/ https://github.com/Anuken/Mindustry/blob/master/core/src/mindustry/logic/LExecutor.java https://github.com/Anuken/Mindustry/blob/master/core/src/mindustry/logic/GlobalVars.java

Dangleos commented 1 year ago

🤓

Dum dum

UltraBlackLinux commented 1 year ago

I picked this back up and will try to continue working on it.

You can track my progress here

UltraBlackLinux commented 1 year ago

Finally got the library working. Just need to iron out all the bugs now.

https://chonkyrabbit.eu/files/_share/lua-processors.mp4

UltraBlackLinux commented 1 year ago

giving up because luaj has some scuffed issues.

Might need to switch to

airminer/jnlua or something comparable

TheEt1234 commented 1 year ago

no way mans insane enough to do it

github-actions[bot] commented 1 year ago

This suggestion is now stale, and will be automatically closed.