error deprecation: unit.side has been deprecated - query

Having trouble with the game? Report issues and get help here. Read this first!

Moderator: Forum Moderators

Forum rules
Before reporting issues in this section, you must read the following topic:
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

error deprecation: unit.side has been deprecated - query

Post by Spannerbag »

Hi,
I'm (still :doh:) developing a new campaign and have a query regarding the following warning that appears multiple times in the logfile.

error deprecation: unit.side has been deprecated and will be removed in version 1.17.0.; This returns 0 for side 1 etc and should not be used. Use side_number instead

That's fine but in my logic I also need to know $second_unit.side.
How will this be implemented in 1.17?

All help and suggestions gratefully 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...
dwarftough
Posts: 484
Joined: August 4th, 2019, 5:27 pm

Re: error deprecation: unit.side has been deprecated - query

Post by dwarftough »

Use side_number instead, as it's written.

So $second_unit.side_number, I guess
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: error deprecation: unit.side has been deprecated - query

Post by Spannerbag »

dwarftough wrote: June 26th, 2022, 8:52 pm Use side_number instead, as it's written.

So $second_unit.side_number, I guess
Thanks for the reply, but unless I've misunderstood (quite likely!) it just means second_unit.side has been renamed to second_unit.side_number which seems... odd.
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...
gnombat
Posts: 704
Joined: June 10th, 2010, 8:49 pm

Re: error deprecation: unit.side has been deprecated - query

Post by gnombat »

Spannerbag wrote: June 26th, 2022, 9:12 pm Thanks for the reply, but unless I've misunderstood (quite likely!) it just means second_unit.side has been renamed to second_unit.side_number which seems... odd.
I think what it's trying to say is that, if there are N sides, then side is a number between 0 and N-1, while side_number is a number between 1 and N. (So side_number will equal side + 1.)
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: error deprecation: unit.side has been deprecated - query

Post by Spannerbag »

gnombat wrote: June 26th, 2022, 10:41 pm I think what it's trying to say is that, if there are N sides, then side is a number between 0 and N-1, while side_number is a number between 1 and N. (So side_number will equal side + 1.)
Thanks for the reply, not sure my original post was clear enough, so I'll explain a bit further.

Quoting from side turn event

side turn

Triggers when a side is about to start its turn. Before events of this type trigger, the value of the WML variable side_number is set to the number of the side of the player about to take their turn. This is before any healing takes place for that side, before calculating income, and before restoring unit movement and status.


Unless this behaviour changes in 1.17 then yes, $side_number will cycle through all sides during a full turn (of all sides).
However, $side_number is only ever=the side currently in play (be it human or ai), what I need is to know the side of the second_unit involved in a fight which I don't see how $side_number can ever provide, with the usual caveat that I've understood everything correctly (dangerous assumption, that!).

So, I don't have a problem with unit.side being removed in 1.17 and using $side_number instead.
However in combat a second_unit is just a defending unit (i.e. not playing its turn) and is the same data entity.
So if unit.side is removed then it seems to me that second_unit.side will also be nuked but without an equivalent of $side_number for unit.side.

To reiterate the original log message

error deprecation: unit.side has been deprecated and will be removed in version 1.17.0.; This returns 0 for side 1 etc and should not be used. Use side_number instead

Hope this makes sense and thanks 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...
gnombat
Posts: 704
Joined: June 10th, 2010, 8:49 pm

Re: error deprecation: unit.side has been deprecated - query

Post by gnombat »

There are several things which have similar names but they aren't really related:
  1. The side_number variable mentioned here
  2. The unit and second_unit variables documented here - these have a side key documented here
  3. The unit object inside a Wesnoth Formula Language formula documented here - this has a side key and a side_number key (actually I don't see the side key documented at all)
The deprecation message is referring to #3 - I believe that is the only thing that needs to be fixed.
User avatar
Celtic_Minstrel
Developer
Posts: 2195
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: error deprecation: unit.side has been deprecated - query

Post by Celtic_Minstrel »

Basically what gnombat said. The error message you're seeing has nothing to do $second_unit.side and also has nothing to do with $side_number. It refers to the side used in a formula key, which should be changed to side_number.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: error deprecation: unit.side has been deprecated - query

Post by Spannerbag »

gnombat wrote: June 27th, 2022, 2:08 am There are several things which have similar names but they aren't really related:
  1. The side_number variable mentioned here
  2. The unit and second_unit variables documented here - these have a side key documented here
  3. The unit object inside a Wesnoth Formula Language formula documented here - this has a side key and a side_number key (actually I don't see the side key documented at all)
The deprecation message is referring to #3 - I believe that is the only thing that needs to be fixed.
Celtic_Minstrel wrote: June 27th, 2022, 2:45 am Basically what gnombat said. The error message you're seeing has nothing to do $second_unit.side and also has nothing to do with $side_number. It refers to the side used in a formula key, which should be changed to side_number.
Thanks very much for the detailed explanation, your time and patience are appreciated! :)
My consufion arose because:
- the warning didn't mention it applied specifically to formulas
- none of my formulas reference a unit's side
- several event filters do reference a unit's side

So I presumed the warning was triggered by the presence of unit.side clauses in various [event] statements rather than by the presence of formula code that did not (I'm assuming the warning is issued whenever a formula is encountered rather than specifically when said formula references a unit's side - if not I'm still not fully understanding what's going on but hey, that's normal in my world :roll: ).

Again, many thanks for taking the time, 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...
gnombat
Posts: 704
Joined: June 10th, 2010, 8:49 pm

Re: error deprecation: unit.side has been deprecated - query

Post by gnombat »

Spannerbag wrote: June 27th, 2022, 12:02 pm - none of my formulas reference a unit's side
I'm not sure how it would be possible to get the warning, then - are you sure these warnings are coming from your own add-on, and not from some other add-on?
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: error deprecation: unit.side has been deprecated - query

Post by Spannerbag »

gnombat wrote: June 27th, 2022, 5:20 pm
Spannerbag wrote: June 27th, 2022, 12:02 pm - none of my formulas reference a unit's side
I'm not sure how it would be possible to get the warning, then - are you sure these warnings are coming from your own add-on, and not from some other add-on?
As sure as I can be; I tried loading my campaign and the warning appears when scenario 3 starts (a rather complicated scenario) and the warning timestamp fits...

Here are all the occurrences of "formula" in that scenario:

Code: Select all

    [filter]
      x,y=20,1
      side=1
      formula="alignment = chaotic"
    [/filter]


    [if]
      [have_unit]
        id=Magnus
        formula="hitpoints < max_hitpoints"
      [/have_unit]
    [then]


    [filter_condition]
      [have_unit]
        ability=lifesaving
        formula="hitpoints = max_hitpoints"
        side=1
      [/have_unit]
    [/filter_condition]


      [filter]
        ability=lifesaving
        formula="hitpoints = max_hitpoints"
        side=1
      [/filter]


    [filter]
      side=4
      [filter_location]
        terrain=*^Efm
      [/filter_location]
      formula="hitpoints < max_hitpoints"
    [/filter]
Here's all occurrences of "formula" (case sensitive) in the entire campaign:

scenarios\03_Mushgrots.cfg: formula="alignment = chaotic"
scenarios\03_Mushgrots.cfg: formula="hitpoints < max_hitpoints"
scenarios\03_Mushgrots.cfg: formula="hitpoints = max_hitpoints"
scenarios\03_Mushgrots.cfg: formula="hitpoints = max_hitpoints"
scenarios\03_Mushgrots.cfg: formula="hitpoints < max_hitpoints"
scenarios\04a_Lornstead.cfg: [set_variable] # This is the formula used by the game:
utils\dialogue.cfg: formula="alignment = chaotic"
utils\dialogue.cfg: formula="alignment = chaotic"
_main.cfg: formula="hitpoints <= $goldband.et_hp and hitpoints > 0"
_main.cfg: formula="hitpoints <= $goldband.et_hp and hitpoints > 0"


My only idea is that it's maybe the last formula in the scenario block:

Code: Select all

   [filter]
      side=4
      [filter_location]
        terrain=*^Efm
      [/filter_location]
      formula="hitpoints < max_hitpoints"
    [/filter]
As this refers to side 4 (ai controlled) whereas all the others refer to a player controlled side or no side at all (Magnus, actually player controlled).

However I'm just happy to understand what the issue is, finally!

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
Celtic_Minstrel
Developer
Posts: 2195
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: error deprecation: unit.side has been deprecated - query

Post by Celtic_Minstrel »

Spannerbag wrote: June 27th, 2022, 12:02 pm (I'm assuming the warning is issued whenever a formula is encountered rather than specifically when said formula references a unit's side - if not I'm still not fully understanding what's going on but hey, that's normal in my world :roll: ).
Nope, it only triggers if a formula actually references a unit's side. The fact that you're seeing it means there's a formula somewhere in use in your campaign that references a unit's side.

It's clearly not any of the formulas you've posted, however. It must be in some other code that your scenario is loading. Do you reference other add-ons in that scenario? Or maybe it comes from a macro? There are also places that use formula code where the key is not "formula", for example in unit ability definitions; maybe it's in one of those?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: error deprecation: unit.side has been deprecated - query

Post by Spannerbag »

Celtic_Minstrel wrote: June 28th, 2022, 2:07 am
Spannerbag wrote: June 27th, 2022, 12:02 pm (I'm assuming the warning is issued whenever a formula is encountered rather than specifically when said formula references a unit's side - if not I'm still not fully understanding what's going on but hey, that's normal in my world :roll: ).
Nope, it only triggers if a formula actually references a unit's side. The fact that you're seeing it means there's a formula somewhere in use in your campaign that references a unit's side.

It's clearly not any of the formulas you've posted, however. It must be in some other code that your scenario is loading. Do you reference other add-ons in that scenario? Or maybe it comes from a macro? There are also places that use formula code where the key is not "formula", for example in unit ability definitions; maybe it's in one of those?
Hi,
Losing the will to live... removed most of the add-ons on my system and cleared up various other warnings to declutter the log.
My campaign doesn't reference any other add-ons, the custom abilities are either [dummy] abilities or derivatives of existing ones (e.g. slow) and none have any side dependencies (that I can see).
I've searched the entire campaign directory tree (including the campaign's macros) for "side" and "self" without seeing anything relevant.
I've also scanned various files by eye.
The warning appears after scenario 3's opening dialogue (when objectives are displayed) as far as I can determine by repeatedly viewing the log.
Nothing relevant (that I can see) in prestart, start or side 1 turn 1 - or anywhere else in the .cfg.

The only method I have left is to systematically remove chunks of the code until the error vanishes - but after spending several days finally getting the damn thing working as I wanted I really can't face more bug snagging right now (getting it to work after major surgery isn't straightforward, at least for me).
My eyesight needs a break too; I've gone a bit codeblind.
If there was some way of knowing what code snippet or file was the cause I'd have something to go on...

Clearly I'm missing something and it's probably staring me in the face but I can't see it... :augh:

Thanks for your help and suggestions but the cause of this warning continues to elude me and just now, I need a break... or I'll throw my PC out the window!

If anyone's interested I'm happy to post something here if/when I fix the issue, but that'll probably not be for a few days at least.

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: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: error deprecation: unit.side has been deprecated - WTF?

Post by Spannerbag »

Hi.
Me again. Couldn't let it rest as it was bugging me.
First, I was being too impatient, if I wait a short while the warning appears in the log when the scenario loads (I put a message in prestart and looked at the log and the warning was already there - it isn't there when the previous scenario is active).

Sooo... changed the scenario for a test scenario: warning went away.

Then started deleting code from the scenario and an early delete removed the warning!
It also explains why, under normal circumstances, I'd never have found the source of the warning.

The warning comes from a core macro:

Code: Select all

# Giant spiders
  [side]
    side=7
    team_name=Spiders
    user_team_name= _ "Spiders"
    no_leader=yes
    controller=ai
    recruit=
    color=black
    gold=0
    {NO_INCOME}
    [ai]
      aggression=0.7
      caution=0
      {MODIFY_AI_ADD_CANDIDATE_ACTION 7 main_loop {AI_CA_POISONING}}
    [/ai]
    hidden=yes
  [/side]
Specifically, if I comment out {MODIFY_AI_ADD_CANDIDATE_ACTION 7 main_loop {AI_CA_POISONING}} the warning goes away???

So, anyone got any idea what I'm doing wrong?

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
Pentarctagon
Project Manager
Posts: 5561
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: error deprecation: unit.side has been deprecated - query

Post by Pentarctagon »

It looks like {AI_CA_POISONING} eventually leads to here, which is probably what's generating the warning.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: error deprecation: unit.side has been deprecated - query

Post by Spannerbag »

Pentarctagon wrote: June 28th, 2022, 8:58 pm It looks like {AI_CA_POISONING} eventually leads to here, which is probably what's generating the warning.
Many thanks for taking the trouble to enlighten me :)

Re.: 'unit', index_of(unit.side, enemies) != -1 and unit.abilities

Wow, this means - for once - it ain't something stupid I've done?

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