[SOLVED] suggested max line size for a script?

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

[SOLVED] suggested max line size for a script?

by TumeniNodes » Wed Jul 13, 2016 22:41

I want to add arched glass to the angled glass in angled walls...
the angledwalls lua is already at 2301 lines of code : /
I sort of remember seeing something about a suggested max lines per script?
Should I create a new Lua file, just for these additional nodes? It will add only arched,angled glass for obsidian glass with default materials so, approx 24 new/additional nodes (or less)...
or..., should I just continue using the angledwalls.lua?

Now, there is a second part to this... I have also started making straight windows and window arches with the same, centered/thin properties to match with the angledglass nodes, again, using default textures.
But I am torn as to which way to put those out as well? I really don't think it makes sense to release an entirely separate mod for just those...
Should I just add a new .lua for all these new/additional glass nodes to the angledwalls mod? Is it too much?
Any suggestions are welcome from those who may have found themselves in such a position in the past...

p.s.
Yes folks, I am almost angled&arched out ; )
Last edited by TumeniNodes on Thu Jul 14, 2016 02:21, edited 1 time in total.
Flick?... Flick who?
 

KCoombes
Member
 
Posts: 278
Joined: Thu Jun 11, 2015 23:19
In-game: Knatt or Rudilyn

Re: suggested max line size for a script?

by KCoombes » Wed Jul 13, 2016 22:58

I wasn't aware there was a soft limit for lines of code, but I have one file that's 3179 lines that works just fine. If it really bothers you, I'd say break it into a second .lua file (or perhaps one file for stone, 1 for glass, 1 for clay, etc.... just to keep it organized).
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: suggested max line size for a script?

by Byakuren » Wed Jul 13, 2016 23:13

If there is a lot of boilerplate in your code you may be able to refactor it so that it does not take that much code. If you are creating the same nodes just with different textures, you can put all the textures in a list, and then use a loop to register a new set of arched/angled things with each texture.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: suggested max line size for a script?

by TumeniNodes » Wed Jul 13, 2016 23:20

KCoombes wrote:I wasn't aware there was a soft limit for lines of code, but I have one file that's 3179 lines that works just fine. If it really bothers you, I'd say break it into a second .lua file (or perhaps one file for stone, 1 for glass, 1 for clay, etc.... just to keep it organized).

Well now I'm not so concerned haha... thanks.
I think if this is the case, I will simply continue the angledwalls.lua, in the end it may be just about that size.
Thanks
Flick?... Flick who?
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: suggested max line size for a script?

by TumeniNodes » Wed Jul 13, 2016 23:23

Byakuren wrote:If there is a lot of boilerplate in your code you may be able to refactor it so that it does not take that much code. If you are creating the same nodes just with different textures, you can put all the textures in a list, and then use a loop to register a new set of arched/angled things with each texture.

Thank you...
the only problem I would have had with this is, these are customized textures and would not be able to use the textures in the way you describe.
If/when you see the textures you will see what I mean. It is the same for angledglass nodes. I only wish it were that simple to do that way... :P would have been very nice
Flick?... Flick who?
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

Re: [SOLVED] suggested max line size for a script?

by Sokomine » Thu Jul 28, 2016 18:54

Over 2000 lines of code for angled walls seems a bit much. Just out of curiosity I counted the lines in my mg_villages mod: 5985 lines alltogether, with mapgen.lua (longest one) consisting of 1241 lines.
Try to avoid repetitions in your code. From first glance: Take the collision_box definitions and pack them up into one variable (provided you need them that one at all!). Grab values for the new nodes (group, texture, description, ...) from the original block's definition. See what all these definitions have in common, check where they vary, and build a function that gets supplied with all that's diffrent from node to node as an extra parameter.
A list of my mods can be found here.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: [SOLVED] suggested max line size for a script?

by TumeniNodes » Fri Jul 29, 2016 07:49

Sokomine wrote:Over 2000 lines of code for angled walls seems a bit much. Just out of curiosity I counted the lines in my mg_villages mod: 5985 lines alltogether, with mapgen.lua (longest one) consisting of 1241 lines.
Try to avoid repetitions in your code. From first glance: Take the collision_box definitions and pack them up into one variable (provided you need them that one at all!). Grab values for the new nodes (group, texture, description, ...) from the original block's definition. See what all these definitions have in common, check where they vary, and build a function that gets supplied with all that's different from node to node as an extra parameter.


I could try to see if I'm able to do this, but I am still only at the copy/paste level (with experimental tinkering) with Lua.
Simply explained, I make a copy of a script, then tinker with settings, values, defs, etc... as well as copying existing script and pasting it, experimenting with various parts.
Anything which works is pure luck at my level :P
When I get an idea, I am limited to finding something similar on the mechanical level. I am a very slow learner when it comes to programming. I am a horrid textual learner, more of a visual/mechanical learner.
And for me to improvise workable solutions, while I am mysteriously talented and skilled at this in a visual/mechanical level, when it comes to the field of programming I'm greatly impaired.
Flick?... Flick who?
 

User avatar
Nathan.S
Member
 
Posts: 679
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21

Re: [SOLVED] suggested max line size for a script?

by Nathan.S » Sat Jul 30, 2016 01:44

As Sokomine said, try using a table and looping through that to set up the nodes if they are mostly all the same. I have a video explaining the process on my website. http://nathansalapat.com/minetest/using-tables-and-loops-minetest
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: [SOLVED] suggested max line size for a script?

by TumeniNodes » Sat Jul 30, 2016 03:36

Nathan.S wrote:As Sokomine said, try using a table and looping through that to set up the nodes if they are mostly all the same. I have a video explaining the process on my website. http://nathansalapat.com/minetest/using-tables-and-loops-minetest


Cool, thank you Nathan.
I like tutorial videos, I find them very helpful most of the time.
The reason I had to add so many nodes of the same item..., is for angled glass. And it is solely due to the fact I had to make custom textures for each one.
There is no way that I know of where I could use the same technique for the other nodes. Unlessss... I saw pithy's use of an overlay texture for his comboblock mod, and I am wondering if I could use the same idea in regards to the angled glass nodes?
Maybe, if I created an overlay for the side fillers, I could then use the same function used for the other nodes to cycle all the textures, rather than having to register each node individually as it is now.
idk... I will take a look later
Thanks all for the help and info and tips/ideas... it really is the best way to keep motivation rolling.
Flick?... Flick who?
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: suggested max line size for a script?

by pithy » Sat Jul 30, 2016 16:15

TumeniNodes wrote:
Byakuren wrote:If there is a lot of boilerplate in your code you may be able to refactor it so that it does not take that much code. If you are creating the same nodes just with different textures, you can put all the textures in a list, and then use a loop to register a new set of arched/angled things with each texture.

Thank you...
the only problem I would have had with this is, these are customized textures and would not be able to use the textures in the way you describe.
If/when you see the textures you will see what I mean. It is the same for angledglass nodes. I only wish it were that simple to do that way... :P would have been very nice

With the new angledglass model I gave you, you would not need customized textures.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: suggested max line size for a script?

by TumeniNodes » Sat Jul 30, 2016 23:43

pithy wrote:With the new angledglass model I gave you, you would not need customized textures.


I was not aware of that... how so?
If a texture (say, cobble) is set to the angled glass model... won't the whole node be covered with cobble?
The angled glass nodes use a filler on each side of the glass to blend with whichever texture the user wishes. If there actually is a way around that with the new model you gave me, please explain how I can implement this feature... (in layman's terms please :D )
If it truly is possible to use the same code for the other nodes to use all the textures..., for the newest glass node, I would be literally thrilled to be able to cut all the extra registered nodes : )

Then again... I will also be really bummed because all that work I did was for not... : /
Flick?... Flick who?
 

User avatar
pithy
Member
 
Posts: 252
Joined: Wed Apr 13, 2016 17:34
GitHub: pithydon

Re: suggested max line size for a script?

by pithy » Sun Jul 31, 2016 01:17

TumeniNodes wrote:
pithy wrote:With the new angledglass model I gave you, you would not need customized textures.


I was not aware of that... how so?
If a texture (say, cobble) is set to the angled glass model... won't the whole node be covered with cobble?
The angled glass nodes use a filler on each side of the glass to blend with whichever texture the user wishes. If there actually is a way around that with the new model you gave me, please explain how I can implement this feature... (in layman's terms please :D )
If it truly is possible to use the same code for the other nodes to use all the textures..., for the newest glass node, I would be literally thrilled to be able to cut all the extra registered nodes : )

Then again... I will also be really bummed because all that work I did was for not... : /


You would still need all of those nodes, but not your custom textures, and it would require change in code.
 

User avatar
Nathan.S
Member
 
Posts: 679
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21

Re: [SOLVED] suggested max line size for a script?

by Nathan.S » Sun Jul 31, 2016 02:36

You would probably end up doing something like this,
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
tiles = {{name='default_wood.png'},{name='default_clay.png'}},

replacing default_wood.png and default_clay.png with your glass and cobble texture.

Of course I didn't make the mesh models, so I couldn't say exactly how they were unwrapped but if pithy created the meshes with two texture slots on them, you'd just switch around whichever textures you needed and everything would just work TM.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: suggested max line size for a script?

by TumeniNodes » Sun Jul 31, 2016 02:48

pithy wrote:You would still need all of those nodes, but not your custom textures, and it would require change in code.


Well, if it will shorten the code and make it better / cleaner, I am all for it. : )
Flick?... Flick who?
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: [SOLVED] suggested max line size for a script?

by TumeniNodes » Sun Jul 31, 2016 02:50

Nathan.S wrote:You would probably end up doing something like this,
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
tiles = {{name='default_wood.png'},{name='default_clay.png'}},

replacing default_wood.png and default_clay.png with your glass and cobble texture.

Of course I didn't make the mesh models, so I couldn't say exactly how they were unwrapped but if pithy created the meshes with two texture slots on them, you'd just switch around whichever textures you needed and everything would just work TM.


If pithy confirms your thoughts, then it sounds fairly straight forward.
I don't mind the work if it means a cleaner, better code in the end...
Flick?... Flick who?
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron