Purpose of [object]

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Jovycos
Posts: 59
Joined: October 12th, 2007, 4:15 pm
Location: Germany

Purpose of [object]

Post by Jovycos » September 3rd, 2011, 12:21 am

Hi!

I just wondered why there is the [object] tag in Wesnoth. It sounds like a tag for handling all changes made to the unit, but they cannot be removed, so, why aren't there simply direct changes instead of [object]s in the [modifications]-section?

Regards
Full of Nerdiness...

User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Purpose of [object]

Post by Sapient » September 3rd, 2011, 12:50 am

quick answer: objects have effects that are automatically applied when the unit advances (or transforms), but any direct modifications will be lost.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."

Jovycos
Posts: 59
Joined: October 12th, 2007, 4:15 pm
Location: Germany

Re: Purpose of [object]

Post by Jovycos » September 3rd, 2011, 1:39 am

Okay, I have written a Lua script “reassembling” a unit, it removes everything except of temporary data (x, y, moves, hitpoints, attacks_left, experience, status, variables), basic data which should not be changed by effects (type, gender, variation, id, underlying_id, name, side) and modifications. Now I can remove an object, then reassemble the unit, do you see any down side of that approach to remove objects?
Full of Nerdiness...

User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Purpose of [object]

Post by Sapient » September 3rd, 2011, 3:15 am

I'm not sure what exactly you are trying to do, or why you feel it needs to be done, or why you feel it needs to be done in Lua. So I'll just share a few random thoughts that may or may not help you. These are not indisputable facts, they are just my own thoughts:

Objects and direct modification are two separate systems for unit modification and mixing the two approaches is bad. The WML author should choose objects for their simplicity or direct unit modification for complete control, not both. If you, as the WML author, find yourself wanting to remove objects, then you probably should have gone with direct unit modification to have the finer degree of control.

A simplistic approach for removing objects is probably going to involve rebuilding the unit from the unit_type, which will of course destroy any direct unit modifications in the process. (FYI, a rebuild can be triggered by "leveling up" the unit into its own type.)

A more complex approach for removing objects would involve storing some sort of undo instructions. But even then, ambiguous situations would arise.

Consider the case of a strong, resilient spearman that has been wounded to half of its maximum hitpoints. Next it finds an object that fully heals it. Next it finds an object that transforms it into a vampire bat. After some fighting it levels up into Blood Bat. Again it is wounded to half of its maximum hitpoints. Finally, an event triggers that randomly selects one of the two objects and removes it.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."

Jovycos
Posts: 59
Joined: October 12th, 2007, 4:15 pm
Location: Germany

Re: Purpose of [object]

Post by Jovycos » September 3rd, 2011, 11:00 am

How to tell a unit to level up to itself? Encapsulating all modifications in objects is reasonable in my opinion. I want to avoid undo-information, that is complicated and error-prone.

PS:
wesnoth.transform_unit?
Full of Nerdiness...

User avatar
Elvish_Hunter
Forum Moderator
Posts: 1406
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Purpose of [object]

Post by Elvish_Hunter » September 3rd, 2011, 5:20 pm

Jovycos wrote:How to tell a unit to level up to itself?
From http://wiki.wesnoth.org/UnitTypeWML:[qu ... dvances_to:[/b] ... the special value 'null' says that the unit does not advance but gets an AMLA instead.[/quote]
Jovycos wrote:PS:wesnoth.transform_unit?
No, this isn't the purpose of wesnoth.transform_unit. Transforming a unit should keep all its [object] tags.
Current maintainer of these add-ons:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Purpose of [object]

Post by zookeeper » September 3rd, 2011, 5:33 pm

He meant how to make a single unit, not the unit type, to level up to itself. I don't know how to do it in lua, but in WML you'd usually want to do it with the ADVANCE_UNIT or TRANSFORM_UNIT macro in data/core/macros/unit-utils.cfg.

User avatar
Elvish_Hunter
Forum Moderator
Posts: 1406
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Purpose of [object]

Post by Elvish_Hunter » September 3rd, 2011, 5:40 pm

zookeeper: on 1.9, advances_to is one of the proxy fields that can directly be modified without accessing the .__cfg table or using wesnoth.put_unit. Untested:

Code: Select all

local unit = wesnoth.get_units( { } )[1] -- filter between the brackets
unit.advances_to = "null"
Also, a code like this should work, on 1.9:

Code: Select all

[modify_unit]
    [filter]
        #SUF
    [/filter]
    advances_to=null
[/modify_unit]
Current maintainer of these add-ons:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons

Jovycos
Posts: 59
Joined: October 12th, 2007, 4:15 pm
Location: Germany

Re: Purpose of [object]

Post by Jovycos » September 3rd, 2011, 8:10 pm

@Elvish_Hunter
That does not help.

unit-utils.cfg:

Code: Select all

#define ADVANCE_UNIT FILTER ID_STRING
    [modify_unit]
        [filter]
            {FILTER}
        [/filter]
        type={ID_STRING}
    [/modify_unit]
#enddef
And I do not want to remove all objects

It seems to work with modifying unit.__cfg (remove objects there) and then calling wesnoth.create_unit, unit gets recreated, all unit-proxy-objects get invalid, but it works.
Full of Nerdiness...

User avatar
Drakefriend
Posts: 436
Joined: September 27th, 2009, 12:57 pm
Location: Wandering from one world to another
Contact:

Re: Purpose of [object]

Post by Drakefriend » September 3rd, 2011, 8:17 pm

You could also let it advance to the unit type in question, just this time to the same unit type the unit is a member of? That would have the advantage of allowing later levels the unit could gain, and the unit would not have been strengthened by the AMLA. I do not have any experience in scenario writing, though...
After far too long an absence, I have returned.
According to the quiz 100% Silver Mage (85% Archmage, 75% Shyde, 67% Flameheart and Ancient Wose,58% Assassin, Troll Warrior and Berserker). And my top score is exactly how I see myself.

Post Reply