Page 1 of 1
[solved]Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sat Oct 01, 2016 8:34 am
by Kupferdrache
I am migrating so stuff and used the recommend methode, but I get a wrong script usage anyway.
Code: Select all
61.504 Warning Scenario.cpp:227: Map loading failed during migrations processing: Error while applying migration: Angel's Processing: angelsprocessing_0.2.2.lua
Cannot execute command. Error: Trying to research technology when the game isn't even initialised. (Wrong script usage)
stack traceback:
[string "game.reload_script()
..."]:62: in main chunk
here is the code snippet, that causes the error:
Code: Select all
if force.recipes["ore-processing-plant-2"].enabled then
force.technologies["bio-processing-1"].researched = true
force.technologies["bio-processing-2"].researched = true
end
May be you can help me to fix that thing.
Edit I changed the title, now that I know that z groups messed my save up, I could restrat, but I like my map, and i don't want to rebuild my factory if at all posible.
Re: Need help on debug wrong script usage in migration lua file
Posted: Sat Oct 01, 2016 10:15 am
by aubergine18
Re: Need help on debug wrong script usage in migration lua file
Posted: Sat Oct 01, 2016 7:17 pm
by Kupferdrache
it is in /modfolder/migration/modname_<actual version>.lua The place where it belongs to. As far as i know, as it only has to run once. I shall activate two technologies, that are hidden for some reson. and I can't find the source of the hiding. If I start a new game with all updated mods, the two technoligies are available to research.
Cam somebody point me to a better way to unhide the technolgies? tell me If you need the foll modlist to do that.
Re: Need help on debug wrong script usage in migration lua file
Posted: Sat Oct 01, 2016 7:39 pm
by Nexela
Is that everything in the migration file? If not it might be worth posting the whole contents of the file.
Re: Need help on debug wrong script usage in migration lua file
Posted: Sat Oct 01, 2016 8:38 pm
by Kupferdrache
Here is the complete file:
Code: Select all
game.reload_script()
for index, force in pairs(game.forces) do
force.reset_technologies()
force.reset_recipes()
if force.technologies["bio-processing-1"].researched then
force.recipes["cellulose-fiber-raw-wood"].enabled = true
force.recipes["wood-from-cellulose-resin"].enabled = true
force.recipes["water-mineralized"].enabled = true
end
if force.technologies["ore-processing-2"].researched then
force.recipes["bauxite-ore-processing"].enabled = true
force.recipes["alumina-raw-processed"].enabled = true
force.recipes["cobalt-ore-raw-processing"].enabled = true
force.recipes["cobalt-oxide-raw-processed"].enabled = true
force.recipes["gold-ore-raw-processing"].enabled = true
force.recipes["bob-gold-plate-raw-processed"].enabled = true
force.recipes["lead-oxide-raw-processed"].enabled = true
force.recipes["lead-ore-raw-processing"].enabled = true
force.recipes["lead-plate-raw-processed"].enabled = true
force.recipes["nickel-ore-raw-processing"].enabled = true
force.recipes["bob-nickel-plate-raw-processed"].enabled = true
force.recipes["quartz-raw-processing"].enabled = true
force.recipes["quartz-glass-raw-processed"].enabled = true
force.recipes["bob-silicon-plate-raw-processed"].enabled = true
force.recipes["zinc-ore-raw-processing"].enabled = true
force.recipes["bob-zinc-plate-raw-processed"].enabled = true
end
if force.technologies["ore-processing-3"].researched then
force.recipes["bauxite-processed-raw-smelting"].enabled = true
force.recipes["alumina-raw-ingot"].enabled = true
force.recipes["cobalt-processed-raw-smelting"].enabled = true
force.recipes["cobalt-oxide-raw-ingot"].enabled = true
force.recipes["bob-gold-plate-raw-ingot"].enabled = true
force.recipes["gold-processed-raw-smelting"].enabled = true
force.recipes["lead-oxide-raw-ingot"].enabled = true
force.recipes["lead-processed-raw-smelting"].enabled = true
force.recipes["lead-plate-raw-ingot"].enabled = true
force.recipes["bob-nickel-plate-raw-ingot"].enabled = true
force.recipes["nickel-processed-raw-smelting"].enabled = true
force.recipes["bob-silicon-plate-raw-ingot"].enabled = true
force.recipes["quartz-glass-raw-ingot"].enabled = true
force.recipes["quartz-processed-raw-smelting"].enabled = true
force.recipes["rutile-ore-raw-processing"].enabled = true
force.recipes["bob-titanium-plate-raw-processed"].enabled = true
force.recipes["tungsten-ore-raw-processing"].enabled = true
force.recipes["tungstic-acid-raw-processed"].enabled = true
force.recipes["bob-zinc-plate-raw-ingot"].enabled = true
force.recipes["zinc-processed-raw-smelting"].enabled = true
end
if force.technologies["ore-processing-4"].researched then
force.recipes["bob-titanium-plate-raw-ingot"].enabled = true
force.recipes["rutile-processed-raw-smelting"].enabled = true
force.recipes["tungstic-acid-raw-ingot"].enabled = true
force.recipes["tungsten-processed-raw-smelting"].enabled = true
end
if force.recipes["ore-processing-plant-2"].enabled then
force.technologies["bio-processing-1"].researched = true
force.technologies["bio-processing-2"].researched = true
end
end
You can find the whole mod in the unoffical patches under:
posting.php?mode=reply&f=120&t=33603#pr211519
Re: Need help on debug wrong script usage in migration lua file
Posted: Sun Oct 02, 2016 11:19 am
by Kupferdrache
As this seems to be a cross mod issue in my case I got the Idea to fix it after migration with help of the control.lua. So I write a patch for the mod, the config got changed after world creation, and that presumingly hides the techs, I now want to unhide together with some recipes, that I don't want to be hidden, but I had to figure this setting out while playing, so changing after creation without reseting the map process is nessecary.
Unfornately, the on_configuration_changed() is not so well documented that I can figure out, how to use it for my case.
If you can help me, take a look on my work so far, be warned it is not much yet.
the currend version is now bug free for transition. new features and bug fixes will wander in a 1.2.7 version.
Re: Need help on debug wrong script usage in migration lua file
Posted: Tue Oct 04, 2016 7:05 pm
by Kupferdrache
I found found something in the lua api, but I am not sure how to use it.
Could somebody tell me via exsample if posible, How to us this scripts (situation, synatx, places, limitations)? I am especially interested in use of these in a /migrations/[...].lua or as function of on_configuration_change inside of control.lua .
Code: Select all
class LuaForce
disable_research() Disable research for this force.
enable_research() Enable research for this force.
disable_all_prototypes() Disable all recipes and technologies.
reset_recipes() Load the original version of all recipes from the prototypes. // this seems to be one of the recomended one for migartion scripts to use
enable_all_recipes() Unlock all recipes.
enable_all_technologies() Unlock all technologies.
research_all_technologies() Research all technologies.
reset_technologies() Load the original versions of technologies from prototypes. // this seems to be other one of the migration script ones, that is recomended to use
reset() Reset everything.
I hope with your help I can figure out, how to get access to hidden recipes back, so I can craft them in assemly maschine.
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sat Oct 08, 2016 3:19 pm
by Kupferdrache
Now I know, I should be able to unhide the technologies on update via contraol.lua and a on.config_changed() function. But I still haveb#t figured out what to do excatly. Would be nice, if someone could help me with that part.
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sun Oct 09, 2016 7:19 am
by Nexela
First the primer
http://lua-api.factorio.com/latest/Data-Lifecycle.html
script.on_init() -- Called once, and only once the first time a mod is installed.
script.on_configuration_changed() -- Called every time an mod is added/removed/has_version_changed. EXCEPT on first install when on_init is called in a NEW game
Migration files are only ran ONCE (for each migration file) and are marked as installed internally. I also don't think migrations are run when a mod is added to a new world but I could be wrong.
script.on_configuration_changed would take the exact same syntax as the migration.lua file. just remember that it is ran (once) every time a mod or mods is/are added/removed/updated (including factorio versions)
I don't believe game.reload_script() is needed though
Code: Select all
script.on_configuration_changed(function()
for index, force in pairs(game.forces) do
force.reset_technologies()
force.reset_recipes()
if force.technologies["bio-processing-1"].researched then
force.recipes["cellulose-fiber-raw-wood"].enabled = true
force.recipes["wood-from-cellulose-resin"].enabled = true
force.recipes["water-mineralized"].enabled = true
end
end)
Alternativly you could do: (syntax may not be %100 accurate)
Code: Select all
script.on_configuration_changed(function (data)
if data.mod_changes["name-of-trouble-making-mod-always-re-hiding-stuff"] then
run the for loops code from above here
end
end)
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sun Oct 09, 2016 8:31 am
by Kupferdrache
Thanks for your help, unfortantly your code doesn't work. I get following Error:
[quote=factorio-output]__ZGroupChange__/control.lua:10: unexpected symbol near ')' [/quote]
And i have another issue, it works for recipes, but my problem is missing Technologies.
And yes, i have the Data-Lifecycle open, but i doesn't help me to track down the code to reverse the tech hiding.
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sun Oct 09, 2016 8:57 am
by aubergine18
Do you have a linter installed? If not, it will help you find the syntax errors as you make changes to scripts (much faster than having to keep restarting game over and over):
viewtopic.php?f=34&t=29919
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sun Oct 09, 2016 9:07 am
by Nexela
Add another "end" above one the "ends" (I highly recommend an editor or IDE that supports lua error checking to easily catch stuff like this Zerobrane Studio *FREE* I believe supports error checking out of the box with no complicated windows linter setup)
I guess it depends on What angel is doing to the technologies, If he is just un-enabling them then something like this might work for your technology problem syntax accuracy not guaranteed cause its 5 am here.
script.on_configuration_changed(function ()
for _, force in pairs(game.forces)
force.technologies["TECH-NAME"].enabled=true
--more code here.
end
end)
Still boils down to what exactly Angel is doing and the best course of action may be asking him. or looking through his code.
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sun Oct 09, 2016 9:49 am
by Kupferdrache
I installed ST3 and the linter, it has better syntax highlighting than my normal used editor, but I am not sure if the linter works.
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sun Oct 09, 2016 10:00 am
by Nexela
I believe you have to have Lua and Luacheck installed on your computer. and with ST3 I "think" the base linter app and linter-luacheck or some such.
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sun Oct 09, 2016 10:47 am
by Kupferdrache
I added a check, so it only enables the techs if they are missing, unfortately checking for enabled = false seems not to be posible.
here the currend code:
Code: Select all
--luacheck: globals defines game global script
script.on_configuration_changed(function()
for _, force in pairs(game.forces) do
if force.technologies["bio-processing-1"].disabled then
force.technologies["bio-processing-1"].enabled = true
end
if force.technologies["bio-processing-2"].disabled then
force.technologies["bio-processing-2"].enabled = true
end
if force.technologies["electronics-machine-1"].disabled then
force.technologies["electronics-machine-1"].enabled = true
end
if force.technologies["electronics-machine-2"].disabled then
force.technologies["electronics-machine-2"].enabled = true
end
if force.technologies["electronics-machine-3"].disabled then
force.technologies["electronics-machine-3"].enabled = true
end
end
for _, force in pairs(game.forces) do
force.reset_technologies()
force.reset_recipes()
if force.technologies["alloy-processing-1"].researched then
force.recipes["bronze-pipe"].enabled = true
force.recipes["bronze-pipe-to-ground"].enabled = true
end
if force.technologies["plastics"].researched then
force.recipes["plastic-pipe"].enabled = true
force.recipes["plastic-pipe-to-ground"].enabled = true
end
if force.technologies["zinc-processing"].researched then
force.recipes["bronze-pipe"].enabled = true
force.recipes["bronze-pipe-to-ground"].enabled = true
end
end
end)
Anyone an idea how to make it better? As lua technology doesn't contain the key disabled.
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Sun Oct 09, 2016 11:45 pm
by Nexela
If you check the LuaTechnology API you will notice there is not a .disabled method/var .To check if something is disabled you check if .enabled (a boolean that is R(ead)/(W)rite meaning you can read it and/or change it) is false
if force.techologies["whatever"].enabled = false then --do whatever here end
This is also the same as doing
if not force.technologies["whatever"].enabled then -- not enabled do stuff here end
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Mon Oct 10, 2016 7:35 am
by Kupferdrache
I tested checking for .enabled = false, you can't do it, you get a error on load, but if not should work.
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Mon Oct 10, 2016 8:06 am
by Nexela
Kupferdrache wrote:I tested checking for .enabled = false, you can't do it, you get a error on load, but if not should work.
What exactly is the error?
Re: Help wanted! Unhide a technologie, so it can be researched afterwarts, in existing game
Posted: Mon Oct 10, 2016 7:07 pm
by Kupferdrache
something about, expecting the then after .enabled, if you add the ' = false ' between '.enabled' and 'then'. I don't have the error mesage on hand anymore. But, annding not worked, now I can undate the unoffical mods, for thatversion a last time, as there shold be no critial errors remaining for other to try out.