How to stop messages from scrolling to the speaking unit?

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
blob
Posts: 22
Joined: January 17th, 2009, 12:33 pm

How to stop messages from scrolling to the speaking unit?

Post by blob »

Hello, I would like to know if it is possible for messages to stop centering on the speaking unit. For example:

Code: Select all

[message]
    id=myunit
    message= _ "This is what I want to say."
[/message]
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:

Code: Select all

[message]
    speaker=narrator
    image=data/core/images/portraits/humans/transparent/outlaw.png
    message= _ "This is what I want to say."
[/message]
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:

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 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?
The Cost Of Living (1.8): main thread, feedback thread
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to stop messages from scrolling to the speaking unit?

Post by zookeeper »

Try this:

Code: Select all

image="data/core/images/portraits/humans/transparent/outlaw+female.png"
+ is used for string concatenation, so if you want to use it in a string you need to wrap the whole string in quotes.
blob
Posts: 22
Joined: January 17th, 2009, 12:33 pm

Re: How to stop messages from scrolling to the speaking unit?

Post by blob »

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
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: How to stop messages from scrolling to the speaking unit?

Post by monochromatic »

Also, you can include

Code: Select all

caption= _ "myunit"
to write the unit's name where it should be, like a real message.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to stop messages from scrolling to the speaking unit?

Post by zookeeper »

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:

Code: Select all

[message]
    speaker=narrator
    caption=$my_stored_unit.name
    image=$my_stored_unit.profile
    ...
[/message]
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

[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]
silene
Posts: 1109
Joined: August 28th, 2004, 10:02 pm

Re: How to stop messages from scrolling to the speaking unit?

Post by silene »

Here is an untested Lua version:

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)
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

[message]
  id=myunit
  message= _ "This is what I want to say."
  noscroll=yes
[/message]
blob
Posts: 22
Joined: January 17th, 2009, 12:33 pm

Re: How to stop messages from scrolling to the speaking unit?

Post by blob »

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
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: How to stop messages from scrolling to the speaking unit?

Post by Anonymissimus »

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 startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
silene
Posts: 1109
Joined: August 28th, 2004, 10:02 pm

Re: How to stop messages from scrolling to the speaking unit?

Post by silene »

Anonymissimus wrote:You wrote litteral instead of literal
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: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.
Right. I guess that replacing the unit query by the following line would allow for full SUF support:

Code: Select all

local u = wesnoth.get_units(cfg)[1]
It still doesn't support the whole [message] speaker= handling (namely "unit" and "second_unit"). I am leaving it as an exercise to the reader.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: How to stop messages from scrolling to the speaking unit?

Post by Anonymissimus »

I wrote a lua version which is supposed to support all of the current [message] handling.

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)
I found that setting speaker = nil is neccessary for wesnoth.get_units to find something btw.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Post Reply