Headache with [tunnel]

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
WhiteWolf
Forum Regular
Posts: 564
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Headache with [tunnel]

Post by WhiteWolf » September 26th, 2019, 12:23 pm

Hello,

I'm having a bit of trouble making some tunnels appear. The idea is to store some locations, then select the sources and targets randomly. Currently, I'm just testing for 1 random tunnel, because that doesn't work already. Here is the code:

Code: Select all

event=prestart
....
		[store_locations]
			x=37-75
			y=5-36
			[not]
				x,y=47,19
			[/not]
			[not]
				terrain=X*,Q*,*^V*
			[/not]
			variable=available_right
		[/store_locations]
		[store_locations]
			x=1-28
			y=1-26
			[not]
				x,y=27,25
			[/not]
			[not]
				terrain=X*,Q*,*^V*
			[/not]
			variable=available_left
		[/store_locations]

				{RANDOM_VARIABLE left 1..$available_left.length}
				{VARIABLE_OP left sub 1}

				{RANDOM_VARIABLE right 1..$available_right.length}
				{VARIABLE_OP right sub 1}

				{VARIABLE right_x "$available_right[$right].x"}
				{VARIABLE right_y "$available_right[$right].y"}
				# the reason for this is a commented out for loop here that will select multiple hexes into right_x and right_y, such as
				# right_x=34,35,36,37
				# right_y=13,15,16,17
				# but this is currently off.

				{CLEAR_VARIABLE available_right[$right]}
				{PRINTF "$available_left[$left].x $available_left[$left].y $right_x $right_y"}
				[tunnel]
					[filter]
					[/filter]
					[source]
						x,y=$available_left[$left].x,$available_left[$left].y
					[/source]
					[target]
						x=$right_x
						y=$right_y
					[/target]
					bidirectional=yes
					#id=$tunnel_id
				[/tunnel]

				[item]
					x,y=$available_left[$left].x,$available_left[$left].y
					name="tunnel_$tunnel_id"
					image=scenery/portal.png
				[/item]
				[item]
					x=$right_x
					y=$right_y
					name="tunnel_$tunnel_id"
					image=scenery/portal.png
				[/item]
Sorry for the terrible indentation, there's some stuff between and before the tags already commented out (for loops, for trying to expand for multiple tunnels, but as said, the example of 1 tunnel already fails).

The {RANDOM_VARIABLE name value} is just the extension of the core {RANDOM} macro with the added name parameter.
The {PRINTF} is just a narrator message for testing, and it always successfully gives 4 integers, for example "11 15 38 17", and the [item]'s in the end successfully place the portal.png items on the requested locations. But for whatever reason, the tunnel itself doesn't work, and I have no idea why.

I tested this:

Code: Select all

{VARIABLE l1 5}
{VARIABLE l2 5}

[tunnel]
	[filter]
	[/filter]
	[source]
		x,y=$l1,$l2
	[/source]
	[target]
		x=6
		y=6
	[/target]
	bidirectional=yes
[/tunnel]
So there is no problem with variable substitution inside [tunnels]'s. Any other idea?
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!

User avatar
MoonyDragon
Posts: 15
Joined: November 29th, 2017, 5:46 pm

Re: Headache with [tunnel]

Post by MoonyDragon » September 26th, 2019, 12:50 pm

Hi, I must admit that I havent done any testing yet, but I noticed a section where an error *might* occur:

Code: Select all

[not]
    x,y=47,19
[/not]
[not]
    terrain=X*,Q*,*^V*
[/not]
I am not sure whether you can put in two [not] tags within the same filter_location (you store locations after all) parent.
Maybe putting in an [and] tag might work, but I do not guarantee anything xD

Code: Select all

[not]
    x,y=47,19
[/not]
[and]
    [not]
        terrain=X*,Q*,*^V*
    [/not]
[/and]
Coding of the Sand Storm Terrain

User avatar
WhiteWolf
Forum Regular
Posts: 564
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Headache with [tunnel]

Post by WhiteWolf » September 26th, 2019, 1:41 pm

No, that's not it. The two codes you pasted are identical. [not] is like [and], but with a false expectation, so several not's after each other work as expected.
Also, the item appear fine on the locations, and the printf also finds legal locations.

On the other hand, I also wanted to check on the variables in inspect mode, so I also removed the code where the variables are cleaned up (which was not included in the original post, sorry):

Code: Select all

# commented out the clear_variable's
				{CLEAR_VARIABLE available_left[$left]}
				{CLEAR_VARIABLE left,right}
		#	[/do]
		#[/while]
		{CLEAR_VARIABLE available_left,available_right}
	[/event]
And now it magically works.

So I guess the answer is that if I use

Code: Select all

[source]
    x,y=$var1,$var2
[/source]
inside a tunnel, then var1 and var2 must constantly exist, as their value is not substituted directly in at the creation of the tunnel, but are instead "constantly read"...? And as soon as they are cleared, the tunnel ceases to have a source. That's my understanding of this.
And if this is the case, then it is bad :D If a dev sees this, would it be possible to pass variables to [source] and [target] tags that are directly substituted at the creation, and can be cleared afterwards?
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!

gfgtdf
Developer
Posts: 1203
Joined: February 10th, 2013, 2:25 pm

Re: Headache with [tunnel]

Post by gfgtdf » September 26th, 2019, 2:27 pm

WhiteWolf wrote:
September 26th, 2019, 1:41 pm
then var1 and var2 must constantly exist, as their value is not substituted directly in at the creation of the tunnel, but are instead "constantly read"...? And as soon as they are cleared, the tunnel ceases to have a source. That's my understanding of this.
And if this is the case, then it is bad :D
yes that's how it looks to me aswell, there are some tags that fo have this bavhoir but usually they have a delayed_variable_substitution attribute to disable this bahviour, but the wiki does not mention that for [tunnel]
WhiteWolf wrote:
September 26th, 2019, 1:41 pm

If a dev sees this, would it be possible to pass variables to [source] and [target] tags that are directly substituted at the creation, and can be cleared afterwards?
Even if delayed_variable_substitution=no does not work here it's surely possible to do this with lua already. (Can't give code since I'm ony phone)
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

User avatar
WhiteWolf
Forum Regular
Posts: 564
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Headache with [tunnel]

Post by WhiteWolf » September 26th, 2019, 3:11 pm

Yay, delayed_variable_substitution=no works and solved it :) Apparently it exists then, but for some reason, yes is the default value here in [tunnel]. I must note, I'm not sure if it's the best default value. :hmm: For now I'll add the key to the wiki.
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!

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

Re: Headache with [tunnel]

Post by Celtic_Minstrel » October 3rd, 2019, 4:17 am

It probably defaults to yes for backwards compatibility, as the key did not exist in [tunnel] in 1.12 if I recall correctly. (Though I might be confusing it with a different place.)
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

Post Reply