Page 1 of 1

Ordering Entites, DCAL Manual updated

PostPosted: Fri Jun 28, 2019 5:38 pm
by dhs
I have a scenario where I need to move a newly created entity behind a group of previously created entities.
I could not find any specific D4D method to do this, but found that I could change the order of the entities using ent_relink as per the following code:

Code: Select all  ent_add (ent);
  mode_init (ExistEntMode);
  mode_group (ExistEntMode, FirstExistEnt);
  adr := ent_first (ExistEntMode);
  while ent_get (ExistEnt, adr) do begin   
    adr := ent_next (ExistEnt, ExistEntMode);
    ent_get (ent, ent.addr);     { crashes after several iterations if this ent_get is  not included }
   if not addr_equal (ent.addr, ExistEnt.addr) then
      ent_relink (ent, ExistEnt);
  end;


The above works (it moves the existing entities to after ent one by one), but does anybody know if there is a better (more efficient?) way (in D4D) to move an entity behind other entities?

On a side note: My initial code did not include the ent_get in the loop and has been working fine until today when I tested it in a scenario where there were about a dozen entities in the ExistEnt group. With a bit of trial and error I managed to ascertain that my macro crashed if there were more than about a half dozen ent_relinks in a row. Adding the ent_get into the loop appears to have fixed the crash.

I have updated my DCAL manual to included some extra notes about ent_relink, as well as about other issues and information that I've encountered since I last updated it. The latest version of my manual can always be downloaded from https://www.dhsoftware.com.au/dcalmanual.htm.