Resizing Map Macros

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Glen
Posts: 70
Joined: August 20th, 2011, 10:59 pm

Resizing Map Macros

Post by Glen »

I found Jamit's Resizing Map Macros and attempted to make use of them in my Armageddon scenario.
viewtopic.php?p=522048#p522048

I followed his setup steps listed but I've run into errors using them in my scenario in game.
Most of the macros work fine except for the RESIZED_MAP_REPLACE macro that replaces current map with a new map.

This is the error I got

Code: Select all

<Lua error> ~addons/Lava_Duel/lua/replace_map.lua:54:invalid value(nil) at index 1 in table for "concat" stack traceback
The lua file used is the exact same as the one in the legend of wesmere campaign lua folder called wml_tags.cfg. Not too well acquainted with LUA so I'm not really understanding what is wrong here.

Replace_map Lua straight from legend of wesmere campaign folder here

Code: Select all

--! #textdomain wesnoth-low

local labels = {}
local wml_label = wesnoth.wml_actions.label
local replace_map = wesnoth.wml_actions.replace_map

local wml_actions = wesnoth.wml_actions
local T = wml.tag
local vars = wml.variables

helper = wesnoth.require "lua/helper.lua"

function wesnoth.wml_actions.shift_labels(cfg)
	for k, v in ipairs(labels) do
		wml_label { x = v.x, y = v.y }
	end
	for k, v in ipairs(labels) do
		v.x = v.x + cfg.x
		v.y = v.y + cfg.y
		wml_label(v)
	end
end

--
-- Overrides of core tags
--

function wesnoth.wml_actions.label(cfg)
	table.insert(labels, cfg.__parsed)
	wml_label(cfg)
end

function wesnoth.wml_actions.replace_map(cfg)
	if not cfg.x and not cfg.y then
		return replace_map(cfg)
	end
	local x1,x2 = string.match(cfg.x, "(%d+)-(%d+)")
	local y1,y2 = string.match(cfg.y, "(%d+)-(%d+)")
	local map = cfg.map_data
	x1 = tonumber(x1)
	y1 = tonumber(y1)
	x2 = x2 + 2
	y2 = y2 + 2
	local t = {}
	local y = 1
	for row in string.gmatch(map, "[^\n]+") do
		if y >= y1 and y <= y2 then
			local r = {}
			local x = 1
			for tile in string.gmatch(row, "[^,]+") do
				if x >= x1 and x <= x2 then r[x - x1 + 1] = tile end
				x = x + 1
			end
			t[y - y1 + 1] = table.concat(r, ',')
		end
		y = y + 1
	end
	local new_map = table.concat(t, '\n')
	replace_map { map = new_map, expand = true, shrink = true }
end
Here is how I attempted to use RESIZED_MAP_REPLACE(this produces error)

Code: Select all

[event]
name = turn 6
first_time_only=no
{RESIZED_MAP_REPLACE (~add-ons/Lava_Duel/maps/turn2.map) }
Last edited by Pentarctagon on April 17th, 2020, 3:49 am, edited 1 time in total.
Reason: use [code]

User avatar
Ravana
Forum Moderator
Posts: 2440
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Resizing Map Macros

Post by Ravana »

What is your goal?

User avatar
Glen
Posts: 70
Joined: August 20th, 2011, 10:59 pm

Re: Resizing Map Macros

Post by Glen »

My armageddon map has spreading lava every turn. This bloats the map with unused lava near the middle to end of the game with lots of unused area compared to the small playing field in middle. I was going to use these macros to resize the map. The problem is since lava is spreading the map itself has changed from its original state so i cant use the GROW_MAP or RESIZE_MAP macros for my purposes or it goes back to the original map state before lava has spread.
So I wanted to use the RESIZED_MAP_REPLACE to replace the current map with a new map file with the current state of the map and then I would use GROW_MAP to shrink the map how I wanted. The LUA used in this macro is giving me errors.

User avatar
Celtic_Minstrel
Developer
Posts: 1654
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Resizing Map Macros

Post by Celtic_Minstrel »

Just noting, when you post code you should enclose it in [code]...[/code] tags.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

Post Reply