Stormworks: Build and Rescue

Stormworks: Build and Rescue

Why the character limit for custom lua (as it is now) is stupid. IMHO
I gave up on making my engine control on logic blocks and went to lua.
And I understand that it has to be limited for obvious reasons, but the way the limit is in place is stupid. And I will explain here why.
  1. The character limit includes comments. Which will only lead to uncommented scripts, especially if they are longer and more complicated (aka, hurting for space).
  2. The character limit will also encourage undescriptive names for variables and functions.
  3. Lastly if you run out of space you will start splitting it up over several lua scripts.
    But at least for what I am doing it will mean that several scripts doing the same stuff. Using more calculating power.

Here is my idea to improve that. Make a global limit. Means no matter how many controllers or custom luas you have in a creation the total will be limited.
Don't limit characters, limit instead the number of functions and variables that can be used.
Last edited by ~* BiZZ Keryear *~; Jul 5, 2020 @ 2:00am
< >
Showing 1-15 of 32 comments
Malli Jul 5, 2020 @ 2:25am 
Apparently its a technical issue and cannot simply be "increased" higher. Somethin about the lua interpreter they use for the game doesnt allow a single script to go beyond that limit.
Ah ok. Never mind then
Ra-Ra-Rasputin Jul 5, 2020 @ 2:38am 
It's not the LUA interpreter, but an intentional limit as far as i'm aware. It's a good limit that forces scripts to be reasonably optimized and efficient. Most things that are done now could be done in 1000-2000 characters as well, and they'd be better optimized for the most part.

I can understand the comments causing issues, but 4000 characters is more than enough to make an operating system. Most BIOSes are less. You can define all your variables and aliases at the start of the file so they aren't much of an issue.

Global limits are a bad idea to begin with, and you'd have roundabout ways around them at any rate.
Last edited by Ra-Ra-Rasputin; Jul 5, 2020 @ 2:40am
zaaephod Jul 5, 2020 @ 10:48am 
I agree, it's frustrating, but I've been using this site to create and minify the LUA code, so you can have a working version, and a sort of 'compiled' version. Maybe this will help you, too. https://lua.flaffipony.rocks/
pieter.1992 Jul 5, 2020 @ 11:59am 
i have an engine instrumentation script that i wrote that's basically 1800 line long.so its still way below that 4096 line limit and very much adaptable. that script is not on the workshop. yet. i actually use https://lua.flaffipony.rocks/ quite a lot when creating these crazy scripts that can get very confusing, very fast
Sakarias Jul 6, 2020 @ 1:47am 
Originally posted by ~* BiZZ Keryear *~:
I gave up on making my engine control on logic blocks and went to lua.
...

I believe the devs have already answered this here if you scroll to the bottom.
http://mcro.org/issues/view_issue/10756

"Sorry, but 4096 will stay. Enough to code most of the things. You can use multiple Lua components anyway."

Originally posted by Ra-Ra-Rasputin:
It's not the LUA interpreter, but an intentional limit as far as i'm aware. It's a good limit that forces scripts to be reasonably optimized and efficient. Most things that are done now could be done in 1000-2000 characters as well, and they'd be better optimized for the most part.

I can understand the comments causing issues, but 4000 characters is more than enough to make an operating system. Most BIOSes are less. You can define all your variables and aliases at the start of the file so they aren't much of an issue.

Global limits are a bad idea to begin with, and you'd have roundabout ways around them at any rate.

The number of characters in a script has no correlation to efficiency or optimization but you could relate it to size in memory(which we have a lot of nowadays). There might be 100 characters of slow code or 4000 characters of fast code. There could be 4000 characters of unreadable code and there could also be 4000 characters of readable code where the 4000 characters of unreadable code is most likely more code.

I don't think it's fair to compare this to BIOSes or OS. For one thing they didn't have any character limit so whoever made the BIOS or OS has no excuse to have undescriptive code. It's also not the same use case. We're making high level gameplay code in a script language.

My point is the character limit doesn't make any sense to the end user who writes the script. There are also several ways to avoid the limit by minimizing code or just having several nodes so what's the point of it? The limit has no real effect and the only thing it does now is enforce bad practices. For example creating aliases is a solution to a problem that was created by the developers themselves. Why not just remove this problem that doesn't need to exist?

I would just remove the limit completely. That way we get what we already have today but without workarounds(several nodes, minimizing code, etc).
Ra-Ra-Rasputin Jul 6, 2020 @ 2:30am 
When you don't have access to extremely heavy methods that translate to a significant amount of instructions (delegates, lambda) or many method calls, yes, the length directly correlates with optimization and efficiency. Though to be fair, the efficiency is more down the conversion line on what's being interpreted and how.

Newer programmers don't really understand optimization or efficiency, because they don't have to. At most C++ programmers have to do very lightweight memory management, and that's that, but in reality there's very few cases where shorter code with no method calls would be less efficient than code that's longer. The only exceptions are really extremely heavy maths, data tables and data sorting, none of which you'll do here. Draw calls are the heaviest thing there is.

Why wouldn't it be a fair comparison? It's an operating system we're talking about vs. a bit of code that affects some numbers in most cases.

The limit is there to guide you in the right direction. Sure, there are awfully written scripts already that alone managed to slow down the tick rate without the intention to do so, but they're fairly rare. Besides, you alias things in normal coding all the time as well. What do you think the "include"/"import" instruction does?

I'm more than happy to support comments not affecting character limit, as they're a very important part, but i believe the limit should be there.
Last edited by Ra-Ra-Rasputin; Jul 6, 2020 @ 2:31am
Sakarias Jul 6, 2020 @ 3:16am 
Now i'm not trying to misunderstand you. I just want to bring up an example that hopefully we can agree on. If the length directly correlates with optimization and efficiency then the code below should be slower than the second snippet.

local function add(first, second) return first + second end local function doSomething() local first = 1 local second = 2 return add(first, second) end

local function a(b,c)return b+c end;local function d()local b=1;local c=2;return a(b,c)end

This is not the case.

It's not a fair to compare this to writing a BIOS or OS because people don't play Stormworks to write an OS or BIOS. I wouldn't write a BIOS or OS in Lua either. It's not the same demographic.

The limit encourages users to write code as in the second snippet and it gives us nothing but code that is hard to read.

Also about the aliasing. If you do it for the reason to lower the amount of chars in your scripts i believe it's the wrong reason since again it will make it harder to read.
Originally posted by Ra-Ra-Rasputin:
It's not the LUA interpreter, but an intentional limit as far as i'm aware. It's a good limit that forces scripts to be reasonably optimized and efficient. Most things that are done now could be done in 1000-2000 characters as well, and they'd be better optimized for the most part.

I can understand the comments causing issues, but 4000 characters is more than enough to make an operating system. Most BIOSes are less. You can define all your variables and aliases at the start of the file so they aren't much of an issue.

Global limits are a bad idea to begin with, and you'd have roundabout ways around them at any rate.
Well, as I said if that is the case then it misses it mark completely. It only causes to be undocumented and undescriptive (why use function drawLayout() if you can save so much letters with function a(), same for variables who will use a variable like motorRpsGood when you can save space with a ... of course one tells you on first glance what it does while the other is decendence into madness)

Originally posted by Sakarias88:
[...snip...]
Perfectly said. Exactly what I meant.
Originally posted by pieter.1992:
i have an engine instrumentation script that i wrote that's basically 1800 line long.so its still way below that 4096 line limit and very much adaptable. that script is not on the workshop. yet. i actually use https://lua.flaffipony.rocks/ quite a lot when creating these crazy scripts that can get very confusing, very fast
It is not 4096 lines. It is 4096 characters!
ElfBossHogg Jul 6, 2020 @ 4:01am 
The limitations are based on the fact that the current standard for Lua is that the interpreter in canonical mode is restricted to 4096 characters. Lua converts the "string of code" in the editor in to the functional code. The max string limit in Lua is 4096 characters. Canonical mode allows for the integration of a editor in system. Non-canonical allows for larger lengths but it is command line based.

Just do a search on Lua and 4096. Did you think the interpreter was coded from scratch? It's probably based on the integration of a developer toolkit.
Alistair Jul 6, 2020 @ 10:28am 
https://steamcommunity.com/sharedfiles/filedetails/?id=2156513506

yeah it's really annoying. But at least it stops the game from being unplayable.
Ra-Ra-Rasputin Jul 6, 2020 @ 11:03am 
You should just alias those. Sadly with LUA it's not so nice to run them inline, at least with my limited LUA knowledge compared to other languages, so you can't DrText and SetClr on the same line as easily.

Also if you're consistently ending up with similar settings you can treat them as presettable optional entries by making a method with them already in place.
Malli Jul 6, 2020 @ 12:05pm 
Originally posted by AngusRetriever:
https://steamcommunity.com/sharedfiles/filedetails/?id=2156513506

yeah it's really annoying. But at least it stops the game from being unplayable.

Why dont you use alias?
Alistair Jul 6, 2020 @ 12:11pm 
wAiT a mInuTe

So I can write more than one draw/input etc. thing on one line of text?
< >
Showing 1-15 of 32 comments
Per page: 1530 50

Date Posted: Jul 5, 2020 @ 2:00am
Posts: 32