How to stop messages from scrolling to the speaking unit?
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.
How to stop messages from scrolling to the speaking unit?
Hello, I would like to know if it is possible for messages to stop centering on the speaking unit. For example:
The above code will first scroll to the speaking unit so that the unit is on-screen, then show the message. Given that I don't want this behavior, a workaround would be:
While this code works the way I'd like provided that the unit's portrait has not changed due to leveling up the unit from its initial state (a problem of its own), it completely fails when loading female versions of unit images, for example:
The above code will show a substitution image instead of the desired image, likely due to the presence of the plus sign. The only workaround for the workaround I could come up with is to include a copy of the desired image in my campaign and name it so that the offending plus sign is removed. The idea of having to create a workaround for a workaround makes me wonder: Is all of this really necessary, or is there a simpler solution to the initial problem that I missed to find in the docs?
Code: Select all
[message]
id=myunit
message= _ "This is what I want to say."
[/message]
Code: Select all
[message]
speaker=narrator
image=data/core/images/portraits/humans/transparent/outlaw.png
message= _ "This is what I want to say."
[/message]
Code: Select all
[message]
speaker=narrator
image=data/core/images/portraits/humans/transparent/outlaw+female.png
message= _ "This is what I want to say."
[/message]
The Cost Of Living (1.8): main thread, feedback thread
Re: How to stop messages from scrolling to the speaking unit?
Try this:
+ is used for string concatenation, so if you want to use it in a string you need to wrap the whole string in quotes.
Code: Select all
image="data/core/images/portraits/humans/transparent/outlaw+female.png"
Re: How to stop messages from scrolling to the speaking unit?
Thanks very much. I already suspected that + had some meaning in WML, just never used string concatenation. Either way, that's one level of workarounds eliminated. How about the other one?
The Cost Of Living (1.8): main thread, feedback thread
-
- Posts: 1549
- Joined: June 18th, 2009, 1:45 am
Re: How to stop messages from scrolling to the speaking unit?
Also, you can include
to write the unit's name where it should be, like a real message.
Code: Select all
caption= _ "myunit"
Re: How to stop messages from scrolling to the speaking unit?
Well, there isn't a convenient general-purpose method for that, but if I needed to do that often then I'd probably do it like this: store the unit you want to talk, and then write your message somewhat like this:
That should work ok if you know the speakers will always have a portrait. If not, then you need to do an extra check for that:
Code: Select all
[message]
speaker=narrator
caption=$my_stored_unit.name
image=$my_stored_unit.profile
...
[/message]
Code: Select all
[if]
[variable]
name=my_stored_unit.profile
equals=$empty
[/variable]
[then]
{VARIABLE my_unit_image "unit_image"}
[/then]
[else]
{VARIABLE my_unit_image $my_stored_unit.profile}
[/else]
[/if]
[message]
speaker=narrator
caption=$my_stored_unit.name
image=$my_unit_image
...
[/message]
Re: How to stop messages from scrolling to the speaking unit?
Here is an untested Lua version:
If I didn't get it too wrong, executing the Lua code above in your scenario should make it possible to write the following WML:
Code: Select all
local old_message
local function new_message(cfg)
if cfg.noscroll then
local u = wesnoth.get_units({id = cfg.id})[1]
cfg = cfg.__literal
cfg.id = nil
cfg.speaker = "narrator"
if u then
local ucfg = u.__cfg
cfg.caption = ucfg.name
cfg.image = ucfg.profile or ucfg.image
end
end
old_message(cfg)
end
old_message = wesnoth.register_wml_action("message", new_message)
Code: Select all
[message]
id=myunit
message= _ "This is what I want to say."
noscroll=yes
[/message]
Re: How to stop messages from scrolling to the speaking unit?
Thanks for the suggestions. I think I'll go with zookeeper's approach and simply create a macro instead of facing something I never heard of with Lua.
The Cost Of Living (1.8): main thread, feedback thread
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: How to stop messages from scrolling to the speaking unit?
silene: You wrote litteral instead of literal, and in case that someone uses silene's code; the tag [message] will not allow for a full SuF this way, only id=, if you use noscroll=yes.
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: How to stop messages from scrolling to the speaking unit?
Thanks, fixed. In my native language, literal takes two t, so it's probably not the last time I will do this mistake.Anonymissimus wrote:You wrote litteral instead of literal
Right. I guess that replacing the unit query by the following line would allow for full SUF support:Anonymissimus wrote:and in case that someone uses silene's code; the tag [message] will not allow for a full SuF this way, only id=, if you use noscroll=yes.
Code: Select all
local u = wesnoth.get_units(cfg)[1]
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: How to stop messages from scrolling to the speaking unit?
I wrote a lua version which is supposed to support all of the current [message] handling.
I found that setting speaker = nil is neccessary for wesnoth.get_units to find something btw.
Code: Select all
local old_message = nil
local function new_message(udArgs)
local bScrollToUnit = udArgs.scroll_to_unit
local wtArgs = udArgs.__literal
if bScrollToUnit == nil then bScrollToUnit = true end
if not bScrollToUnit then
wtArgs.scroll_to_unit = nil
if udArgs.speaker then
if udArgs.speaker == "unit" then wtArgs.id = wesnoth.get_variable("unit.id")
elseif udArgs.speaker == "second_unit" then wtArgs.id = wesnoth.get_variable("second_unit.id")
else wtArgs.id = udArgs.speaker end
end
wtArgs.speaker = nil
local tSpeaker = wesnoth.get_units(wtArgs)[1]
if tSpeaker then
wtArgs.speaker = "narrator"
wtArgs.caption = tSpeaker.name
local wtSpeaker = tSpeaker.__cfg
wtArgs.image = wtSpeaker.profile or wtSpeaker.image
end
end
old_message(wtArgs)
end
old_message = wesnoth.register_wml_action("message", new_message)
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