Event trigger: Why didn't work?

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.
AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Event trigger: Why didn't work?

Post by AssassinT90 » June 23rd, 2009, 9:22 am

Hello... I was practicing a bit when I found a problem:
[event]
name=moveto
[filter]
side=1
[/filter]
[filter]
canrecruit=yes
[/filter]
[filter]
x,y=3,1
[/filter]
[event]
[unit]
type=Mage
side=1
gender=male
x,y=5,1
name=Ashkatar
{TRAIT LOYAL}
{TRAIT INTELLIGENT}
experience=24
facing=sw
[/unit]

[/event]
first_time_only=yes

[/event]
This event didn't work. Could you point the mistake, please?

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Event trigger: Why didn't work?

Post by zookeeper » June 23rd, 2009, 9:32 am

Multiple [filter] blocks, a nested event with no name= and also traits not inside [modifications].

User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Event trigger: Why didn't work?

Post by melinath » June 23rd, 2009, 10:53 am

In other words, it should look more like this:

Code: Select all

[event]
     name=moveto
     [filter]
          side=1
          canrecruit=yes
          x,y=3,1
     [/filter]
     [unit]
          type=Mage
          side=1
          gender=male
          x,y=5,1
          name=Ashkatar
          [modifications]
               {TRAIT LOYAL}
               {TRAIT INTELLIGENT}
          [/modifications]
          experience=24
          facing=sw
     [/unit]
     first_time_only=yes
[/event]
The nested event seems completely unnecessary. Also, it's a lot easier to read if you put the code in a

Code: Select all

 tag, since the indentation is preserved.

AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Re: Event trigger: Why didn't work?

Post by AssassinT90 » June 23rd, 2009, 3:52 pm

@zookeeper, melinath:
Thanks for it, it's fixed now.
Just wondering about where I should put this:

Code: Select all

{GENERIC_UNIT 1 Spearman 3 2}
	{GENERIC_UNIT 1 Spearman 5 2}
	{GENERIC_UNIT 1 Spearman 5 3}
Edited:
Just found where I should had put that code.

User avatar
A Guy
Posts: 790
Joined: May 24th, 2008, 1:55 am

Re: Event trigger: Why didn't work?

Post by A Guy » June 23rd, 2009, 4:07 pm

AssassinT90 wrote:@zookeeper, melinath:
Thanks for it, it's fixed now.
Just wondering about where I should put this:

Code: Select all

{GENERIC_UNIT 1 Spearman 3 2}
	{GENERIC_UNIT 1 Spearman 5 2}
	{GENERIC_UNIT 1 Spearman 5 3}
Edited:
Just found where I should had put that code.
Just put it in the event.
I'm just... a guy...
I'm back for now, I might get started on some work again.

AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Re: Event trigger: Why didn't work?

Post by AssassinT90 » June 23rd, 2009, 5:20 pm

Guys, I found other problems.
It's about variable manipulating:

Here's the code:

Code: Select all

[event]
     name=moveto
     [filter]
          side=1
          canrecruit=yes
          x,y=3,1
     [/filter]
     [unit]
          type=$unit_of_$leader
          side=1
          gender=male
          x,y=5,1
          name=Ashkatar
          [modifications]
               {TRAIT LOYAL}
               {TRAIT INTELLIGENT}
          [/modifications]
          experience=24
          facing=sw
     [/unit]
	{GENERIC_UNIT 1 Spearman 3 2}
   	{GENERIC_UNIT 1 Spearman 5 2}
   	{GENERIC_UNIT 1 Spearman 5 3}
	#Variável de testes
	[set_variable]
		name=leader
		value=$unit.type
	[/set_variable]
	[set_variable]
		name=unit_of_Troll
		value=Orcish Grunt
	[/set_variable]
	[set_variable]
		name=unit_of_Orcish Crossbowman
		value=Orcish Grunt
	[/set_variable]

	[message]
		speaker=narrator
		message="$unit_of_$leader||"
	[/message]
	[message]
		speaker=narrator
		message="$leader|"
	[/message]
	[message]
		speaker=narrator
		message= "$unit_of_Troll|"
	[/message]	
	[message]
		speaker=narrator
		message= "$unit_of_Orcish Crossbowman|"
	[/message]
	#Fim da variável de teste

     first_time_only=yes
[/event]
First: when a Troll is my leader, the first message shows:
Orcish grunt(Right)

Second message shows:
Troll(Right)

Third message shows:
Orcish Grunt(Right)

Fourth message shows:
Crossbowman|(Wrong)

I'm almost sure that the mistake comes from the space on the variable. But if(for instance)
my leader was an Orcish Crossbowman the first message would be wrong too
($unit_of_Orcish Crossbowman).
Is there any way to solve that problem?


Second:
Why is the unit type wrong? When the event triggers, the game shows an error message, saying that the type should be empty,
but by my calcs it would be "type=Orcish Grunt"

Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Event trigger: Why didn't work?

Post by Exasperation » June 23rd, 2009, 5:35 pm

There are two problems here: the first, as you already guessed, is that variable names can't have whitespace in them. The second is that your [set_variable] tags are after the first time you try to access the value stored in them. Everything before the [set_variable] tags (such as the line type=$unit_of_$leader) sees the variables as containing empty strings, because their value hasn't been set yet.

AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Re: Event trigger: Why didn't work?

Post by AssassinT90 » June 23rd, 2009, 5:46 pm

Exasperation:
Thanks for it! You fixed the second bug, told me why the first happened, I just need some help to find an way to fix it. Let me exemplify:

value=$unit_of_$leader
leader=Orcish Crossbowman
Translating:
value=$unit_of_Orcish Crossbowman

How to make it work? If it's "$unit_of_Troll"(for instance), the variable will work, but if it has more than two words, it won't.

Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Event trigger: Why didn't work?

Post by Exasperation » June 23rd, 2009, 5:59 pm

Well, you could do some cleanup on the contents of leader before you try to use it:

Code: Select all

[if]
	[variable]
		name=leader
		equals="Orcish Crossbowman"
	[/variable]
	[then]
		{VARIABLE leader "Oricsh_Crossbowman"}
	[/then]
[/if]
Then you could replace that space in your variable name with an underscore.

AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Re: Event trigger: Why didn't work?

Post by AssassinT90 » June 23rd, 2009, 6:39 pm

@Exasperation:
Thanks again. It's fixed now. Sorry for my laziness(or stupidity, if you prefer). I din't search for it before posting. I would probably find it if I had search on the Conditional Actions.

AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Re: Event trigger: Why didn't work?

Post by AssassinT90 » June 25th, 2009, 4:58 pm

Hey, guys, could you help me here?
First: Here's the event resume:

Code: Select all

[event]
	[set_variable]
	name=zombie
	rand=0,1,0
	[/set_variable]
	{RANDOM 0,1,0,0,0,1,1}
     name=moveto
     [filter]
	canrecruit=yes
	x,y=3,1
     [/filter]
	[message]
	message= "$zombie|"
	[/message]
	[message]
	message= "$random|"
	[/message]

	{CLEAR_VARIABLE zombie}
	{CLEAR_VARIABLE random}
[/event]
(Full event)
Spoiler:
All messages were 0. Why did it happen(and my random variable didn't work)?

Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Event trigger: Why didn't work?

Post by Exasperation » June 25th, 2009, 5:08 pm

When you use {RANDOM <options>} (or the equivalent [store_variable] block you used to set the zombie variable) it picks one of the options you passed to it at random and stores that specific result in the variable, where it will remain until you do something to change it. If you want each of the messages to display independent results, you need to put another RANDOM call in between each message, like so:

Code: Select all

[event]
     name=moveto
     [filter]
   canrecruit=yes
   x,y=3,1
     [/filter]
   [set_variable]
   name=zombie
   rand=0,1,0
   [/set_variable]
   [message]
   message= "$zombie|"
   [/message]
   [set_variable]
   name=zombie
   rand=0,1,0
   [/set_variable]
   [message]
   message= "$zombie|"
   [/message]
   [set_variable]
   name=zombie
   rand=0,1,0
   [/set_variable]
   [message]
   message= "$zombie|"
   [/message]
   [set_variable]
   name=zombie
   rand=0,1,0
   [/set_variable]
   [message]
   message= "$zombie|"
   [/message]
   [set_variable]
   name=zombie
   rand=0,1,0
   [/set_variable]
   [message]
   message= "$zombie|"
   [/message]
   [set_variable]
   name=zombie
   rand=0,1,0
   [/set_variable]
   [message]
   message= "$zombie|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]
   {RANDOM 0,1,0,0,0,1,1}
   [message]
   message= "$random|"
   [/message]

   {CLEAR_VARIABLE zombie}
   {CLEAR_VARIABLE random}
[/event]

User avatar
A Guy
Posts: 790
Joined: May 24th, 2008, 1:55 am

Re: Event trigger: Why didn't work?

Post by A Guy » June 25th, 2009, 5:24 pm

It's preferred that you use 0,0,1 instead of 0,1,0 for consistency.
I'm just... a guy...
I'm back for now, I might get started on some work again.

AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Re: Event trigger: Why didn't work?

Post by AssassinT90 » June 25th, 2009, 6:23 pm

@Exasperation:
Thank you!

@Forum:

Code: Select all

	{RANDOM 0,1}
	[unit]
		type=Walking Corpse
		x,y=2,1
		name=$random
		[modifications]
			[effect]
				apply_to=zoc
				value=$random
			[/effect]
		[/modifications]
	[/unit]
(Full event)
Spoiler:
Is there any problem with the [effect] tag? It's not working. I think it's not working because it's wrongly placed.

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Event trigger: Why didn't work?

Post by zookeeper » June 25th, 2009, 6:54 pm

AssassinT90 wrote:@Exasperation:
Thank you!

@Forum:

Code: Select all

	{RANDOM 0,1}
	[unit]
		type=Walking Corpse
		x,y=2,1
		name=$random
		[modifications]
			[effect]
				apply_to=zoc
				value=$random
			[/effect]
		[/modifications]
	[/unit]
(Full event)
Spoiler:
Is there any problem with the [effect] tag? It's not working. I think it's not working because it's wrongly placed.
As you can see, [modifications] only recognizes [trait]s and [object]s. So just wrap your [effect] inside an [object], it'll probably work.

Post Reply