Jump to content
timmiej93

What does ACTION_INSERT do?

Recommended Posts

So let's be honest, the "PushAction..." system used by EM4 isn't great, but it's what we've got, so I'd like to understand it a bit better.

 I think most scripters know what ACTION_NEWLIST and ACTION_APPEND do. ACTION_INSERTAFTERFIRST, ACTION_INSERTBEFORELAST and ACTION_REPLACEFIRST are self-explanatory, but what does ACTION_INSERT do? Where does the command get inserted? Has anyone ever figured this out?

Link to comment
Share on other sites

In scripting, all Em4 "actors" (meaning objects, persons, vehicles) follow a sequential "list" of actions.

ACTION_NEWLIST is what you indicate on any push action to start a new "list" of actions. This will override any other action at the time.

ACTION_APPEND is how you continue the list. Say, you want to do task A first, then B. You would put task A as an ACTION_NEWLIST, then the next action and so on will be ACTION_APPEND.

ACTION_INSERT is used to insert an action in between a set of ACTION_APPEND lines.

The other ones are self-explanatory. The action will either be before the last, after the first, or replace the first action in the list.

 

Link to comment
Share on other sites

On 4/19/2020 at 10:56 PM, timmiej93 said:

Thanks for the reply. I got to about the same understanding as what you've written up, but like I asked in my initial post: Where does the command get inserted? Is there any logic to that?

It gets inserted based on the order it is on the list. Newlist is always first on a pushAction list. After this, an insert or append may follow depending on what you're doing.

If you put the insert after the NEWLIST, then it will actually swap places with the newlist and do the "insert" action first. This is only required in some very specific situations however, like you have a command that has separate instructions for a specific unit.

Link to comment
Share on other sites

Alright, I finally got around to doing an experiment, after a lot of irritation. Here's the testing and the results:

Calling function:
		blabla...
		Caller->PushActionExecuteCommand(ACTION_NEWLIST, "TimTest", NULL, 0, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 19, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 20, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 21, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 22, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 23, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 24, false);
	}	
};

object TimTest : CommandScript
{
	TimTest() {}
	bool CheckPossible() { return true; }
	bool CheckTarget() { return true; }

	void PushActions(GameObject *Caller, Actor *Target, int childID) {

		System::Log("childID %i", childID);

		if (childID != 0) {
			return;
		}

		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 1, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 2, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 3, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 4, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 5, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 6, false);
		Caller->PushActionExecuteCommand(ACTION_INSERT, "TimTest", NULL, 7, false);
		Caller->PushActionExecuteCommand(ACTION_INSERT, "TimTest", NULL, 8, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 9, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 10, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 11, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 12, false);
		Caller->PushActionExecuteCommand(ACTION_INSERTBEFORELAST, "TimTest", NULL, 13, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 14, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 15, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 16, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 17, false);
		Caller->PushActionExecuteCommand(ACTION_APPEND, "TimTest", NULL, 18, false);
	}
};

Results in log:

!childID 0
!childID 8
!childID 7
!childID 19
!childID 20
!childID 21
!childID 22
!childID 23
!childID 24
!childID 1
!childID 2
!childID 3
!childID 4
!childID 5
!childID 6
!childID 9
!childID 10
!childID 11
!childID 13
!childID 12
!childID 14
!childID 15
!childID 16
!childID 17
!childID 18

 

My conclusions from this test:

  • Any PushAction... that's INSIDE another function called by PushActionExecuteCommand gets executed AFTER EVERYTHING from the calling function has been executed, as demonstrated by the numbers 0 > 19 > 20 > 21 > 22 > 23 > 24 before going to 1.
  • Using ACTION_NEWLIST inside the second function (TimTest in this case) DOES cancel all queued commands from the calling function. For example, for the PushActionExecuteCommand with ChildID 1, if that had ACTION_NEWLIST instead of ACTION_APPEND, ChildID 8, 7, 19, 20, 21, 22, 23 and 24 do NOT print.
  • Using ACTION_INSERT inserts the command IMMEDIATELY after the PushActionExecuteCommand that called the function you're now in. Using ACTION_INSERT again will do the same, thus pushing the previously inserted item down one spot, as demonstrated by ChildID 0 > 8 > 7.

Hopefully this can prevent some frustration among scripters. If you have any questions about my testing, feel free to ask.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...