[harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
Moderator: Forum Moderators
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.
[harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
Hello,
I spotted a rather mysterious Lua error message concerning a [harm_unit] action. Here is a screenshot of the error: And here is the [harm_unit] that definitely fired just before this occured:
player_lead, and ai_lead are existing leader units at the time. Ftf is an existing custom location.
The action is supposed to harm every unit that is not the leaders and are not standing in villages or in Ftf. And usually it does it perfectly.
This is Wesnoth 1.14.5 on Debian.
That's all I'm afraid. This event happens every turn (turn refresh), and there weren't any issues with it ever, nor have been since... so this only happened once. But it did, so it potentially can again. What could this be? (can it be related to me using still 1.14.5...?)
Thanks
I spotted a rather mysterious Lua error message concerning a [harm_unit] action. Here is a screenshot of the error: And here is the [harm_unit] that definitely fired just before this occured:
Code: Select all
[harm_unit]
[filter]
[not]
id=player_lead,ai_lead
[/not]
[not]
[filter_location]
terrain=Ftf,*^V*
[/filter_location]
[/not]
[/filter]
delay=0
amount=4
kill=yes
fire_event=no
animate=no
experience=no
[/harm_unit]
The action is supposed to harm every unit that is not the leaders and are not standing in villages or in Ftf. And usually it does it perfectly.
This is Wesnoth 1.14.5 on Debian.
That's all I'm afraid. This event happens every turn (turn refresh), and there weren't any issues with it ever, nor have been since... so this only happened once. But it did, so it potentially can again. What could this be? (can it be related to me using still 1.14.5...?)
Thanks
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
Error message gives line 163, which just accesses unit location. Before that there is some logic about poisoned/slowed/petrified/unhealable status.
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
@WhiteWolf If you have a savefile that reproduces this, feel free to upload it, that might help someone figure it out.
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
See that's the thing - no matter how hard I try I can't reproduce it. I try reloading the same save, try to move my units exactly as I did - the AI probably won't though - and nothing. It works just fine. I'm dumbstruck - I can't see what can possibly go wrong here, and I am failing to reproduce it...
Here it is though.
But what does it mean? What is an 'unknown unit' then? Did a location somehow pass the filter that had no unit on it? But that is plain impossible, based on the filter.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
Based on code I can only guess that one of those units was broken by adding status. Some lines before, in status block, same unit location was working.
Something like unit_placed event might be able to do it.
Something like unit_placed event might be able to do it.
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
Could extract_unit/put_unit pair in there have invalidated the variable somehow?
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
Well, I tried manually adding different (even some custom) statuses to several units, couldn't reproduce the issue.
I'm afraid I'm not familiar with the lua code behind the tag So... I don't know.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
- Celtic_Minstrel
- Developer
- Posts: 2211
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
As for the precise meaning of the error, it means the Lua unit proxy did not refer to an actual unit. This situation is detectible by testing the
The source of the error in the actual code would be here. Maybe that information can help someone else track down what's going on.
u.valid
key on the unit; it'll be nil
in this situation, otherwise it'll return a string. Off the top of my head I'm not quite sure how the situation could come to pass... possibly if you called erase_unit
at some point or if the unit died since the proxy was created or something? It might be possible that extract_unit
would do it, as that function returns the extracted unit (with u.valid == "private"
), so if you passed a unit as argument, that unit may become invalidated. That said, I'd consider it a bug if that happens.The source of the error in the actual code would be here. Maybe that information can help someone else track down what's going on.
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
(Sorry for the late answer, I did not notice this post until now).
I'm afraid I don't quite understand all of that, because I'm not familiar with how lua works. I only used the tag in OP.
All I can say is that since then, I could not reproduce the issue, not once, despite having played the same scenario many times.
I'm afraid I don't quite understand all of that, because I'm not familiar with how lua works. I only used the tag in OP.
All I can say is that since then, I could not reproduce the issue, not once, despite having played the same scenario many times.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
- Celtic_Minstrel
- Developer
- Posts: 2211
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)
I guess it's probably a rare bug in the
[harm_unit]
tag's implementation, so it would need to be fixed there... which is something we need to worry about, not you.