I'm just starting out in the modding community and LUA programming in general, and I have a couple of problems, that make my modding life miserable.
I do have a PHP, C++, JS, HTML background (in diminishing order), so I do understand the basics. I'm just not familiar with Factorios game structure enough yet.
First of is the scope of functions and variables from the mod.
For instance, I use the console to help me out a lot and usually start the game with adding the following line to it:
Code: Select all
pr = function(text) game.player.print(text) -- this is an example, don't go all "it's not MP proof" on me :)
I'm also having trouble getting some of my variables to initialize (most likely, the same problem as above). In particular I'm trying to get a small notes thing going (don't need to keep data after quit) and would like to store strings and some uints locally. By that I mean, if I ever do make it MP proof, I don't need (want) other player to see this array/table or have access to it. Nor do I want to cause any kind of desyncs or save alterations. I'm aware of the "remote.some.things[player_index]" thing, i would just like to know my limitations, before I go down that route. At this point I can't even get a simple variabale like redfury = "Hello" to get passed to the game so I could print it out... but all I get is NIL! And I tried it in on_init, on_load, outside of functions, control and data lua, local, global.redfury and other more or less useless things. The only thing that comes to mind that i didn't try was squishing it into data.raw . But it didn't seem to be the right way anyways. The only other thing i can think of, is creating a hidden frame or label and dumping the strings there. For some reason GUI elements and things linked with the event handler are the only ones working ... tell me there's something i'm missing, or will i have to link all my functions through the event handler and then raise them this way?
So, how do I scope things in the mod in terms of Game world vs local computer data? And also, saved data vs current session data only (i guess global vs local, but i can't get any of them to work either way)? And how do I access functions from other scopes via the console (ie game.SomeMagicHandler.mymod.DoTheThingThatYouNeedToDo(true) ) ?
And while we're on the subject of scoping, my Gui elements are doing the whole CSS IS AWESOME thing to me.
I don't want elements in a frame to just spill out of it. I mean that's why i "framed" them in the first place

"maximal_width" seems to help in the sense that they are put in the next row, but maximal_height seems to be ignored and they just spill over. It might be that my guielement structures are wrong, but to be honest, I haven't found any useful tutorials on that yet. Is there a handler(guielement) for the debug window (F4)? I'd like to see how it's structured, to get its effects (like resizing to fit window, creating a scrollbar ...).
But for now the scoping thing please.