[solved] attacker_weapon_index

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

User avatar
Celtic_Minstrel
Developer
Posts: 2371
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [solved] attacker_weapon_index

Post by Celtic_Minstrel »

A for loop to get the index is probably best in any case, as it means you can loop over unit.attacks (using ipairs()) instead of wml.child_range(unit.__cfg, "attack").
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
white_haired_uncle
Posts: 1456
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: [solved] attacker_weapon_index

Post by white_haired_uncle »

Celtic_Minstrel wrote: June 27th, 2024, 12:37 pm A for loop to get the index is probably best in any case, as it means you can loop over unit.attacks (using ipairs()) instead of wml.child_range(unit.__cfg, "attack").
This has always bugged me (attacks vs [attack]+), though I can't quite put a finger on it. It's just [attack] in [unit] or the gamestate_inspector, so if I didn't know any better, where would I come up with unit.attacks[x] ? I mean, it's kind of sort of maybe intuitive, at least in English, but it seems to me like something you'd hit upon by accident (or example) and then just "go with" because you've seen it before.

And then there's the use of "weapon" in places like attacker_hits, where it's really referring to the attack?
Speak softly, and carry Doombringer.
gnombat
Posts: 892
Joined: June 10th, 2010, 8:49 pm

Re: [solved] attacker_weapon_index

Post by gnombat »

white_haired_uncle wrote: June 27th, 2024, 3:23 pm This has always bugged me (attacks vs [attack]+), though I can't quite put a finger on it. It's just [attack] in [unit] or the gamestate_inspector, so if I didn't know any better, where would I come up with unit.attacks[x] ?
It looks like the official documentation for it is here:

https://wiki.wesnoth.org/LuaAPI/types/unit#Unit_sub-tables
Post Reply