Currently Online

Latest Posts

Topic: Scrtipting trouble infrastructure.lua

Lokimaros
Avatar
Joined: 2016-10-21, 17:51
Posts: 49
Ranking
Pry about Widelands
Location: Leiden, the Netherlands
Posted at: 2017-01-04, 14:30

To do a specific test I've made a simple map with a script to set up the intended starting conditions: a headquarters, with a lumberjack-range size forest to the east and a single lumberjack in the centre, with a connecting road. That's the goal.

Curerntly it crashes with:
Message: adding warehouse for player 1 at (11, 23)
Fatal exception: lua: [../src/scripting/lua_errors.cc:22] [string "scripting/infrastructure.lua"]:94: bad argument #1 to 'get_field' (number expected, got nil)

The full inti.lua is listed below: [code] include "scripting/infrastructure.lua"

local game=wl.Game()
local map = game.map
local plr = wl.Game().players[1]

-- reveal the whole map for every player
local fields = {}
local i = 1
for x=0, map.width-1 do
for y=0, map.height-1 do
fields[i] = map:get_field(x,y)
i = i + 1
end
end
plr:reveal_fields(fields)

local sf = map.player_slots[1].starting_field

prefilled_buildings(plr, { "barbarians_headquarters", sf.x, sf.y,
wares = {
ax = 5,
bread_paddle = 2,
blackwood = 32,
cloth = 5,
coal = 12,
felling_ax = 4,
fire_tongs = 2,
fish = 6,
fishing_rod = 2,
gold = 4,
grout = 12,
hammer = 12,
hunting_spear = 2,
iron = 12,
iron_ore = 5,
kitchen_tools = 4,
meal = 4,
meat = 6,
pick = 14,
barbarians_bread = 8,
ration = 12,
granite = 40,
scythe = 6,
shovel = 4,
snack = 3,
thatch_reed = 24,
log = 80,
},
workers = {
barbarians_blacksmith = 2,
barbarians_brewer = 1,
barbarians_builder = 10,
barbarians_carrier = 40,
barbarians_charcoal_burner = 1,
barbarians_gardener = 1,
barbarians_geologist = 4,
barbarians_lime_burner = 1,
barbarians_lumberjack = 3,
barbarians_miner = 4,
barbarians_ranger = 1,
barbarians_stonemason = 2,
barbarians_ox = 5,
},
soldiers = {
[{0,0,0,0}] = 45,
}
})

prefilled_buildings(plr, "barbarians_lumberjacks_hut", 24, 24)
plr:conquer(map:get_field(24, 24), 20)

sf = map.player_slots[1].starting_field
connect_road(plr, sf, "se,e|e,e|e,e|e,e|e,e|e,e|e,e")
[/code]


Top Quote
Lokimaros
Avatar
Joined: 2016-10-21, 17:51
Posts: 49
Ranking
Pry about Widelands
Location: Leiden, the Netherlands
Posted at: 2017-01-04, 15:27

Upon reflection, it's not the connect_road that fails, of course, but the prefilled_building of the lumberjack, but I still don't see what the error in my using it is. I've already moved the conquer to precede it, in case land ownership was the problem, but the result is exactly the same.


Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 1857
Ranking
One Elder of Players
Location: Germany
Posted at: 2017-01-04, 15:54

Compare the first prefilled_buildings function and the one which causes the error:

prefilled_buildings(plr, { "barbarians_headquarters", sf.x, sf.y,
[...]
})

and the second:

prefilled_buildings(plr, "barbarians_lumberjacks_hut", 24, 24)

Try to add curly braces to it:

prefilled_buildings(plr, {"barbarians_lumberjacks_hut", 24, 24})

And be aware that a flag of a building is not at the same spot as the building is.


Top Quote
Lokimaros
Avatar
Joined: 2016-10-21, 17:51
Posts: 49
Ranking
Pry about Widelands
Location: Leiden, the Netherlands
Posted at: 2017-01-04, 16:52

Doing! Well, grate my skin and bake me for 197 minutes, I should have seen that!

As for the starting point, I had that right originally, but a previous error made me think I might have the wrong spot. Corrected back, now, and with a further correction of connect_road to connected_road, and eliminating one 'e', (e,e|e,e into e,e,e), it works as intended, yay! My slumberjack is happily hacking away at his wood, and results will be posted in about 4 hours.


Top Quote