tip for graphics

Place to get help with not working mods / modding interface.
User avatar
Lutra
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Fri Apr 01, 2016 9:22 pm
Contact:

tip for graphics

Post by Lutra »

Ever get tired of adding 20 items, having to type out "icon = "__mymod__/graphics/icons/item.png" 20 times, and then again for the entities, and then again for technologies? I did.

When starting a prototype file, before entering data:extend, simply add
iconpath = "__mymod__/graphics/icons/"
then, when you need to specify an icon, use
icon = iconpath.."item-png"
then you win :D
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
Sean Mirrsen
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Apr 27, 2016 6:30 pm
Contact:

Re: tip for graphics

Post by Sean Mirrsen »

That is actually very helpful! :D

Thank ye kindly for this bit of wisdom. :)
Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: tip for graphics

Post by Zeblote »

Why are you typing that 20 times? Copy-paste and autocomplete are your friends :D
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: tip for graphics

Post by prg »

If you're creating lots of similar prototypes you can even go a step further and do something like

Code: Select all

function beltplanner_item(type)
    return {
        type = "item",
        name = "beltplanner-"..type,
        icon = "__beltplanner__/graphics/beltplanner-"..type..".png",
        flags = {"goes-to-quickbar"},
        place_result = "beltplanner-"..type,
        stack_size = 50,
    }
end

data:extend({
    beltplanner_item("basic"),
    beltplanner_item("fast"),
    beltplanner_item("express"),
    beltplanner_item("end"),
})
to save even more typing. Lua is amazing.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: tip for graphics

Post by ArderBlackard »

prg wrote: Lua is amazing.
I'd say "programming is amazing". The same approach is possible for almost all programming languages. ;)
Gib dich hin bis du Glück bist
Sean Mirrsen
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Apr 27, 2016 6:30 pm
Contact:

Re: tip for graphics

Post by Sean Mirrsen »

ArderBlackard wrote:
prg wrote: Lua is amazing.
I'd say "programming is amazing". The same approach is possible for almost all programming languages. ;)
That is true. However, Lua being a scripting language (or, the proper term I suppose being, "interpreted language", more specifically a multi-paradigm, dynamically typed, interpreted language), it allows for this sort of thing to be typed up in Notepad and just plugged into the main program without any recompilation. It doesn't need includes for basic functions, doesn't need you to cast data types into one another, and generally simple to use. I know there are a lot of programming languages offering similar functions, but I'd say Lua is still, in itself, amazing. :)
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: tip for graphics

Post by prg »

Damn, I wasn't even being serious. Of course calling a function is a fundamental programming concept and does not make Lua special. I actually hate duck typing and that everything that does not exist is implicitly nil. Causes way too many unnecessary errors which could easily be avoided with a proper type system that checks if a function is called with the right number of arguments etc. Refactoring Lua code is a nightmare, if you missed something somewhere it'll only blow up at run time even if such an error could be easily detected with static type checking.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: tip for graphics

Post by ArderBlackard »

Sean Mirrsen wrote: Lua being a scripting language (or, the proper term I suppose being, "interpreted language", more specifically a multi-paradigm, dynamically typed, interpreted language)
BTW I guess that Factorio uses LuaJIT which allows compiling Lua code for a great performance boost. Run-time interpretation usually is slow :)
prg wrote: I actually hate duck typing and that everything that does not exist is implicitly nil
Can't say I 'hate' it, but I also prefer using statically typed languages. In my opininon the main (dis)advantage of Lua is that it is extremely simple in it's syntax (while not in power).
prg wrote:Refactoring Lua code is a nightmare, if you missed something somewhere it'll only blow up at run time even if such an error could be easily detected with static type checking.
If this would be of any help, you may try a JetBrains IntelliJ IDEA with Lua plugin. It does not provide as good refactoring/control possibilities as for other languages in IDEA (or like a ReSharper for respective languages :) ), but at least allows simple refactorings (like local names renaming, variables extraction etc.), and even to some extent an on-the-fly code analysis and errors detecion.
I have tried a number of other editors/IDEs (notepad++, ZeroBrain Studio, VSCode) and for now it seems to be the best option.
P.S. It seems I'm being Captain Obvious -_-
Gib dich hin bis du Glück bist
Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: tip for graphics

Post by Zeblote »

ArderBlackard wrote:BTW I guess that Factorio uses LuaJIT which allows compiling Lua code for a great performance boost. Run-time interpretation usually is slow :)
Factorio doesn't use luajit, at some point the devs actually said it would be unnecessary (wtf?) but seems to be planned for 0.13 now :D
User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: tip for graphics

Post by ArderBlackard »

Nice to hear it! :) Seems like the devs themselves didn't realize a complexity of the mods the community would try to implement :D
Gib dich hin bis du Glück bist
Sean Mirrsen
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Apr 27, 2016 6:30 pm
Contact:

Re: tip for graphics

Post by Sean Mirrsen »

ArderBlackard wrote:Nice to hear it! :) Seems like the devs themselves didn't realize a complexity of the mods the community would try to implement :D
I'd dare to say that there's quite a lot of complexity the devs did not realize the mod community would want to make. :P

You can't have a fuel-fed power generator unless it extracts energy from fluid, you can't rotate an assembly machine before or after placement unless it has an assigned fluidbox, you can't make a lamp that burns fuel (aka brazier, or sconce) even if you can set the energy source to "burner" (it won't accept fuel), you can't make anything that doesn't explicitly allow it not require power (lamps, inserters, etc), the list goes on and on. We're saved only by the tremendous capacity for kludge solutions that the Lua scripting provides. :)
(even then, I needed to make a large subroutine that creates copies of some transport belts and their contents, in order to rotate them along with the building they're attached to, because it's impossible to move transport belts via code. Limits, limits everywhere.)
User avatar
Lutra
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Fri Apr 01, 2016 9:22 pm
Contact:

Re: tip for graphics

Post by Lutra »

the devs have also removed the file system included with Lua. i guess it means security, but makes a lot of problems...
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
Sean Mirrsen
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Apr 27, 2016 6:30 pm
Contact:

Re: tip for graphics

Post by Sean Mirrsen »

Lutra wrote:the devs have also removed the file system included with Lua. i guess it means security, but makes a lot of problems...
There's problems, and there's problems. Modders not having quite the same power as they could does not quite measure up to the magnitude of "problem" that a keylogger or trojan hidden in 5000 lines of elaborate filesystem-accessing code can create. Especially if you consider the devs as being a company with a public image.
User avatar
Lutra
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Fri Apr 01, 2016 9:22 pm
Contact:

Re: tip for graphics

Post by Lutra »

hehehe. should probably change this topic to 'language discussions'.
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: tip for graphics

Post by Zeblote »

Sean Mirrsen wrote:There's problems, and there's problems. Modders not having quite the same power as they could does not quite measure up to the magnitude of "problem" that a keylogger or trojan hidden in 5000 lines of elaborate filesystem-accessing code can create. Especially if you consider the devs as being a company with a public image.
How do you get from basic file access to a trojan or keylogger? The lua api wouldn't have any way to run an executable, obviously.
Sean Mirrsen
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Apr 27, 2016 6:30 pm
Contact:

Re: tip for graphics

Post by Sean Mirrsen »

Zeblote wrote:
Sean Mirrsen wrote:There's problems, and there's problems. Modders not having quite the same power as they could does not quite measure up to the magnitude of "problem" that a keylogger or trojan hidden in 5000 lines of elaborate filesystem-accessing code can create. Especially if you consider the devs as being a company with a public image.
How do you get from basic file access to a trojan or keylogger? The lua api wouldn't have any way to run an executable, obviously.
Lua is a programming language. Any programming language with filesystem access can be used to create malicious code, in one way or another. The OS is often all too happy to automatically run plain-text scripts placed in certain strategic locations, for instance.
User avatar
ArderBlackard
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Thu May 05, 2016 12:41 pm
Contact:

Re: tip for graphics

Post by ArderBlackard »

Currently there is a game.write_file(path, content) function that can write files to disk, but only to a specific folder "script-output" (subfolders can be created too). I guess that ability to read files from this sandboxed folder would be enough for the majority of IO-related tasks,

UPD: At least it can solve the long-term problem of "Pass some info from data.lua to control.lua" :lol:
Gib dich hin bis du Glück bist
Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: tip for graphics

Post by Zeblote »

Sean Mirrsen wrote:
Zeblote wrote:
Sean Mirrsen wrote:There's problems, and there's problems. Modders not having quite the same power as they could does not quite measure up to the magnitude of "problem" that a keylogger or trojan hidden in 5000 lines of elaborate filesystem-accessing code can create. Especially if you consider the devs as being a company with a public image.
How do you get from basic file access to a trojan or keylogger? The lua api wouldn't have any way to run an executable, obviously.
Lua is a programming language. Any programming language with filesystem access can be used to create malicious code, in one way or another. The OS is often all too happy to automatically run plain-text scripts placed in certain strategic locations, for instance.
You could limit file access to subfolders inside the game folder, then. No harm done creating malicious files if you can't run them.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: tip for graphics

Post by Adil »

prg wrote:I actually hate duck typing and that everything that does not exist is implicitly nil. Causes way too many unnecessary errors which could easily be avoided with a proper type system that checks if a function is called with the right number of arguments etc. Refactoring Lua code is a nightmare, if you missed something somewhere it'll only blow up at run time even if such an error could be easily detected with static type checking.
But hey that's what makes lua fun to code! Just type whatever comes to your head , not think about formal stuff.
Also, certain tricks actually work due to language defined this way.
Surely, once code gets over certain limit, it collapses on itself like a supernova, but for sufficiently separated small bits of scripts that works.
Also, it's sufficiently fluid for the coder to implement those checks without much effort. [1][2]
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
Sean Mirrsen
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Apr 27, 2016 6:30 pm
Contact:

Re: tip for graphics

Post by Sean Mirrsen »

ArderBlackard wrote:UPD: At least it can solve the long-term problem of "Pass some info from data.lua to control.lua" :lol:
I wasn't aware there was even a need to pass info from data to control. Isn't data just a hub for all the things you've got spread around the mod's folders, with some final fixes thrown in? Could you describe a use case, I'm actually curious. :)
Zeblote wrote:You could limit file access to subfolders inside the game folder, then. No harm done creating malicious files if you can't run them.
And yeah, I suppose that could work. Still probably wise to not even have a hint of a possibility of a security hole, but with sufficient control it could be "safe enough" at least.
Post Reply

Return to “Modding help”