[message] behaviour check

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.
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

[message] behaviour check

Post by Spannerbag »

Hi,
just spent quite some time nailing down a bit of [message] weirdness.
I was puzzled why a [message] was not highlighting the unit doing the speaking even though I explicity set highlight=yes and scroll=yes.

(Very) long story short: the (side 1) [message] speaker speaks inside a side 2 moveto (i.e. when a side 2 unit moves to a certain location) and happens to have [hides] active (i.e. is not seen by side 2).
So though the [message] is displayed (including the name and image of the speaking unit) the speaking unit's position on the map is not highlighted (presumably because side 2 can't see it).

Is this the intended behaviour? I can see why it makes sense and if so, fair enough.
Just curious :)

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: [message] behaviour check

Post by Toranks »

Have you tried setting side_to=?
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [message] behaviour check

Post by Spannerbag »

Toranks wrote: June 9th, 2023, 9:05 pm Have you tried setting side_to=?
Hi,
I guess you mean side_for?
If so, yes, both in [message] and [scroll_to_unit] (also tried [scroll_to_unit] with highlight=yes)

Event tried this (some comments removed so it isn't a spoiler):
(Vrty is a custom village that works OK).
The dialogue is actually a veiled hint, so I could, I suppose, not bother with the whole thing and just issue a difficulty dependent hint (note) in objectives... or add some klunky dialogue :whistle:

Code: Select all

# Bodge to highlight unit if hidden (side 2 can't see it)
  [event]
    name=moveto
    [filter]
      side=2
      [filter_location]
        terrain=Ds^Vrty
      [/filter_location]
    [/filter]
    [filter_condition]
      [have_location]
        terrain=Ds^Vrty
        count=4
      [/have_location]
    [/filter_condition]
    {FUNT side=1 x,y=$x1,$y1}		# Dialogue delivered by nearest side 1 unit
    [if]
      {VARIABLE_CONDITIONAL funt_found.length greater_than 0}
    [then]				# unit(s) found
      [if]
        [have_unit]
          ability_id_active=ambush
          id=$funt_found.id
        [/have_unit]
      [then]
{DEBUG_MSG (_"About to unhide unit")}
        [unhide_unit]
          id=$funt_found.id
        [/unhide_unit]
        [redraw]
        [/redraw]
        [message]
          speaker=$funt_found.id		# Cleared at scenario end
          message=_"Why would they enter canvas bags on the sands?   What are they for?   What is within?"
#        highlight=yes
#        scroll=yes
        [/message]
        [hide_unit]
          id=$funt_found.id
        [/hide_unit]
        [redraw]
        [/redraw]
      [/then]
      [else]
        [message]
          speaker=$funt_found.id		# Cleared at scenario end
          message=_"Why would they enter canvas bags on the sands?   What are they for?   What is within?"
#        highlight=yes
#        scroll=yes
        [/message]
      [/else]
      [/if]
    [/then]
    [/if]
  [/event]
Didn't work :(
It did go down the hide/unhide path.
Turning off the ai via debug (droid 2 off) and testing highlights an "empty" (contains a hidden unit) hex.
The unhide doesn't reveal the unit?
Seems the engine simply won't reveal a hidden unit when a side that can't see the hidden unit is playing it's turn.
At least if there is a way I haven't found it...

Thanks for taking the trouble to reply, it's appreciated!

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: [message] behaviour check

Post by Toranks »

hide/unhide_unit are different from hides ability, so if they have a hides ability, they still count as hidden even if you use unhide
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: [message] behaviour check

Post by Toranks »

You can try using an [object] that removes the hides ability temporarily, and remove the object when the message ends.
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [message] behaviour check

Post by Spannerbag »

Toranks wrote: June 10th, 2023, 3:59 am hide/unhide_unit are different from hides ability, so if they have a hides ability, they still count as hidden even if you use unhide
Ah... hadn't realised that.
Thanks!

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [message] behaviour check

Post by Spannerbag »

Toranks wrote: June 10th, 2023, 4:04 am You can try using an [object] that removes the hides ability temporarily, and remove the object when the message ends.
Great idea, might give it a go. Thanks.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [message] behaviour check

Post by Spannerbag »

Well, tried it and it almost worked... here's the code:

Code: Select all

# Note: speaking unit will almost certainly be hidden so won't be highlighted on map
#  hence temporarily remove ambush ability with [object] - suggested by Toranks
  [event]
    name=moveto
    [filter]
      side=2
      [filter_location]
        terrain=Ds^Vrty
      [/filter_location]
    [/filter]
    [filter_condition]
      [have_location]
        terrain=Ds^Vrty
        count=4
      [/have_location]
    [/filter_condition]
    {FUNT side=1 x,y=$x1,$y1}		# Dialogue delivered by nearest wose
    [if]
      {VARIABLE_CONDITIONAL funt_found.length greater_than 0}
    [then]				# Own unit(s) found
      [object]
        [filter]
          id=$funt_found.id
        [/filter]
        duration=turn
        id=lsb02_noambush
        silent=yes
        [effect]
          apply_to=remove_ability
          [abilities]
            [hides]
              id=ambush
            [/hides]
          [/abilities]
        [/effect]
      [/object]
      [redraw]
      [/redraw]
      [message]
        speaker=$funt_found.id		# Cleared at scenario end
        message=_"Why do they enter canvas bags?   What is within?"
        image_pos=right
        mirror=yes
        highlight=yes
        scroll=yes
        side_for=1
      [/message]
      [remove_object]
        id=$funt_found.id
        object_id=lsb02_noambush
      [/remove_object]
    [/then]
    [/if]
  [/event]
The unit becomes visible and reverts back to hiding (ambush) afterwards.
But no highlight :annoyed:

I've spent too long on this already and can't think of anything else to try so will revert back to plain old message and no highlight.
Ah well, it was worth a shot.

Thanks Toranks for the suggestion.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: [message] behaviour check

Post by Toranks »

That's not what I expected. It's weird, really. Let's see if someone else can think of what can happen.
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [message] behaviour check

Post by Spannerbag »

Toranks wrote: June 10th, 2023, 11:22 pm That's not what I expected. It's weird, really. Let's see if someone else can think of what can happen.
Also, IIRC (tried so many combinations that it's all got mixed up in my head) if I explicity highlight the hex first (using [scroll_to] or [scroll_to_unit]) then that works but that highlight goes away when the [message] is displayed.
(I added a [delay] after the highlight to check it was working).

One thing I haven't tried is to manually craft the message with speaker=narrator, but I suspect I'll have the same highlighting issue...

The [message] does it's main job of issuing a vague hint to the player, it's just a pity that it won't be obvious that the speaking unit is the one nearest to where the event of interest occurred. And I wrote a little macro to find the correct unit (but it's used elsewhere as well so no great loss).

Ah well, sometimes when I revisit gnarly problems I have new ideas so I'll move on for now (I thought I'd properly tested these early scenarios already and was testing some big retrofits to this campaign - #1 - as I'd not touched it for ages as I'd been caught up in campaign #2 and had since learned/coded a load of additional useful stuff :augh:).

Thanks again for taking the trouble to reply.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
lhybrideur
Posts: 357
Joined: July 9th, 2019, 1:46 pm

Re: [message] behaviour check

Post by lhybrideur »

BTW, I would by interested in your "finding nearest unit" macro.
I wanted to do that earlier but found no easy way to do it.
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [message] behaviour check

Post by Spannerbag »

lhybrideur wrote: June 12th, 2023, 9:04 am BTW, I would by interested in your "finding nearest unit" macro.
I wanted to do that earlier but found no easy way to do it.
Yeah, no worries - I was going to package up all my various bits and bobs into a small library and publish it as a (hopefully) useful aid for coders.
However if you want the code, no problem.

Style note: in some places I have deeply indented lines so use 2 spaces rather than 4 throughout (but when published the system correctly formats everything so no problem).

First the macro, put this in your macros folder:

Code: Select all

# --- Find unit(s) nearest to location(s), aka funt ---
#
# Event to find nearest unit(s) to location
# Does not consider unit's movement (maximum or current)
# Searches by increasing the radius
#
# Variables:
# - funt_units   an array of stored units
# - funt_locs	 an array of stored locations
#
# Return value:
# - funt_found   nearest unit(s), can be empty (length=0)
#
#define FUNT_EVENT
[event]
  name=find_unit_nearest_to
  first_time_only=no
  [filter_condition]
    {VARIABLE_CONDITIONAL funt_units.length greater_than 0}
    {VARIABLE_CONDITIONAL funt_locs.length greater_than 0}
  [/filter_condition]
  [store_unit]			# Sanity check: see if unit(s) found in funt_locs
    [filter]			#  if so, use one of them and skip while loop below
      find_in=funt_units
      [filter_location]
        find_in=funt_locs
      [/filter_location]
    [/filter]
    variable=funt_found
  [/store_unit]
  [store_map_dimensions]
    variable=funt_map
  [/store_map_dimensions]
  {VARIABLE largest_dimension $funt_map.height}
  [if]
    {VARIABLE_CONDITIONAL funt_map.width greater_than $funt_map.height}
  [then]
    {VARIABLE largest_dimension $funt_map.width}
  [/then]
  [/if]
  {VARIABLE funt_radius 1}
  [while]
    {VARIABLE_CONDITIONAL funt_found.length less_than 1}
    {VARIABLE_CONDITIONAL funt_radius less_than_equal_to $largest_dimension}
    [do]
      [store_unit]
        [filter]
          find_in=funt_units
          [filter_location]
            find_in=funt_locs
            radius=$funt_radius
          [/filter_location]
        [/filter]
        variable=funt_found
      [/store_unit]
      {VARIABLE_OP funt_radius add 1}
    [/do]
  [/while]
  {CLEAR_VARIABLE funt_map,funt_radius,largest_dimension}
[/event]
#
[event]
  name=scenario end
  {CLEAR_VARIABLE funt_found}
[/event]#enddef

# Macro to setup and fire find_unit_nearest_to event
#
#define FUNT FILTER FILTER_LOC
[store_unit]
  [filter]
    {FILTER}
    [not]
      x,y=recall,recall
    [/not]
  [/filter]
  variable=funt_units
[/store_unit]
[store_locations]
  {FILTER_LOC}
  variable=funt_locs
  include_borders=no
[/store_locations]
[fire_event]
  name=find_unit_nearest_to
[/fire_event]
{CLEAR_VARIABLE funt_locs,funt_units}
#enddef
Then in a scenario, you need to include the above somewhere, i.e.:

Code: Select all

# Needed to make funt macro work
  {FUNT_EVENT}
Then, finally, to actually use the thing simply specify unit(s) and location(s) via the appropriate filters:

Code: Select all

    {FUNT side=1 x,y=$x1,$y1}		# Dialogue delivered by nearest wose
    [if]
      {VARIABLE_CONDITIONAL funt_found.length greater_than 0}
    [then]				# Own unit(s) found
... code if unit(s) found ...
funt_found is an array so:
  • there may be more than 1 unit returned if 2+ units are equidistant from the location(s) specified,
  • no units may be found hence the need to check for length>0
  • $funt_found.id is actually $funt_found[0].id assuming 1+ unit(s) found.
All the variables are cleared within the routine so there's no need for any housekeeping :)

Coding note: did it this way rather than shove everything into FUNT to save WML bloat.
(I.e. what's repeated is a shortish variable assignment and event call rather than all the stuff in the event).

If you improve or extend my efforts please let me know or - even better - share it here!

Hope this helps!

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: [message] behaviour check

Post by beetlenaut »

I couldn't replicate the highlighting problem you are having in BfW 1.16 or 1.17 using the code you posted above. The unit highlighted correctly when I tried it. I had to remove some pieces of the code because I didn't have the variable, macro, or terrain, but I can't see how that would make a difference. Maybe the problem is not in this code but in the hidden unit's code.

If you want to work on this more, I would suggest making a small test case. (I use WML_Guide for this. In this case, I made a prestart event that stuck an Elvish Avenger in the woods and stored it in a variable called $funt_found.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [message] behaviour check

Post by Spannerbag »

beetlenaut wrote: June 12th, 2023, 5:26 pm I couldn't replicate the highlighting problem you are having in BfW 1.16 or 1.17 using the code you posted above. The unit highlighted correctly when I tried it. I had to remove some pieces of the code because I didn't have the variable, macro, or terrain, but I can't see how that would make a difference. Maybe the problem is not in this code but in the hidden unit's code.

If you want to work on this more, I would suggest making a small test case. (I use WML_Guide for this. In this case, I made a prestart event that stuck an Elvish Avenger in the woods and stored it in a variable called $funt_found.)
Thanks for that, good to know.
The unit is of a custom race but is simply a clone of the normal wose race to allow traits.
[message] works fine elsewhere so I'll have a go at comparing the custom unit vs a regular wose and see if I can nail it down.

Thanks for taking the trouble to run a few tests, much appreciated.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 505
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [message] behaviour check

Post by Spannerbag »

Quick update:

Reimplemented the custom unit types in my test campaign and they issue messages perfectly.
However I do now know what I am seeing.
The enemy (side 2) is ai controlled and that works fine.
However if the enemy controller is human then the units cannot be seen on that turn.
For hidden units that's what I'm seeing, unhidden unit are fine.

Unfortunately the problematic scenario does a lot of stuff in prestart and start.
The enemy side has no_leader=yes then4 (!) are created in start, 3 wander off and 4th and last one created moves to a keep.
The enemy leaders are removed using store_unit with kill=yes.

I have approximated this in my test campaign and so far I've not found the issue.
I'm probably looking in the wrong place :roll:

Will do some more later, have to leave this for now.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Post Reply