Jump to content


Photo

Processing all records that meet a condition


  • Please log in to reply
3 replies to this topic

#1 IWantMyMod

IWantMyMod

    Prisoner

  • Members
  • 15 posts

Posted 18 March 2018 - 07:39 PM

Hello.

 

I'm trying to future out how to process all records that meet some condition.  It seem like I should be able to use a custom filter and the Process function but so far that doesn't seem to work. It applies the custom filter then stops.  Here is the example test code:

unit ApplyCustomScripted;

function Filter(e: IInterface): Boolean;
begin
  Result := GetElementNativeValues(e, 'Record Header\Record Flags\Shield') <> 0;
end;

function Initialize: Integer;
begin
  FilterConflictAll := False;
  FilterConflictThis := False;
  FilterByInjectStatus := False;
  FilterInjectStatus := False;
  FilterByNotReachableStatus := False;
  FilterNotReachableStatus := False;
  FilterByReferencesInjectedStatus := False;
  FilterReferencesInjectedStatus := False;
  FilterByEditorID := False;
  FilterEditorID := '';
  FilterByName := False;
  FilterName := '';
  FilterByBaseEditorID := False;
  FilterBaseEditorID := '';
  FilterByBaseName := False;
  FilterBaseName := '';
  FilterScaledActors := False;
  FilterByPersistent := False;
  FilterPersistent := False;
  FilterUnnecessaryPersistent := False;
  FilterMasterIsTemporary := False;
  FilterIsMaster := False;
  FilterPersistentPosChanged := False;
  FilterDeleted := False;
  FilterByVWD := False;
  FilterVWD := False;
  FilterByHasVWDMesh := False;
  FilterHasVWDMesh := False;
  FilterBySignature := True;
  FilterSignatures := 'ARMO';
  FilterByBaseSignature := False;
  FilterBaseSignatures := '';
  FlattenBlocks := False;
  FlattenCellChilds := False;
  AssignPersWrldChild := False;
  InheritConflictByParent := False; // color conflicts
  FilterScripted := True; // use custom Filter() function

  ApplyFilter;
end;

function Process(e: IInterface): integer;
begin
	AddMessage(GetElementEditValues(e, 'FULL'));
end;

end.

If I want to preform some action on all shields or all axes only what is the best way to do that.


  • 0

#2 zilav

zilav

    Thane

  • Mod Authors
  • PipPipPipPipPipPip
  • 356 posts

Posted 19 March 2018 - 12:52 AM

Depends of what actions you want to perform. This script will leave shield recods only in the records tree https://pastebin.com/raw/HjAQzcU0


  • 0

#3 IWantMyMod

IWantMyMod

    Prisoner

  • Members
  • 15 posts

Posted 19 March 2018 - 11:06 PM

It turns out my example from above does work. Originally I had the "Result := 1;" at the end of the "Initialize" function like so many examples show. By removing it the test script does exactly what I expected it to do. It sets a filter for all shield records then list the name of all shields to the log.

 

A return value other then 0 from Initialize, Process, or Finalize indicates an error which causes the script to stop. So I'm not sure why that's at the end of the Initialize function in example filter scripts.


  • 0

#4 zilav

zilav

    Thane

  • Mod Authors
  • PipPipPipPipPipPip
  • 356 posts

Posted 20 March 2018 - 01:18 AM

Setting Result to anything not zero stops the script, this is intended as the only way to stop the running script programmatically.


  • 0


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users