Variables Question

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.
Post Reply
User avatar
DEATH_is_undead
Posts: 960
Joined: March 4th, 2007, 3:00 pm
Location: Northern United States

Variables Question

Post by DEATH_is_undead »

OK, I never really needed to set my own variables in a map, so I'm fairly new to setting them. It's a simple variable I'm trying to do just to push the boundaries of WML knowledge.
All I'm trying to do is make it so that when a unit dies, it adds one to the variable.
I set the variable as bats to start with :

Code: Select all

[set_variable]
name=bats
value=0
[/set_variable]
Now, since I have the variable made, I shall add one each time a bat is killed.

Code: Select all

[event]
name=die

[filter]
type=Vampire Bat,Dread Bat,Blood Bats
[/filter]

[set_variable]
name=bats
add=1
[/set_variable]

[/event]
Using :debug feature in-game, I decided to check this to see if it was working before I continued to make the last part. Obviously it hasn't worked, and seeing variables are...varying... I haven't found a link to help me with what I'm planning to do.

EDIT: I found that only side 1 is able to change the variable for some reason, even though I don't have a filter set to just side 1, nor any other side for this matter.
EDIT2: Found that first_time_only wasn't set to no.

(I haven't even attempted to make the last part yet; making an event fire after a variable reaches a certain number. I'm going to use this thread to help with that as, if needed be.)
Last edited by DEATH_is_undead on July 25th, 2011, 8:56 pm, edited 2 times in total.
3P MP Scenario - Great Dwarves Escape
The best way to learn is to follow. In order to learn WML, you have to follow other's work, and check their codes.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Variables Question

Post by zookeeper »

By default events fire only once. You need to tell it to fire every time, not just the first time.
User avatar
DEATH_is_undead
Posts: 960
Joined: March 4th, 2007, 3:00 pm
Location: Northern United States

Re: Variables Question

Post by DEATH_is_undead »

zookeeper wrote:By default events fire only once. You need to tell it to fire every time, not just the first time.
I just noticed that, and changed it, then tried it again, but it still doesn't set the variable for any other side.
3P MP Scenario - Great Dwarves Escape
The best way to learn is to follow. In order to learn WML, you have to follow other's work, and check their codes.
User avatar
lipk
Posts: 637
Joined: July 18th, 2011, 1:42 pm

Re: Variables Question

Post by lipk »

What kind of bat you'd like to count? If there are Blood Bats among them, you should change the type 'Blood Bats' to Blood Bat, even if you are going to count multiple Blood Bats. :)
User avatar
Captain_Wrathbow
Posts: 1664
Joined: June 30th, 2009, 2:03 pm
Location: Guardia

Re: Variables Question

Post by Captain_Wrathbow »

Also, just fyi, there are some helpful macros for setting variables and performing operations on them: {VARIABLE} for just setting one to a fixed value or initializing it, and {VARIABLE_OP} for doing any mathematical operations.
User avatar
DEATH_is_undead
Posts: 960
Joined: March 4th, 2007, 3:00 pm
Location: Northern United States

Re: Variables Question

Post by DEATH_is_undead »

lipk wrote:What kind of bat you'd like to count? If there are Blood Bats among them, you should change the type 'Blood Bats' to Blood Bat
Shoot, how did the S get there? I copied and pasted it directly from the CFG file... Yeah, that fixed it :roll: Now to make an attempt at counting Variables.
Captain_Wrathbow wrote:Also, just fyi, there are some helpful macros for setting variables and performing operations on them: {VARIABLE} for just setting one to a fixed value or initializing it, and {VARIABLE_OP} for doing any mathematical operations.
I figure it's only right to start doing a variable without Marcos first; But thank you.
3P MP Scenario - Great Dwarves Escape
The best way to learn is to follow. In order to learn WML, you have to follow other's work, and check their codes.
User avatar
boru
Posts: 788
Joined: November 19th, 2009, 11:02 pm

Re: Variables Question

Post by boru »

Just tweaking, but

Code: Select all

[filter]
     race=bats
[/filter]
is a lot easier to type than

Code: Select all

[filter]
     type=Vampire Bat,Dread Bat,Blood Bat
[/filter]
“It is written in my life-blood, such as that is, thick or thin; and I can no other.” - J.R.R. Tolkien

My campaign: Swamplings - Four centuries before the founding of Wesnoth, the first wolf rider emerges from a tribe of lowly swamp goblins.
User avatar
DEATH_is_undead
Posts: 960
Joined: March 4th, 2007, 3:00 pm
Location: Northern United States

Re: Variables Question

Post by DEATH_is_undead »

boru wrote:Just tweaking, but

Code: Select all

[filter]
     race=bats
[/filter]
is a lot easier to type than

Code: Select all

[filter]
     type=Vampire Bat,Dread Bat,Blood Bat
[/filter]
Heh, didn't think about race. Truthfully, I only think I'm going to put the level 0 in, but I have to do some balance testing to make sure they'll be strong enough for my needs. (Hence why I haven't started coding the counting variable part)

And truthfully, I'm just going to copy and paste this code for the next part, and there is more then one race there.

Edit: I made the event in which it checks, once a bat has died, if it has 8 kills. If it has 8 kills, then it was to show a message stating I was going to balance the area there in. But, this, as well, is not working. Originally, it was in the same event as the set_variable was in, but it didn't work. So I changed it to its own event, in false hopes.

Code: Select all

[event]
name=die
[filter]
race=bats
[/filter]
[if]
[variable]
name=bats
numerical_equals=8
[/variable]
[then]
{QUAKE (rumble.ogg)}
[message]
speaker=narrator
message="I Am Currently Working On Balancing What Is Already Made. The Rest Of This Map Will Be Revealed In The Next Release."
[/message]
[kill]
side=4
canrecruit=yes
[/kill]

[/then]
[/if]
[/event]
3P MP Scenario - Great Dwarves Escape
The best way to learn is to follow. In order to learn WML, you have to follow other's work, and check their codes.
User avatar
boru
Posts: 788
Joined: November 19th, 2009, 11:02 pm

Re: Variables Question

Post by boru »

zookeeper wrote:By default events fire only once. You need to tell it to fire every time, not just the first time.
“It is written in my life-blood, such as that is, thick or thin; and I can no other.” - J.R.R. Tolkien

My campaign: Swamplings - Four centuries before the founding of Wesnoth, the first wolf rider emerges from a tribe of lowly swamp goblins.
User avatar
DEATH_is_undead
Posts: 960
Joined: March 4th, 2007, 3:00 pm
Location: Northern United States

Re: Variables Question

Post by DEATH_is_undead »

boru wrote:
zookeeper wrote:By default events fire only once. You need to tell it to fire every time, not just the first time.
Heh, shoot (again). That worked perfectly. (In my subconscious, it was filtering it, so I wouldn't need the first_time_only)
3P MP Scenario - Great Dwarves Escape
The best way to learn is to follow. In order to learn WML, you have to follow other's work, and check their codes.
Post Reply