I'm trying to write a script that will export particular data from an NPC to a file for further processing. However, the program exhibits strange behaviour when I try to access some of the NPC's elements. Getting simple fields and printing them as strings works fine, but it goes wrong as soon as I try to get non-string elements.
In particular, I have the following script:
{
Export list of records
------------------------
Hotkey: Ctrl+Alt+Shift+E
}
unit UserScript;
const sRecordsToSkip = 'REFR,PGRD,PHZD,ACHR,NAVM,NAVI,LAND';
function Initialize: integer;
begin
// Do nothing
end;
function Process(e: IInterface): integer;
var
_aidt : IwbElement;
_assigned : string;
begin
if Pos(Signature(e), sRecordsToSkip) <> 0 then begin
Exit;
end;
if not ElementExists(e, 'AIDT') then begin
Exit;
end;
_aidt := ElementByName(e, 'RNAM');
_assigned := Assigned(_aidt);
AddMessage('Is assigned? ' + _assigned);
end;
function Finalize: integer;
begin
// Do nothing
end;
end.
Whenever I run this script, the message "Is assigned? False" is printed. I do not understand how this is possible: I checked whether the element existed, but after getting it, it is Nil.
Question
FWDekker
I'm trying to write a script that will export particular data from an NPC to a file for further processing. However, the program exhibits strange behaviour when I try to access some of the NPC's elements. Getting simple fields and printing them as strings works fine, but it goes wrong as soon as I try to get non-string elements.
In particular, I have the following script:
{ Export list of records ------------------------ Hotkey: Ctrl+Alt+Shift+E } unit UserScript; const sRecordsToSkip = 'REFR,PGRD,PHZD,ACHR,NAVM,NAVI,LAND'; function Initialize: integer; begin // Do nothing end; function Process(e: IInterface): integer; var _aidt : IwbElement; _assigned : string; begin if Pos(Signature(e), sRecordsToSkip) <> 0 then begin Exit; end; if not ElementExists(e, 'AIDT') then begin Exit; end; _aidt := ElementByName(e, 'RNAM'); _assigned := Assigned(_aidt); AddMessage('Is assigned? ' + _assigned); end; function Finalize: integer; begin // Do nothing end; end.Whenever I run this script, the message "Is assigned? False" is printed. I do not understand how this is possible: I checked whether the element existed, but after getting it, it is Nil.
What's going wrong here? Any help is appreciated.
Edited by FWDekker3 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now