[solved] unit.__cfg.advances_to
Moderator: Forum Moderators
- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
[solved] unit.__cfg.advances_to
I am surrounding. can someone provide me with a function to check if a unit can advance to another unit or to null?
I tried many different methods but I am stock.
I tried many different methods but I am stock.
Last edited by hermestrismi on August 27th, 2024, 6:40 am, edited 1 time in total.
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: unit.__cfg.advances_to
You have
unit.advances_to
(__cfg
not needed here, and in fact it makes it worse), which is a list of possible advancements, so you can iterate through that list and compare each element to your reference.- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: unit.__cfg.advances_to
I already tried that. I use print to check the resulted string and even type(val) to check if it is a string or nil.Celtic_Minstrel wrote: ↑July 20th, 2024, 6:47 am You haveunit.advances_to
(__cfg
not needed here, and in fact it makes it worse), which is a list of possible advancements, so you can iterate through that list and compare each element to your reference.
when a unit have advances_to "null", I get an empty space which I can't tell if it is a string or not.
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: unit.__cfg.advances_to
See if this helps get you started
That will only handle a single advancement, though. If you need to see if the unit has a path to advance to something that takes more than one advancement you'll have to expand the search, probably using wesnoth.unit_types on the results.
Code: Select all
wesnoth.interface.add_chat_message(string.format("%s advances to:",unit.name))
if #unit.advances_to == 0 then
wesnoth.interface.add_chat_message("Nothing!")
else
for _,v in pairs(unit.advances_to) do
wesnoth.interface.add_chat_message(string.format("\t%s",v))
end
end
Speak softly, and carry Doombringer.
- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: unit.__cfg.advances_to
a small workaŕound I found is this (sorry to post a picture instead of code).
If I didn't use else, units with more than one advances will be a match, too.
this way I get units with only "null" as advancement
If I didn't use else, units with more than one advances will be a match, too.
this way I get units with only "null" as advancement
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: unit.__cfg.advances_to
image
Last edited by hermestrismi on July 20th, 2024, 9:51 am, edited 1 time in total.
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
Re: unit.__cfg.advances_to
Please use the
[code]
tag to copy-and-paste instead of pasting a screenshot.- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: unit.__cfg.advances_to
I m sorry for that. I can't plug or send anything directly from the pc for now. I will delete the image and post the code later
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: unit.__cfg.advances_to
You're trying to use tostring on a table? I don't think that's going to do what you want.
Also, I note you say "advancement = ". "advancement" is singular, which makes me wonder if you are considering the fact that a unit can have multiple advancements.
Also, I note you say "advancement = ". "advancement" is singular, which makes me wonder if you are considering the fact that a unit can have multiple advancements.
Speak softly, and carry Doombringer.
- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: unit.__cfg.advances_to
I was surprised that it worked, too.white_haired_uncle wrote: ↑July 20th, 2024, 9:50 am You're trying to use tostring on a table? I don't think that's going to do what you want.
before that, I used other methods and it didn't work.
now, I have a table containing only units with advances not null. all what I need now, is comparing the two table (table for all units on map and units with advances_to not null) then extract the rest.
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: unit.__cfg.advances_to
Code: Select all
function Books_Inventory_Configuration()
-- first step, loop over all units of side 1 (units on map) and extract units that have 'advances_to=null' (in the __.cfg files of the type of unit). then build a table from the matching units.
local eligible_units = {}
local legal_units = {}
local inadequate_units = {}
local value = ""
-- Loop over all units on side 1 (units on the map)
local units = wesnoth.units.find_on_map{ side = 1}
for _, unit in ipairs(units) do
table.insert(eligible_units, {
type = unit.type,
experience = unit.experience,
id = unit.id,
name = unit.name,
advancement = tostring(unit.__cfg.advances_to),
image = unit.__cfg.image
})
end
for _, eligible_unit in ipairs(eligible_units) do
value = eligible_unit.advancement
if value == "" then
else
table.insert(inadequate_units, {
id = eligible_unit.id
})
print("id: " .. eligible_unit.id)
print("--------------------")
end
end
end
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: unit.__cfg.advances_to
the main problem for my point of view is that 'advances_to=null' give an empty space when use 'unit.advance_to' or 'unit.__cfg.advances_to'. in both cases, that space is not a nil value neither a "null" string nor a 'string'. what is it exactly?
note: I use advancement without 's' because I will use a table of 'advancements' later and was afraid that the two word may cause a conflict in my mind
note: I use advancement without 's' because I will use a table of 'advancements' later and was afraid that the two word may cause a conflict in my mind

The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: unit.__cfg.advances_to
If you just want to check for advances_to==null, #unit.advances_to==0 should do it.
There's a button in the lower left corner of the lua console screen that will allow you to copy to clipboard so you don't have to use photos.
There's a button in the lower left corner of the lua console screen that will allow you to copy to clipboard so you don't have to use photos.
Speak softly, and carry Doombringer.
- hermestrismi
- Posts: 730
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: unit.__cfg.advances_to
thanks. my pc is very slow. a pic from the phone is faster for me but I will try to not use them too muchwhite_haired_uncle wrote: ↑July 20th, 2024, 10:06 am If you just want to check for advances_to==null, #unit.advances_to==0 should do it.
There's a button in the lower left corner of the lua console screen that will allow you to copy to clipboard so you don't have to use photos.
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin