Scriptending not working in entity


#1

I just try to detect with my script that is inside entity when you close interface or get out of range etc. I got as advise to use scriptending. That worked in 2014 fine :grin: After that not used it much.

Here’s a part of the code,

 function scriptEnding() 
	{ 
		var Avatarinrange=AvatarList.isAvatarInRange (basepos, 10); 
		print("script end");
	}	
	
	//-------------
	
    function ParamsEntity() 
	{
        return;
    }	

	ParamsEntity.prototype = 
	{	
		preload: function(entityID)
		{ 
			Ent = entityID;
			parentID = Entities.getEntityProperties(Ent, ['parentID']).parentID;
			//print("Parent EntID  "+parentID);	
			initdoor();			
		},			

		doorHandleTouched: function() 
		{
			print("DOORhandleTouched");
			movedoor()
		}
	}

	Script.scriptEnding.connect(scriptEnding);		
	
	return new ParamsEntity();

To make sure i did not do anything wrong i tried the example from the wiki.

(function()
{
	print("This script just prints this line and then ends.");

	function scriptEnding() 
	{
		print("SCRIPT ENDNG!!!");
	}

	// register our scriptEnding callback
	Script.scriptEnding.connect(scriptEnding);
})

But also this ex ampel does not trigger the scriptending. Bug or do i make a error. or does scriptedning not work inside a entity ? and what would be the right command instead if scriptending not work ?

ADD: I knew that i have seen this problem before , but this forum is hard place to find something. I go try soem suggestions from this topic.


I hate prototype it made high fidelity much more difficult
#2

Starting to hit a dead end. i tried the unload trick. but still nothing in the log.

//-------------
	
    function ParamsEntity() 
	{
        return;
    }	

	ParamsEntity.prototype = 
	{	
		preload: function(entityID)
		{ 
			Ent = entityID;
			parentID = Entities.getEntityProperties(Ent, ['parentID']).parentID;
			//print("Parent EntID  "+parentID);	
			initdoor();			
		},	

		unload: function()
		{
			var Avatarinrange=AvatarList.isAvatarInRange (basepos, 10); 
			print("script end");
		},	

		doorHandleTouched: function() 
		{
			print("DOORhandleTouched");
			movedoor()
		}
	}
	
	return new ParamsEntity();

Ok, just tried unload by teleporting to other domain, that is working fine.
It now seems to work when the viewer is exiting to. High Fidelity scripting is not complete reliably (executed from local disk) Oh well, i can at least work further for now.

This last example works for me with the unload:
But it keeps strange that it did seem to fail every round before. Oh well, we still moving forward.


#3

I do not believe you have a reliable solution. This may be a race condition between the last client leaving the scene and the script having a chance to execute. I would love to get a dev’s or program manager’s answer on this one. @chris ?


#4

I think it’s not reliable. But that i find it soon i think.

Also, it looks like i need to approch it different as long i
cannot get the amount of avatars in the area around the script.


#5

I never found any script from triggering scriptending unless the user has teleported away or closed the client where the client registers a change in the entity tree which the script is connected to.

Instead of connect the script ending in the exterior of the object, I suggest defining it in the constructor /preload event.

That’s atleast where I define mine.

Also another note. If the script is ending and the client is shutting down or going out of the domain, what exact use is there for detecting avatars in range? The script instance only applies for the client running the script.

So by the time the user disconnects they most likely have no access to the domain and agent info.


#6

Inthinked about putting it in preload. still end would be nicer.
But as long i cannot read how many avatars are around the object i cannot proceed. it really need to be a number not true or false.

Like i asked in other post, wich command tell you how many avatars are in radius you set. I cannot find any command on the wiki.

When i know if there’s one or more then one abtr i can work further on the script to make it better then the old one.


#7

I believe ‘AvatarList.getAvatarIdentifiers();’ returns a array with all avatar-uuid’s in the region.
With that you can get their positions.
Something like:

var avatars = AvatarList.getAvatarIdentifiers();
for (i = 0; i < avatars.length; i++) {
    var avatarPos = AvatarList.getAvatar( avatars[i] ).position;
}

From there you should be able to check if they’re in range.

I could be wrong though.


#8

Thanks. it gives some results back. sad that there’s not much info on the wiki about soem commands. I go think how to implement it.

getAvatar
getAvatarIdentifiers

Tried that, nothing found.


#9

you’re wasting your time – there’s no guarantee scriptEnding will actually be called, especially by a client that disconnects quickly (think alt-f4) or crashes. give up. the best you can do is set up a lifetime for the entity to clean it up, or an AC script to run regular maintenance. i already responded re: avatars on your other post.


#10

alt-F4 that is how i did test it, and explain why it failed. also means that high fidelity have not done the quite code correct. Because you can dettect F4 to as far i know.

AC and lifetime sre not solution.
The only option menithal,pointed also at is the bit more ugly way and do the check in the preload section. The avatar check code i still need, so possible i just check both preload and unload.


#11

Going back to the question of what problem you want to solve, is the issue that your door opens and closes smoothly by imparting velocity and you want it to be deterministically fully opened or fully closed? If that is the issue, because there is no super observer, it is not possible to do that at the tail end. When all observers leave the area, whether by distance or leaving the domain altogether, the scripts unload and it is possible no client script ever gets to run.

Instead try fixing it from the load side. When loaded (and the preload event is fine place), check the door’s current rotation. Fix it there. This is a bit of hack too, and it has to be refined to perform that action when the script determines it is the first instance bound to the door.