Unit creation using variables
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.
Unit creation using variables
Alright guys, I've been trying to fix this all day. I've changed this probably thirty or forty times and it's quite frustrating.
To start off, my goal is to store a unit so I can get its location and then use that location to spawn a unit next to it; however, my unit that I want to spawn does not appear and all of his dialog does not follow (I'm assuming because the unit is not created). The other unit's dialog does proceed and he also vanishes on schedule. I've had other errors and whatnot, but now I'm officially stuck with this one. You'll notice that I have another unit (the main character) outputting the location information, which is correct. I just don't understand why this is not working. Granted, I've found working with variables in Wesnoth a little confusing compared to traditional languages that I've worked with like C++ and Java.
This macro that I created is called in several spots. My main issue has been with assigning the new unit's y value to one more than the stored unit. I can output the right value in text, but not assign the right value to the unit. I don't want to waste any more time on this one issue, so I thought I would ask you guys for some help. Also, please do not make fun of my attempt. I've tried looking at examples and have read the documentation quite a lot. My $($variable + 1) was only done because I had seen something like it in an example, and it proved to work when I printed out the messages to compare values.
Oh, and if the indentations look a little off, it might have something to do with me using Notepad++, which seems to transfer my text to other things a little weird.
[EDIT]
It now seems that I've edited something that causes the whole dialog between both characters to be skipped (the messages containing the locations still appear).
To start off, my goal is to store a unit so I can get its location and then use that location to spawn a unit next to it; however, my unit that I want to spawn does not appear and all of his dialog does not follow (I'm assuming because the unit is not created). The other unit's dialog does proceed and he also vanishes on schedule. I've had other errors and whatnot, but now I'm officially stuck with this one. You'll notice that I have another unit (the main character) outputting the location information, which is correct. I just don't understand why this is not working. Granted, I've found working with variables in Wesnoth a little confusing compared to traditional languages that I've worked with like C++ and Java.
This macro that I created is called in several spots. My main issue has been with assigning the new unit's y value to one more than the stored unit. I can output the right value in text, but not assign the right value to the unit. I don't want to waste any more time on this one issue, so I thought I would ask you guys for some help. Also, please do not make fun of my attempt. I've tried looking at examples and have read the documentation quite a lot. My $($variable + 1) was only done because I had seen something like it in an example, and it proved to work when I printed out the messages to compare values.
Oh, and if the indentations look a little off, it might have something to do with me using Notepad++, which seems to transfer my text to other things a little weird.
[EDIT]
It now seems that I've edited something that causes the whole dialog between both characters to be skipped (the messages containing the locations still appear).
Code: Select all
#define KILL_KING
[if]
[variable]
name=Tornik_Dead
boolean_equals=false
[/variable]
[then]
[store_unit]
[filter]
id=Tornik
[/filter]
variable=varTornik
[/store_unit]
[message]
speaker=Samuel
message= _ "King Location: $varTornik.x| , $varTornik.y|"
[/message]
[message]
speaker=Samuel
message= _ "Assassin Location: $varTornik.x| , $($varTornik.y + 1)"
[/message]
[kill]
x,y=$varTornik.x,$($varTornik.y + 1)
animate=yes
fire_event=no
[/kill]
[unit]
id=Wrostren
name= _ "Wrostren"
type=Assassin
side=2
x=$varTornik.x
y=$($varTornik.y + 1)
[/unit]
[message]
speaker=Wrostren
message= _ "Those pathetic soldiers never stood a chance."
[/message]
[message]
speaker=Tornik
message= _ "Who are you?"
[/message]
[message]
speaker=Wrostren
message= _ "That is not for you to know."
[/message]
[message]
speaker=Tornik
message= _ "Gah!"
[/message]
[message]
speaker=Tornik
message= _ "My... my son. Y-You must... must... live."
[/message]
[hide_unit]
x,y=$varTornik.x,$varTornik.y
[/hide_unit]
[message]
speaker=Wrostren
message = _ "I still have another duty to fulfill. I will leave the rest here to Ravsha's troops."
[/message]
[kill]
x,y=$varTornik.x,$($varTornik.y + 1)
animate=no
fire_event=no
[/kill]
[kill]
id=Tornik
animate=no
fire_event=no
[/kill]
[set_variable]
name=Tornik_Dead
value=true
[/set_variable]
[clear_variable]
name=varTornik
[/clear_variable]
[/then]
[else]
[message]
speaker=Samuel
message= _ "Father!"
[/message]
[message]
speaker=Leon
message= _ "The King has fallen! We will not be able to escape them!"
[/message]
[endlevel]
result=defeat
[/endlevel]
[/else]
[/if]
#enddef
Re: Unit creation using variables
I'm double-posting because I found a fix for my problem. I'm not sure if this is how it is supposed to work, but by placing my $($varTurnik.y + 1) inside quotes, it gives me the correct value and everything plays out perfectly!
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Unit creation using variables
The reason for your issue could be that wesnoth performs string concatenation in the formula if without quotes, so $varTurnik.y + 1 becomes $varTurnik.y1
http://forums.wesnoth.org/viewtopic.php?f=21&t=27444 (silene's quizz)
http://forums.wesnoth.org/viewtopic.php?f=21&t=27444 (silene's quizz)
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: Unit creation using variables
Oh, thanks for the reply! That's a very informative link!