Heindals WML Questions

The place to post your WML questions and answers.

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.
User avatar
Heindal
Posts: 1352
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Heindals WML Questions

Post by Heindal »

Hello,

Is it possible to check the "terrain type" of a coordinate and than save it in a variable? I need this for a random encounter, with changing maps.
I haven't found anything so far within the wiki and I'd appreciate your help.

Kind regards

Heindal
Last edited by Heindal on October 22nd, 2012, 5:54 pm, edited 1 time in total.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Adamant14
Posts: 968
Joined: April 24th, 2010, 1:14 pm

Re: Check Terrain Type of a changing coordinate

Post by Adamant14 »

Try something like:

Code: Select all

	[store_locations]
		x,y=$x1,$y1
		variable=stored_terrain
	[/store_locations]
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
User avatar
Heindal
Posts: 1352
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Check Terrain Type of a changing coordinate

Post by Heindal »

Holy WML knowledge gap :oops:. This should work fine.

Thank you very much Adamant14 .
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Heindal
Posts: 1352
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Check Terrain Type of a changing coordinate

Post by Heindal »

Well, it doesn't work. I don't know what I'm doing wrong. The idea sounds simple.

Select the x,y coordinate of the herounit, check the terraintype and than call an encounter (each type of terrain is a scenario) that is based on the terrain type, for example a scenario within a desert, when the hero stands on a desert field.

My main problem is that the saved varriable "terrain" is always empty. I tried different approaches with filters, adding the hero id it won't work. Can anybody give me an advice?



Code: Select all


#define CALLENCOUNTER

[store_unit]
	[filter]
	   id=you
        	[/filter]
        	variable=younit
[/store_unit]

[set_variable]
	name=XHEROSPAWN
	value=$younit.x
[/set_variable]

[set_variable]
	name=YHEROSPAWN
	value=$younit.y
[/set_variable]

{CLEAR_VARIABLE younit}

[store_time_of_day]
x,y=$XHEROSPAWN,$YHEROSPAWN
variable=daytime
[/store_time_of_day]

[store_locations]
x,y=$XHEROSPAWN,$YHEROSPAWN
variable=terrain
[/store_locations]

[if]
[variable]
name=terrain
equals=Dd^Dc
[/variable]
[or]
[variable]
name=terrain
equals=Dd^Do
[/variable]
[/or]
[or]
[variable]
name=terrain
equals=Hd
[/variable]
[/or]
[or]
[variable]
name=terrain
equals=Md
[/variable]
[/or]
[then]
{CONTINUE Encounter5}
[/then]
[/if]
#enddef 
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Check Terrain Type of a changing coordinate

Post by Sapient »

terrain.terrain
It stores terrain inside the container variable


I would avoid naming a location variable as terrain to prevent this confusion, e.g. my_location.terrain
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Kernigh
Posts: 107
Joined: February 13th, 2007, 10:21 pm
Location: United States
Contact:

Re: Check Terrain Type of a changing coordinate

Post by Kernigh »

As a shortcut, you might remove [store_locations] and use [have_location].

Code: Select all

[if]
    [have_location]
        x,y=$XHEROSPAWN,$YHEROSPAWN
        terrain=Dd^Dc,Dd^Do,Hd,Md
    [/have_location]
    [then]
        # ...
User avatar
Heindal
Posts: 1352
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Check Terrain Type of a changing coordinate

Post by Heindal »

Thanks both of you! It works fine now. No I need to look up some terrain variables, but thanks to have location I can make a comma separated list, which should work fine and reduce the code. If anyone is interested in the code for the random encounter or the maps, I can post them later. It will be published in the new version of Strange Legacy.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Heindal
Posts: 1352
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Heindals WML Questions

Post by Heindal »

I have two other questions. At the moment I'm working on two macros.


The first macro should be simple range test, that will allows to use a attack, spell or ability over a greater range. The parts of the macro are placed within a spelloption and should test if the target is in range. At the moment it has no effect for some reason. The else part is buggy, but it seems that I'm blind. I can't find a mistake in the definition.
Spoiler:



The second macro should place a trap (or a move to event) in a scenario.
Spoiler:

It doesn't seem to work, the macro so far just places the label but not the event.

I tried two different approaches to solve the problem. I used $x1/$y1 and a random identifier togehter with trapx/trapy to define each coordinate as a unique variable. When using trapx/trapy + an identifier just the first trap seems to work when placing the second, it will have the second placed traps has the effect of two traps, while the first one is disarmed. $x1/$y1 each creature moving will be hurt by any placed trap. Any idea what's wrong with it?
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: Heindals WML Questions

Post by Ceres »

Code: Select all

[set_variable]
  name=texty
  value=$firer.y
[/set_variable]
I'm assuming that it should be testy, not texty.
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Heindals WML Questions

Post by Max »

you need to learn to debug your code.

using :inspect (you have to enable debug mode, see http://wiki.wesnoth.org/CommandMode) would have revealed the variable mismatch (testx vs. textx).

if you're interested in certain variables directly within your code use [inspect]. it's also sometimes helpful to display messages to see what parts of your code are actually evaluated. you can use [message] or stick to the error macro http://www.wesnoth.org/macro-reference. ... -utils.cfg (just displays message in in-game chat and you don't have to discard lots of message windows).

your way to calculate the distance seems quite complicated, maybe something like that might help: http://forums.wesnoth.org/viewtopic.php ... 08#p481119
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Heindals WML Questions

Post by pyrophorus »

Hi !
Why not this to test the range ?

Code: Select all

[have_unit]
	id=$firer.id
	[filter_location]
		x,y=$x1,$y1
		radius=$range
	[/filter_location]
	count=1
[/have_unit]
As for the trap event which don't work, did you checked 'delayed_variable_substitution=no' ?

HTH
User avatar
Heindal
Posts: 1352
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Heindals WML Questions

Post by Heindal »

Thanks for your replies, as soon as I have time and motivation I will test all the proposals.
I'm sorry for not using debugging, I'm still using the game itself as validator. :oops:
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Heindal
Posts: 1352
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Heindals WML Questions

Post by Heindal »

Thanks for your answers, I could solve both problems.
Pyrophorus posted solution for range works fine.

I also placed 'delayed_variable_substitution=no' in the event tag, where the map is created.
It works fine now! Thanks to you I could finish my work on "Dungeons of Wesnoth".
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Heindal
Posts: 1352
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Game Crash

Post by Heindal »

Its me again:

I made several terrain overlays to place them within the map editor. It worked fine for some time but after adding more overlays I can not reload the map editor. I can open the game, but as soon as I try to open the map editor the game crashes. Is there a maximum of terrain overlays for a group?
Can adding terrains cause a crash?
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Alarantalara
Art Contributor
Posts: 786
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Heindals WML Questions

Post by Alarantalara »

There is no maximum that I know of (you'd run out of space in "All" first anyway and Archaic Era already has a lot).
It's more likely that you have problems with your ids or terrain strings. Can you post a copy of the file containing all the terrain definitions?

You might also want to try removing other add-ons and trying again. You may have something that conflicts with it in an unusual way. If this is the case, including a list of the add-ons you have installed would also be useful.
Post Reply