[closed] Where is current attack weapon stored/how it's marked?

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

Moderator: Forum Moderators

User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

[closed] Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

Hi
I can't find where the current attack weapon is in the data structure (while attacking).
Last edited by ZombieKnight on March 31st, 2024, 12:33 pm, edited 1 time in total.
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

(The existing code)

Code: Select all

local function printTable(table, indent)
    indent = indent or 0
    for key, value in pairs(table) do
        if type(value) == "table" then
            std_print(string.rep("  ", indent) .. key .. ":\n")
            printTable(value, indent + 1)
        else
            std_print(string.rep("  ", indent) .. key .. ": " .. tostring(value) .. "\n")
        end
    end
end
printTable(wml.variables["unit[0].attack[0]"])
(prints units first attack)
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

Thanks,
thats what I'm looking for but I can't find it when I use

Code: Select all

printTable(wml)
I can't see it there (tryied even with [inspect] inside attacker hits event).
Is it stored somewhere else?
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Ravana
Forum Moderator
Posts: 3012
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Where is current attack weapon stored/how it's marked?

Post by Ravana »

Automatically stored variables are only stored into variable during first time you access it. Example https://github.com/ProditorMagnus/Agele ... e.cfg#L125
User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

Thanks!
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

It works!
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Celtic_Minstrel
Developer
Posts: 2235
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Where is current attack weapon stored/how it's marked?

Post by Celtic_Minstrel »

Ravana has linked you to the wrong wiki page. What you're looking for is documented here. Specifically, you're looking for wesnoth.current.event_context.weapon and/or wesnoth.current.event_context.second_weapon.

The way Ravana described is the WML way. It'll still work to use that in Lua, but it's not the Lua way.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

Oh thanks, I'm new to wesnoth lua...
I'm actually using the "wml." way a lot is it wrong?
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Celtic_Minstrel
Developer
Posts: 2235
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Where is current attack weapon stored/how it's marked?

Post by Celtic_Minstrel »

It's not technically wrong. It's probably less efficient or something, though that rarely actually matters. If you use wml.variables.unit or whatever, the weapon needs to be serialized into a WML variable, which normally takes a little bit of time. If you use wesnoth.current.event_context.unit, I believe it just gives you the Lua unit proxy without serializing anything. It probably makes less of a difference with weapon, as from what I recall that's just a WML table anyway.
Last edited by Celtic_Minstrel on February 2nd, 2024, 6:26 pm, edited 1 time in total.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

Whats event_context and current.event_context?
What it's stored in wesnoth.? (are there stored even on-board units?)
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Celtic_Minstrel
Developer
Posts: 2235
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Where is current attack weapon stored/how it's marked?

Post by Celtic_Minstrel »

wesnoth.current.event_context is all the information about the currently-running event.

I don't understand what the second line of your post means.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

Are there stored on-board units in wesnoth.?
If they are, can I change things saved there(directly, using lua, not store/unstore unit)
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Ravana
Forum Moderator
Posts: 3012
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Where is current attack weapon stored/how it's marked?

Post by Ravana »

As soon as you store it, you do not have unit anymore, you have copy of its wml.

In Lua there is support for proxy units which let you change without storing. https://wiki.wesnoth.org/LuaAPI/wesnoth ... .transform has example.
User avatar
ZombieKnight
Posts: 154
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Where is current attack weapon stored/how it's marked?

Post by ZombieKnight »

Thanks, so

Code: Select all

 wesnoth.units.transform(my_unit_stored_from_map, "Ghoul") 
changes a on-map unit that has same x,y as a unit stored in my_unit_stored_from_map to type Ghoul?
Or has every parameter to be exactly same as the on-map unit?
I had saurian in profile before, but I've merged my discord profile with forum one...
Post Reply