View Single Post
Mathias
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 13,207

Old October 7th, 2022, 12:25 PM
I'm not sure if that's the entire reason for the field not found - there could be a second error I didn't see when looking at your code.

This should work:
myRef = tagids[Target1.?,"|"]
myRef = replace(myRef,"Target1","Reference1",0)
perform this.field[usrChosen1].setchosen[Ability,myRef,hero]

Oh, actually, you had an error in myRef - you had a ",", but you're building a tag expression, so you want "|" to mean "OR". The code you were writing would have failed at the foreach step if there was more than one Target1 tag, because it wouldn't have been a properly formatted tag expression.

Also, I'd add a safety check at the beginning - test that there is exactly 1 Target1 tag before building your variable and running setchosen, because if there's 0, then things will fail, and if there's 2, then it's mostly random which choice will be selected (although the choice is likely to be consistent for that character loaded at that time, but it could change if you build a new test character, or even if you save and load your test character). You can even add a notify if there's more than one - that's a combo of abilities you didn't expect to be able to happen, but the user made it happen anyway.

HL's error reporting can sometimes fail in ways that pretend the error is earlier than expected - I think what's happening here is that the real error is "the tag expression is not formed as a tag expression", but that's not specifically checked for, so it's just stored as "I found an error on this line", which gets traced back up the chain of transitions - setchosen, back to field, back to "this", and the field is where HL notices "this has been flagged as an error" and then it just defaults to the standard error report for errors about fields.

Last edited by Mathias; October 7th, 2022 at 12:31 PM.
Mathias is online now   #8 Reply With Quote