[closed] Where is current attack weapon stored/how it's marked?
Moderator: Forum Moderators
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
[closed] Where is current attack weapon stored/how it's marked?
Hi
I can't find where the current attack weapon is in the data structure (while attacking).
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...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Where is current attack weapon stored/how it's marked?
(The existing code)
(prints units first attack)
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]"])
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Where is current attack weapon stored/how it's marked?
Thanks,
thats what I'm looking for but I can't find it when I use
I can't see it there (tryied even with [inspect] inside attacker hits event).
Is it stored somewhere else?
thats what I'm looking for but I can't find it when I use
Code: Select all
printTable(wml)
Is it stored somewhere else?
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
Re: Where is current attack weapon stored/how it's marked?
Automatically stored variables are only stored into variable during first time you access it. Example https://github.com/ProditorMagnus/Agele ... e.cfg#L125
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Where is current attack weapon stored/how it's marked?
Thanks!
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Where is current attack weapon stored/how it's marked?
It works!
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Where is current attack weapon stored/how it's marked?
Ravana has linked you to the wrong wiki page. What you're looking for is documented here. Specifically, you're looking for
The way Ravana described is the WML way. It'll still work to use that in Lua, but it's not the Lua way.
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.
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Where is current attack weapon stored/how it's marked?
Oh thanks, I'm new to wesnoth lua...
I'm actually using the "wml." way a lot is it wrong?
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...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Where is current attack weapon stored/how it's marked?
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.
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Where is current attack weapon stored/how it's marked?
Whats event_context and current.event_context?
What it's stored in wesnoth.? (are there stored even on-board units?)
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...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Where is current attack weapon stored/how it's marked?
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.
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Where is current attack weapon stored/how it's marked?
Are there stored on-board units in wesnoth.?
If they are, can I change things saved there(directly, using lua, not store/unstore unit)
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...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
Re: Where is current attack weapon stored/how it's marked?
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.
In Lua there is support for proxy units which let you change without storing. https://wiki.wesnoth.org/LuaAPI/wesnoth ... .transform has example.
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Where is current attack weapon stored/how it's marked?
Thanks, so 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?
Code: Select all
wesnoth.units.transform(my_unit_stored_from_map, "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...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills