Need help with sticky teleport code.

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
Circon
Posts: 1200
Joined: November 17th, 2003, 4:26 am
Location: Right behind Gwiti, coding

Need help with sticky teleport code.

Post by Circon »

Code: Select all

#define LANDINGHEX NUMBER X Y
	[if]
			[variable]
			name=random
			numerical_equals={NUMBER}
			[/variable]
			[then]
			x={X}
			y={Y}
			[/then]
	[/if]
#enddef

#Co-ords for middles: 
# 3,4 9,4 15,4
# 6,8 12,8 18,8
# 3,13 9,13 15,13
# 6,17 12,17 18,17

		

#define TELEPORTINGMIDDLE X Y
	[event]
	name=moveto
	first_time_only=no
		[filter]
		x={X}
		y={Y}
		[/filter]
		{RANDOM 1..12}
		[teleport]
			[filter]
			x={X}
			y={Y}
			[/filter]
	LANDINGHEX 1 3 4
	LANDINGHEX 2 9 4
	LANDINGHEX 3 15 4
	LANDINGHEX 4 6 8
	LANDINGHEX 5 12 8
	LANDINGHEX 6 18 8
	LANDINGHEX 7 3 13
	LANDINGHEX 8 9 13
	LANDINGHEX 9 15 13
	LANDINGHEX 10 6 17
	LANDINGHEX 11 12 17
	LANDINGHEX 12 18 17
		[/teleport]
	[/event]
#enddef
TELEPORTINGMIDDLE 3 4
TELEPORTINGMIDDLE 9 4
TELEPORTINGMIDDLE 15 4
TELEPORTINGMIDDLE 6 8
TELEPORTINGMIDDLE 12 8
TELEPORTINGMIDDLE 18 8
TELEPORTINGMIDDLE 3 13
TELEPORTINGMIDDLE 9 13
TELEPORTINGMIDDLE 15 13
TELEPORTINGMIDDLE 10 6 17
TELEPORTINGMIDDLE 11 12 17
TELEPORTINGMIDDLE 12 18 17
What's wrong with this code? Nobody teleports when I move to (3,4) or to (4,3) or to anything else for that matter.

As far as I see, the first code block should give out an X and a Y based on the random variable RANDOM.

The second code block initiates teleport of whoever is on the coordinates specified, randomizes RANDOM, calls in the first code block to give it a X and a Y, then teleports the unit there.

But it doesn't work.
Circon
Posts: 1200
Joined: November 17th, 2003, 4:26 am
Location: Right behind Gwiti, coding

Post by Circon »

Edit: Tried putting braces on {} as suggested be Cedric... didn't work.
Invisible Philosopher
Posts: 873
Joined: July 4th, 2004, 9:14 pm
Location: My imagination
Contact:

Re: Need help with sticky teleport code.

Post by Invisible Philosopher »

You need braces, but the problem is, you can't put [if] inside [teleport] or x= and y= inside [then]. The x= and y= must be directly inside [teleport], and the ones inside [then] make no difference. In fact, putting an [if] inside [teleport] has no effect, because that is not a place where Wesnoth expects a command (or the new use: inside a [story] tag). Wesnoth's cfg engine will totally ignore tags and attributes that don't belong where you put them. Here's the fixed code:

Code: Select all

#define LANDINGHEX NUMBER X1 Y1 X2 Y2
	[if]
			[variable]
			name=random
			numerical_equals={NUMBER}
			[/variable]
			[then]
			[teleport]
				[filter]
				x={X1}
				y={Y1}
				[/filter]
			x={X2}
			y={Y2}
			[/teleport]
			[/then]
	[/if]
#enddef

#Co-ords for middles: 
# 3,4 9,4 15,4
# 6,8 12,8 18,8
# 3,13 9,13 15,13
# 6,17 12,17 18,17

		

#define TELEPORTINGMIDDLE X Y
	[event]
	name=moveto
	first_time_only=no
		[filter]
		x={X}
		y={Y}
		[/filter]
		{RANDOM 1..12}
	{LANDINGHEX 1 {X} {Y} 3 4}
	{LANDINGHEX 2 {X} {Y} 9 4}
	{LANDINGHEX 3 {X} {Y} 15 4}
	{LANDINGHEX 4 {X} {Y} 6 8}
	{LANDINGHEX 5 {X} {Y} 12 8}
	{LANDINGHEX 6 {X} {Y} 18 8}
	{LANDINGHEX 7 {X} {Y} 3 13}
	{LANDINGHEX 8 {X} {Y} 9 13}
	{LANDINGHEX 9 {X} {Y} 15 13}
	{LANDINGHEX 10 {X} {Y} 6 17}
	{LANDINGHEX 11 {X} {Y} 12 17}
	{LANDINGHEX 12 {X} {Y} 18 17}
	[/event]
#enddef
{TELEPORTINGMIDDLE 3 4}
{TELEPORTINGMIDDLE 9 4}
{TELEPORTINGMIDDLE 15 4}
{TELEPORTINGMIDDLE 6 8}
{TELEPORTINGMIDDLE 12 8}
{TELEPORTINGMIDDLE 18 8}
{TELEPORTINGMIDDLE 3 13}
{TELEPORTINGMIDDLE 9 13}
{TELEPORTINGMIDDLE 15 13}
{TELEPORTINGMIDDLE 10 6 17}
{TELEPORTINGMIDDLE 11 12 17}
{TELEPORTINGMIDDLE 12 18 17}
Play a Silver Mage in the Wesvoid campaign.
Circon
Posts: 1200
Joined: November 17th, 2003, 4:26 am
Location: Right behind Gwiti, coding

Post by Circon »

IT WORKS!!!
quartex
Inactive Developer
Posts: 2258
Joined: December 22nd, 2003, 4:17 am
Location: Boston, MA

Post by quartex »

Hallelujah!
Circon
Posts: 1200
Joined: November 17th, 2003, 4:26 am
Location: Right behind Gwiti, coding

Post by Circon »

Here is the map with code attached. Place map in data/maps/multiplayer, the .cfg file in data/scenarios/multiplayer.
Post Reply