How to load a map from an array of variables?
Moderator: Forum Moderators
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.
- PapaSmurfReloaded
- Posts: 822
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
How to load a map from an array of variables?
Here is the thing, I want to save the terrains of the entire map, to be able to load it eventually.
How does it work? First I have to save the map using [store_locations], but then how do I load the entire map using [terrain]?
How does it work? First I have to save the map using [store_locations], but then how do I load the entire map using [terrain]?
Re: How to load a map from an array of variables?
Do you mean "load" as in "the scenario is already running, I've covered half the map with lava, now I want to change those hexes back to what they originally were"?
(Note: cut, modified and pasted without checking that I didn't break anything)
Code: Select all
{FOREACH original i}
{MODIFY_TERRAIN $original[$i].terrain $original[$i].x $original[$i].y}
{NEXT i}
{CLEAR_VARIABLE i}
[redraw][/redraw]
Re: How to load a map from an array of variables?
Although, better use [foreach] or [for], as {FOREACH} is deprecated by them.
Try out the dark board theme.
- PapaSmurfReloaded
- Posts: 822
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
Re: How to load a map from an array of variables?
Yep, to be exact what I am doing working on the ARRPGA, allowing the DM to change the seasons of the map. As well adding an option to return the map to what it originally looked like(since it might have terrains which correspond to different "seasons".octalot wrote: ↑June 18th, 2018, 4:32 pm Do you mean "load" as in "the scenario is already running, I've covered half the map with lava, now I want to change those hexes back to what they originally were"?
(Note: cut, modified and pasted without checking that I didn't break anything)Code: Select all
{FOREACH original i} {MODIFY_TERRAIN $original[$i].terrain $original[$i].x $original[$i].y} {NEXT i} {CLEAR_VARIABLE i} [redraw][/redraw]
Edit: Works perfectly, thank you a million.
Re: How to load a map from an array of variables?
If the map is at all large, then saving the map using nothing but [store_locations] would naturally create a gigantic array. You could avoid that by iterating through the columns and rows of the map and constructing a proper map data string that you could later apply using [terrain_mask] [replace_map], but obviously that's more complicated to write.
Re: How to load a map from an array of variables?
If you just wanted to use seasons, in some cases it could be useful and more efficient or fast to just do something like this:PapaSmurfReloaded wrote: ↑June 18th, 2018, 5:28 pm Yep, to be exact what I am doing working on the ARRPGA, allowing the DM to change the seasons of the map. As well adding an option to return the map to what it originally looked like(since it might have terrains which correspond to different "seasons".
Code: Select all
[terrain]
terrain=Kha
[and]
terrain=Kh
[/and]
[/terrain]
And then reverse them... when needed.
Same way:
Code: Select all
[terrain]
terrain=Ai
[and]
terrain=W*,W*^*
[/and]
[/terrain]
But of course to make it look nicer it's better change every tile manually... but some areas you probably could automate.. limiting the x, y area..
in which case it may be a bit of a slow lag to replace the terrains, but not necessarily.. However if it's slow you could convert the WML code into lua and make it run much faster, because lua
for
cycle is much faster than wml cycle. So you could store locations in WML as normal (as in octalot example I used "original" as an array variable name), but then instead of WML [foreach]
do something like this:
Code: Select all
[lua]
code = <<
for i=0,wesnoth.get_variable("original.length")-1,1 do
local current_hex_x = wesnoth.get_variable("original["..tostring(i).."].x")
local current_hex_y = wesnoth.get_variable("original["..tostring(i).."].y")
local current_hex_terrain = wesnoth.get_variable("original["..tostring(i).."].terrain")
wesnoth.set_terrain(tonumber(current_hex_x), tonumber(current_hex_y), current_hex_terrain)
end
>>
[/lua]
if it doesn't work let me know...
- PapaSmurfReloaded
- Posts: 822
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
Re: How to load a map from an array of variables?
The feature is currently added to ARRPGA.
It doesn't take that long to change the hexes of the entire map (three second max I believe) and ARRPGA uses pretty big maps in general, along the lines of 100 x 100. It isn't a feature that is supposed to be used often that I find it alright. The idea is to allow the DM to be able to add some more flavor to the setting of the story.
As for the replacement, it works as desired. Of course not every maps looks well with changing seasons (like those with "pre-set seasons" like Northern Mountains which is a winter environment. the Desert of Doom which is a dry sand desert (duh). or the tropical Lost Island.
But for mostly greenish maps like Wesnoth, the Far North, the Green Isle, it works fine.
The only issues is with reefs being replaced by ice in Winter(technically the issue is that I don't have anything better to change it into, ice covered by debris looks bad xD) but I find it quite irrelevant.
It doesn't take that long to change the hexes of the entire map (three second max I believe) and ARRPGA uses pretty big maps in general, along the lines of 100 x 100. It isn't a feature that is supposed to be used often that I find it alright. The idea is to allow the DM to be able to add some more flavor to the setting of the story.
As for the replacement, it works as desired. Of course not every maps looks well with changing seasons (like those with "pre-set seasons" like Northern Mountains which is a winter environment. the Desert of Doom which is a dry sand desert (duh). or the tropical Lost Island.
But for mostly greenish maps like Wesnoth, the Far North, the Green Isle, it works fine.
The only issues is with reefs being replaced by ice in Winter(technically the issue is that I don't have anything better to change it into, ice covered by debris looks bad xD) but I find it quite irrelevant.
Re: How to load a map from an array of variables?
For me I think 3 seconds is quite long, and keep in mind that maybe on your computer it is 3 seconds, but on some old computer it could be 10 And it would look like a big lag/freeze, not something with a nice image saying "loading please wait"PapaSmurfReloaded wrote: ↑June 19th, 2018, 2:28 pm It doesn't take that long to change the hexes of the entire map (three second max I believe)
I would try to add my lua code to check on difference (I already wrote it so that it will be 100% compatible with octalot WML example), but of course it's up to you.
Well yeah I dont think its so extremely important to change reefs into proper ice reefs, but while Ai^Es doesn't look too bad at all you could always add [item] with image like "terrain/water/reef2.png" like so:PapaSmurfReloaded wrote: ↑June 19th, 2018, 2:28 pm The only issues is with reefs being replaced by ice in Winter(technically the issue is that I don't have anything better to change it into, ice covered by debris looks bad xD) but I find it quite irrelevant.
Code: Select all
[item]
x,y=25,28
image="terrain/water/reef.png"
[/item]
Code: Select all
[remove_item]
x,y=25,28
image="terrain/water/reef.png"
[/remove_item]
Code: Select all
[item]
terrain=Wwr
image="terrain/water/reef.png"
[/item]
[terrain]
terrain=Ai
[and]
terrain=Wwr
[/and]
[/terrain]
Never tried to use image on top of ice, not sure how it will look like:) maybe not nice at all no idea.
- PapaSmurfReloaded
- Posts: 822
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
Re: How to load a map from an array of variables?
My computer is an old computer, and it lags big maps.enclave wrote: ↑June 19th, 2018, 3:15 pmFor me I think 3 seconds is quite long, and keep in mind that maybe on your computer it is 3 seconds, but on some old computer it could be 10 And it would look like a big lag/freeze, not something with a nice image saying "loading please wait"PapaSmurfReloaded wrote: ↑June 19th, 2018, 2:28 pm It doesn't take that long to change the hexes of the entire map (three second max I believe)
I would try to add my lua code to check on difference (I already wrote it so that it will be 100% compatible with octalot WML example), but of course it's up to you.
ARRPGA is about roleplaying and the game already takes a lot of time anyway.
Three seconds is absolutely nothing compared to narrating the story and unit actions.
I thought about adding ^Es, but then I would have issue with frozen shallow river tiles that have ^Es overlays, which in ARRPGA maps are far, far way more common than reefs.
I honestly have never delved into LUA, I should sometime. Too lazy.
Re: How to load a map from an array of variables?
well it's quite simple if you ever used any other programming language...PapaSmurfReloaded wrote: ↑June 19th, 2018, 5:50 pm I honestly have never delved into LUA, I should sometime. Too lazy.
I guess you just never really needed it, I only started using lua because i had no choice