Page 1 of 1

Failing to edit player force

Posted: Wed Apr 04, 2018 5:05 pm
by Puma
What I'm trying to do is essetially the following during map creation on a headless server.

Code: Select all

game.forces["player"].manual_crafting_speed_modifier=-0.9
I can get the mod I made to load without error, but it doesn't do what I want it to do. The "player" force manual_crafting_speed_modifier remains zero. And when a new player logs on to the server they are able to craft with the default speed.

I have rewritten the mod multiple times, tried copying what other modders have done, tried triggering the command at different times using different event triggers, but nothing has worked and I don't understand what I'm doing wrong. And it doesn't help that I'm unable to print any debugging info on the headless console.

Re: Failing to edit player force

Posted: Wed Apr 04, 2018 6:51 pm
by eradicator
I think that's a multiplicative modifier and thus negative values are invalid. You can't have a crafting time of "minus one second". If you want to make crafting ten times slower try 0.1 instead.

Re: Failing to edit player force

Posted: Wed Apr 04, 2018 11:44 pm
by Puma
eradicator wrote:I think that's a multiplicative modifier and thus negative values are invalid. You can't have a crafting time of "minus one second". If you want to make crafting ten times slower try 0.1 instead.
No, you misunderstood. The default value of manual_crafting_speed_modifier is zero. And I can't get the mod to change it away from the default. The value I'm trying to change it to is right, but I just can't change the variable away from zero. (But I tried with a positive value, and still no change.)

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 1:58 am
by Nexela
Without your code we cant be of much help. Setting manual_crafting_speed_modifier to -0.9 works for me

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 8:01 am
by Puma
My current iteration of control.lua looks like this

Code: Select all

script.on_event({defines.events.on_tick}, function(e)
        if e.tick == 1 then
                game.forces["player"].manual_crafting_speed_modifier = -0.9
        end
end)
I was thingking that maybe it would work if the code got called after map creation. Maybe the code was getting called before the forces were created. But alas this doesn't work either.

But if it works for you then I can only assume that the line of code isn't getting called. Is there a easy way I can input debugging information to the headless server console during map creation? Just to see if any of my code is actually being run.

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 8:38 am
by betrok
Works for me. Btw ticks start at 0 and you can just use game.on_init().
Puma wrote:Is there a easy way I can input debugging information to the headless server console during map creation?
Yep, it is literally log()

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 9:55 am
by Puma
Thanks. That helped. Now I'm under the impression that my mod simply isn't being run at all. And I don't understand why.

In my /mods/ directory I have the following entries:

CraftNerf90_1.0.0/
mod-list.json

The mod-list.json contains the following:

Code: Select all

{
  "mods": [
    {
      "name": "base",
      "enabled": true
    },
    {
      "name": "CraftNerf90",
      "enabled": true
    }
  ]
}
The CraftNerf90_1.0.0/ directory contains the following files with following content:

info.json

Code: Select all

{
    "name": "CraftNerf90",
    "version": "1.0.0",
    "title": "CraftNerf90",
    "author": "Puma",
    "contact": "",
    "homepage": "",
    "factorio_version": "0.15",
    "dependencies": ["base >= 0.15"],
    "description": "Pocket crafting speed -90% for the player force."
}
control.lua

Code: Select all

log('DEBUG !!!! TEST !!!!! HOX !!!')
print('MORE DEBUGGING !!!!!!! HOX HOX !!!!!!')
script.on_init( function()
        game.forces["player"].manual_crafting_speed_modifier = -0.9
end)
Yet on map creation the debugging info is not printed on the console. For what I can tell I'm doing everything exactly the same as other mods I have inspected.

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 10:13 am
by eradicator
Is your mod shown as enabled (white) in the in-game mod menu? If yes, it is enabled. If no, it is not. If it doesn't show up at all your info.json has broken formatting.

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 10:31 am
by Puma
eradicator, no, you don't understand. I'm running the headless server. There is no menu. Only the console output. That's why I was asking about the console debugging earlier. And also I'm trying to get this to happen ideally during map creation. Before the server starts. So the mod doesn't need to stay active after it has changed the value of that one variable.

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 1:12 pm
by betrok
If something is really wrong with mods, server does not start at all. After loading of your mod log should contain something like

Code: Select all

   0.322 Checksum for script __CraftNerf90__/control.lua: 3210040014   
Attach you logs, lets check them.

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 1:38 pm
by Bilka
Your mod does not work in 0.16 because the factorio version is set to 0.15.

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 3:46 pm
by Puma
Edit:
I changed the version in info.json to "0.16". And now it prints the debugging lines. Thanks. I failed to understand what that field means. I taught it was "minimum required version".

So version update of the game "breaks" all mods?

Edit2:
Everything works perfectly now. This has been such a frustrating experience. Thanks for the help. You saved my sanity.

Edit3:
Also... hey devs, if the game refuses to load a mod because of version mismatch, I feel like an error message in the log wouldn't be unreasonable thing to ask.

Edit4:
apparently log() does nothing. print() prints to the console output, but log() doesn't print to the console nor the log.

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 7:26 pm
by eradicator
Puma wrote:eradicator, no, you don't understand. I'm running the headless server. There is no menu. Only the console output. That's why I was asking about the console debugging earlier. And also I'm trying to get this to happen ideally during map creation. Before the server starts. So the mod doesn't need to stay active after it has changed the value of that one variable.
Sorry, kinda difficult to keep track of all those threads at once :P. Didn't realize you're on headless. Which might also then be the reason log() doesn't work, as it works fine if you attach a console to the normal client. Also i simply assumed you _wanted_ to have 0.15, which is why i didn't mention that :x. I definetly agree that there should be more verbose errors when mods fail to load. Currently all mod loading that fails due to anything related to info.json simply results in the mod being ignored.

Glad you worked it out though.

Re: Failing to edit player force

Posted: Thu Apr 05, 2018 10:38 pm
by Nexela
Also the event you want to use is on_init to set the value initially.

script.on_init(function(e) blah end)

log outputs to the log file
print outputs to the console