Page 1 of 1

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

Posted: Sat Nov 12, 2016 10:30 pm
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.

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

Posted: Sat Nov 12, 2016 10:43 pm
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.

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

Posted: Sat Nov 12, 2016 11:05 pm
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.

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

Posted: Sat Nov 12, 2016 11:07 pm
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.",

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

Posted: Sat Nov 12, 2016 11:29 pm
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. :)

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

Posted: Sun Nov 13, 2016 12:00 am
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.

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

Posted: Sun Nov 13, 2016 7:49 am
by prg
Remove the 'require "defines"' at the beginning. It's available automatically now.

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

Posted: Sun Nov 13, 2016 11:28 am
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)

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

Posted: Sun Nov 13, 2016 3:23 pm
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.

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

Posted: Sun Nov 13, 2016 3:34 pm
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. :)

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

Posted: Sun Nov 13, 2016 3:54 pm
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)

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

Posted: Sun Nov 13, 2016 4:02 pm
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)

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

Posted: Sun Nov 13, 2016 4:06 pm
by Pippaf1
Close now the error is:

__DriveAssist__/control.lua:2: unexpected symbol near char(160)

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

Posted: Sun Nov 13, 2016 4:29 pm
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