Page 1 of 1

[0.3.0] Simple Questions

Posted: Sat Mar 30, 2013 12:58 am
by FreeER
Ilnor asked for a bike mod (for early transport) so I was going to make one, but it's having issue right now
it shows in mod-list but it has no research and I tried

Code: Select all

game.getplayer().character.insert{name="ilbike",count=1}
but it says that ilbike does not exist.

For now if you want to tell me what is wrong with it: https://www.dropbox.com/s/ys4en9oydr7lm6u/Ilbike.zip

I WILL place this in the actual mod forum this when it is working and when it has better graphics. I intend to do a few more things with it but until I can at least get it working....

edit: It looks like factorio isn't actually loading the mod...it sees that it is there but it doesn't load it. I moved the content into base (after creating a backup) and it sees it fine. Right now I have part of the mod as __base__ when i should be __Ilbike__ and it doesn't error out about not finding files...

Re: [0.3.0]

Posted: Sat Mar 30, 2013 9:08 am
by slpwnd
I played around with your mod and found the way how to fix it. The problem was in the data.lua file. I have replaced the original one with the following:

Code: Select all

require("prototypes.entity.entities")
require("prototypes.item.item")
require("prototypes.recipe.recipe")
require("prototypes.technology.technology")
Mod manager adds the absolute path to the mod into the package path so only the relative paths are necessary. You can see the package path yourself by simply putting the following code into the data.lua:

Code: Select all

print(package.path)
In the base mod I have used slashes in the require paths and for some (to me strange) reason that worked well. However the proper way in Lua is to use the dots to separate the parts in the package path. When I used slashes in your mod it didn't work. Not sure why that is because it worked for me in the lua console though. Probably some 1s and 0s magic.

Anyway remember that this is a full fledged programming language (not just json data files). Therefore it gives you tools to figure what the problem is. Basically what I did is that I put a simple print statement into the entities.lua file:

Code: Select all

print("Hello world")
After this I immediately saw that it wasn't imported. Then I kept playing around with the require path till it worked.

Also keeping the tree structure for the prototypes from the base mod is not necessary. You can simply put all the definitions into the data.lua file (yes you can mix the definitions of items, entities, etc. the data:extend function will sort them out). Actually for smaller mods this is even the preffered way. In base we have kept the directory structure because there are is so much data.

One last note. Using pcall is not a good idea. I am to blame for using it in the base/data.lua though :) The reason it is used there is not to give errors in the demo when those files are not present. Basically the following call will not complain when it can't find the "xxx" package:

Code: Select all

pcall(require, "xxx")
This is not the case for the mods. Som simple way with require is much better (as it gives you errors when it doesn't find the package).

Apart from that there was a small fix needed in technology.lua where time field was outside of the unit scope.

Re: [0.3.0]

Posted: Sat Mar 30, 2013 9:31 am
by drs9999
Hello,
just 2 quick questions:

Where I have to place the control.lua? In the root-mod-folder?
And if a mod uses a control.lua I have to add the file to the data.lua, right?

Re: [0.3.0]

Posted: Sat Mar 30, 2013 9:59 am
by slpwnd
1) Yes control.lua is placed in the root mod folder. So something like mods/foo/control.lua.
2) The data.lua is only for prototype objects. The control.lua is loaded automatically independent of what is in the data.lua.
You can do a simple test with following control.lua:

Code: Select all

require "defines"

game.onevent(defines.events.ontick, function(event)
  if event.tick % 100 == 0 then
    game.player.print("Hello from the mod.")
  end
end)

Re: [0.3.0]

Posted: Sat Mar 30, 2013 8:24 pm
by FreeER
slpwnd wrote:I played around with your mod and found the way how to fix it. The problem was in the data.lua file. I have replaced the original one with the following:

Code: Select all

require("prototypes.entity.entities")
require("prototypes.item.item")
require("prototypes.recipe.recipe")
require("prototypes.technology.technology")
Mod manager adds the absolute path to the mod into the package path so only the relative paths are necessary.
Apart from that there was a small fix needed in technology.lua where time field was outside of the unit scope.
Thank you, a lot. Since I'd copied pretty much everything, especially the data.lua I couldn't figure out what the problem was. It seems obvious now lol, I know that lua uses the . separator for packages but I never thought to try it. I tried several ways (except the proper one of course) before I posted and was starting to get pissed off as to why I couldn't figure it out :lol:
slpwnd wrote:Also keeping the tree structure for the prototypes from the base mod is not necessary.
While it may not be necessary I definitely prefer the organized structure myself, I may not be OCD but I absolutely do not want to be scrolling through a file trying to find where I placed something lol. Plus it makes it easier when you expand upon a mod

Re: [0.3.0] Simple Questions

Posted: Sat Mar 30, 2013 8:46 pm
by ficolas
Can you add GUI documentation to the wiki? Im so excited about that feature :)