variable in turn#

Discussion and development of scenarios and campaigns for the game.

Moderator: Forum Moderators

Post Reply
Darwin
Posts: 2
Joined: July 11th, 2005, 3:08 pm

variable in turn#

Post by Darwin »

On this page http://wesnoth.slack.it/?VariablesWML it says:
For example the attribute turns=$turns is a way to set the number of turns in a scenario to a particular variable.

I'm working on a multiplayer scenario with a friend of mine and neither one of us can figure out why the following does not set the number of turns to the variable:

[event]
name=prestart
[set_variable]
name=turns
value=13
[/set_variable]
[/event]

turns=$turns

[event]
name=start
[print]
text=$turns
duration=100
red=255
[/print]
[/event]

I've added [print] in the start event to check if the variable indeed had a value, which it does. So why turns=0 instead of turns=13 in the game?!
A different name for the variable doesn't help.

Thanks for any solutions
Dacyn
Posts: 1855
Joined: May 1st, 2004, 9:34 am
Location: Texas

Re: variable in turn#

Post by Dacyn »

Darwin wrote:So why turns=0 instead of turns=13 in the game?!
Turn value is determined based on the value of 'turns' (or whatever you put) when the scenario starts. Changes to 'turns' will only affect the number of turns if it is in a previous scenario's event; i.e. a carry-over variable. The number of turns cannot be changed during a scenario.

I added this information to the wiki page... possibly a better example should be used too :)
Darwin
Posts: 2
Joined: July 11th, 2005, 3:08 pm

Post by Darwin »

Dacyn wrote:The number of turns cannot be changed during a scenario.
Thanks, Dacyn, it's not the answer I was hoping for, but it'll have to do.. :wink:

[event]
name=turn $turns
This won't work for the same reason, then, right?
Dacyn wrote:Changes to 'turns' will only affect the number of turns if it is in a previous scenario's event; i.e. a carry-over variable.
So are all variables carried over from one scenario to another, if they are not cleared? Are they carried over multiple scenarios until cleared?

That would be good news. Good enough to compensate for the above-mentioned disappointment, perhaps :lol:
scott
Posts: 5243
Joined: May 12th, 2004, 12:35 am
Location: San Pedro, CA

Post by scott »

Yes, variables set with [set_variable] do carry over.
If you want a variable number of turns, you could set the scenario to unlimited turns then have different victory defeat or victory events based on the variable's value. I think the code you posted should work as long as you have a value in the variable you're using.
Hope springs eternal.
Wesnoth acronym guide.
User avatar
turin
Lord of the East
Posts: 11662
Joined: January 11th, 2004, 7:17 pm
Location: Texas
Contact:

Post by turin »

There is also a way to have a certain turn limit AFTER you do something. So, you have the objective be "move here", then, after you do that, the objective changes to "survive for 5 turns" or something like that.

Code: Select all

	[event]
	name=moveto
		[filter]
		x,y=16,25
		description=Thursagan
		[/filter]
		[set_variable]
		name=turnsleft
		value=5
		[/set_variable]
		[objectives]
		side=1
			[objective]
			description= _ "Survive for 5 turns"
			condition=win
			[/objective]
			[objective]
			description= _ "Death of Rugnur"
			condition=lose
			[/objective]
			[objective]
			description= _ "Death of Baglur"
			condition=lose
			[/objective]
			[objective]
			description= _ "Death of Krawg"
			condition=lose
			[/objective]
			[objective]
			description= _ "An enemy moves onto the forge"
			condition=lose
			[/objective]
			[objective]
			description= _ "Time runs out"
			condition=lose
			[/objective]
		[/objectives]
		[event]
		name=new turn
		first_time_only=no
			[set_variable]
			name=turnsleft
			add=-1
			[/set_variable]
			[if]
				[variable]
				name=turnsleft
				numerical_equals=0
				[/variable]
				[then]
					[endlevel]
					result=victory
					bonus=no
					[/endlevel]
				[/then]
			[/if]
		[/event]		
	[/event]
For I am Turin Turambar - Master of Doom, by doom mastered. On permanent Wesbreak. Will not respond to private messages. Sorry!
And I hate stupid people.
The World of Orbivm
Invisible Philosopher
Posts: 873
Joined: July 4th, 2004, 9:14 pm
Location: My imagination
Contact:

Post by Invisible Philosopher »

Darwin wrote:[event]
name=turn $turns
This won't work for the same reason, then, right?
I believe that reason would make it not work, although I am not sure. In any case most tags, such as that "name", do not interpolate variables but rather check only for a $ as the first character. However events can generate events, and other things can be used for formatting, so it is still doable:

Code: Select all

[event]
name=prestart
	#...
	{VARIABLE_OP turn_event_value format (turn $turns)}
	[event]
		name=$turn_event_value
		#...
	[/event]
[/event]
However I have no idea when that attribute is actually evaluated, if at all, so it might not quite work in the way I am guessing it does.
Play a Silver Mage in the Wesvoid campaign.
Post Reply