How to make a 12.x mod work on a 13.x game

Place to get help with not working mods / modding interface.
Post Reply
Pippaf1
Inserter
Inserter
Posts: 31
Joined: Sun Apr 26, 2015 11:37 pm
Contact:

How to make a 12.x mod work on a 13.x game

Post by Pippaf1 »

I have a mod that I have been able to keep working all though to 12.x but I can't seem to find a way to transfer it to 13.x and onward.

I am hopping there is just a small coding change like the other changes I have done. Is this the case? If so what is the change needed?

For clarity the mod considered is Drive Assist originally authored by Turtle. I do not claim any ownership of the original or modified code.
Philippa
Transport Belt Repair Engineer

Watch what you wish for. You may just get it.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by aubergine18 »

For most mods it's just a case of updating the info.json file to include factorio_version. Open up one of the 0.14 mods from the portal and you can see examples. Try that and if it doesn't work, report back with error messages.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Pippaf1
Inserter
Inserter
Posts: 31
Joined: Sun Apr 26, 2015 11:37 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by Pippaf1 »

Hi Thank you for the reply. I tried the modification you suggested but I just got the following message:
--------------------------
Error
---------------------------
JSON parser error in package metadata: C:/Users/Hal/AppData/Roaming/Factorio/mods/DriveAssist_1.0.0/info.json(9): expected '}' or ','
---------------------------
OK
---------------------------
I think the file considered is as follows:
{
"name": "DriveAssist",
"version": "1.0",
"title": "DriveAssist",
"author": "Turtle",
"contact": "",
"homepage": "https://forums.factorio.com/forum/vie ... =14&t=6232",
"description": "Points your vehicle north, east, south or west as desired."
"factorio_version": "0.13"
}

I hope this helps. Again thanks for your help.
Philippa
Transport Belt Repair Engineer

Watch what you wish for. You may just get it.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by aubergine18 »

Put a comma at end of this line:

"description": "Points your vehicle north, east, south or west as desired."

should be

"description": "Points your vehicle north, east, south or west as desired.",
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Pippaf1
Inserter
Inserter
Posts: 31
Joined: Sun Apr 26, 2015 11:37 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by Pippaf1 »

Ok that seems to work now but with new game I get this error code:

_DriveAssist__/control.lua:1: module defines not found; no such file __DriveAssist__/defines.lua no such file __DriveAssist__/defines.lua no such file C:/Program Files/Factorio/data/core/lualib/defines.lua

Never seems to end. :)
Philippa
Transport Belt Repair Engineer

Watch what you wish for. You may just get it.

Pippaf1
Inserter
Inserter
Posts: 31
Joined: Sun Apr 26, 2015 11:37 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by Pippaf1 »

Thinking on It might be helpful if I posted the lua file so please see below:

require "defines"

script.on_event(defines.events.on_tick, function(event)
if game.tick%20 == 0 then
if game.player.vehicle and game.player.vehicle.valid and game.player.vehicle.type == "car" then
if game.player.gui.left.frameDA == nil then
frameDA = game.player.gui.left.add{type = "frame", name = "frameDA", direction = "horizontal"}
local tab = frameDA.add{type ="table", name = "tableDA", colspan = 3}
tab.add{type = "button", name = "buttonDANorthWest", caption = "NW"}
tab.add{type = "button", name = "buttonDANorth", caption = "N"}
tab.add{type = "button", name = "buttonDANorthEast", caption = "NE"}
tab.add{type = "button", name = "buttonDAWest", caption = "W"}
tab.add{type = "label", name = "DAblank4", caption = " "}
tab.add{type = "button", name = "buttonDAEast", caption = "E"}
tab.add{type = "button", name = "buttonDASouthWest", caption = "SW"}
tab.add{type = "button", name = "buttonDASouth", caption = "S"}
tab.add{type = "button", name = "buttonDASouthEast", caption = "SE"}
end
elseif game.player.gui.left.frameDA then
game.player.gui.left.frameDA.destroy()
end
end
end)

script.on_event(defines.events.on_gui_click, function(event)
if event.element.name == "buttonDANorth" then
game.player.vehicle.orientation = 0.0
-- game.player.print("North")
elseif event.element.name == "buttonDANorthWest" then
game.player.vehicle.orientation = 0.875
-- game.player.print("NorthWest")
elseif event.element.name == "buttonDAWest" then
game.player.vehicle.orientation = 0.75
-- game.player.print("West")
elseif event.element.name == "buttonDASouthWest" then
game.player.vehicle.orientation = 0.625
-- game.player.print("SouthWest")
elseif event.element.name == "buttonDASouth" then
game.player.vehicle.orientation = 0.5
-- game.player.print("South")
elseif event.element.name == "buttonDASouthEast" then
game.player.vehicle.orientation = 0.375
-- game.player.print("SouthEast")
elseif event.element.name == "buttonDAEast" then
game.player.vehicle.orientation = 0.25
-- game.player.print("East")
elseif event.element.name == "buttonDANorthEast" then
game.player.vehicle.orientation = 0.125
-- game.player.print("West")
-- else
-- game.player.print(event.element.name or "Element missing name!")
end
end)


I hope this clarifies matters.
Philippa
Transport Belt Repair Engineer

Watch what you wish for. You may just get it.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by prg »

Remove the 'require "defines"' at the beginning. It's available automatically now.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Pippaf1
Inserter
Inserter
Posts: 31
Joined: Sun Apr 26, 2015 11:37 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by Pippaf1 »

Ok done but would you belive it I have a new message, as follows:

Error while running the event handler: __DriveAssist__/control.lua:3: attempt to index field 'player' (a nil value)
Philippa
Transport Belt Repair Engineer

Watch what you wish for. You may just get it.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by prg »

You might want to handle the GUI creation/destruction in response to an on_player_driving_changed_state event, which comes with a player_index. You also need to use the player_index in the on_gui_click event handler.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Pippaf1
Inserter
Inserter
Posts: 31
Joined: Sun Apr 26, 2015 11:37 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by Pippaf1 »

Sorry I am very new to this, so i have no idea what you just said. I'm afraid i need the idiots version. :)
Philippa
Transport Belt Repair Engineer

Watch what you wish for. You may just get it.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by Klonan »

Pippaf1 wrote:Sorry I am very new to this, so i have no idea what you just said. I'm afraid i need the idiots version. :)
This should work

Code: Select all

script.on_event(defines.events.on_tick, function(event)
  if game.tick%20 ~= 0 then return end
  for k, player in pairs (game.connected_players) do
    check(player)
  end
end)

function check(player)
  if player.vehicle and player.vehicle.valid and player.vehicle.type == "car" then
    if player.gui.left.frameDA == nil then
      frameDA = player.gui.left.add{type = "frame", name = "frameDA", direction = "horizontal"}
      local tab = frameDA.add{type ="table", name = "tableDA", colspan = 3}
      tab.add{type = "button", name = "buttonDANorthWest", caption = "NW"}
      tab.add{type = "button", name = "buttonDANorth", caption = "N"}
      tab.add{type = "button", name = "buttonDANorthEast", caption = "NE"}
      tab.add{type = "button", name = "buttonDAWest", caption = "W"}
      tab.add{type = "label", name = "DAblank4", caption = " "}
      tab.add{type = "button", name = "buttonDAEast", caption = "E"}
      tab.add{type = "button", name = "buttonDASouthWest", caption = "SW"}
      tab.add{type = "button", name = "buttonDASouth", caption = "S"}
      tab.add{type = "button", name = "buttonDASouthEast", caption = "SE"}
    end
  elseif player.gui.left.frameDA then
    player.gui.left.frameDA.destroy()
  end
end

script.on_event(defines.events.on_gui_click, function(event)

  local player = game.players[event.player_index]
  local gui = event.element.name
  
  if gui== "buttonDANorth" then
    game.player.vehicle.orientation = 0.0
  elseif gui== "buttonDANorthWest" then
    game.player.vehicle.orientation = 0.875
  elseif gui== "buttonDAWest" then
    game.player.vehicle.orientation = 0.75
  elseif gui== "buttonDASouthWest" then
    game.player.vehicle.orientation = 0.625
  elseif gui== "buttonDASouth" then
    game.player.vehicle.orientation = 0.5
  elseif gui== "buttonDASouthEast" then
    game.player.vehicle.orientation = 0.375
  elseif gui== "buttonDAEast" then
    game.player.vehicle.orientation = 0.25
  elseif gui== "buttonDANorthEast" then
    game.player.vehicle.orientation = 0.125
  end
  
end)

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by prg »

No need for on_tick.

Code: Select all

script.on_event(defines.events.on_player_driving_changed_state, function(event)
    local player = game.players[event.player_index]
    if player.vehicle and player.vehicle.valid and player.vehicle.type == "car" then
        if player.gui.left.frameDA == nil then
            local frameDA = player.gui.left.add{type = "frame", name = "frameDA", direction = "horizontal"}
            local tab = frameDA.add{type ="table", name = "tableDA", colspan = 3}
            tab.add{type = "button", name = "buttonDANorthWest", caption = "NW"}
            tab.add{type = "button", name = "buttonDANorth", caption = "N"}
            tab.add{type = "button", name = "buttonDANorthEast", caption = "NE"}
            tab.add{type = "button", name = "buttonDAWest", caption = "W"}
            tab.add{type = "label", name = "DAblank4", caption = " "}
            tab.add{type = "button", name = "buttonDAEast", caption = "E"}
            tab.add{type = "button", name = "buttonDASouthWest", caption = "SW"}
            tab.add{type = "button", name = "buttonDASouth", caption = "S"}
            tab.add{type = "button", name = "buttonDASouthEast", caption = "SE"}
        end
    elseif player.gui.left.frameDA then
        player.gui.left.frameDA.destroy()
    end
end)

script.on_event(defines.events.on_gui_click, function(event)
    local player = game.players[event.player_index]
    if event.element.name == "buttonDANorth" then
        player.vehicle.orientation = 0.0
    elseif event.element.name == "buttonDANorthWest" then
        player.vehicle.orientation = 0.875
    elseif event.element.name == "buttonDAWest" then
        player.vehicle.orientation = 0.75
    elseif event.element.name == "buttonDASouthWest" then
        player.vehicle.orientation = 0.625
    elseif event.element.name == "buttonDASouth" then
        player.vehicle.orientation = 0.5
    elseif event.element.name == "buttonDASouthEast" then
        player.vehicle.orientation = 0.375
    elseif event.element.name == "buttonDAEast" then
        player.vehicle.orientation = 0.25
    elseif event.element.name == "buttonDANorthEast" then
        player.vehicle.orientation = 0.125
    end
end)
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Pippaf1
Inserter
Inserter
Posts: 31
Joined: Sun Apr 26, 2015 11:37 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by Pippaf1 »

Close now the error is:

__DriveAssist__/control.lua:2: unexpected symbol near char(160)
Philippa
Transport Belt Repair Engineer

Watch what you wish for. You may just get it.

Pippaf1
Inserter
Inserter
Posts: 31
Joined: Sun Apr 26, 2015 11:37 pm
Contact:

Re: How to make a 12.x mod work on a 13.x game

Post by Pippaf1 »

Well this error was on my end and has been solved. Just got to game test now as this will take some time, I will post the results hear as I get them.

Thank you so much for your help. All the best. :D
Philippa
Transport Belt Repair Engineer

Watch what you wish for. You may just get it.

Post Reply

Return to “Modding help”