Hide/Delete Movement Object (Character)

Post Reply
User avatar
Osa__PL
Posts: 3
Joined: Tue Feb 28, 2017 5:15 am

Hide/Delete Movement Object (Character)

Post by Osa__PL » Tue Feb 28, 2017 5:24 am

How can I delete or hide a character/Movement Object in my .as script?

User avatar
Gyrth
Posts: 225
Joined: Sat Sep 10, 2011 12:49 pm

Re: Hide/Delete Movement Object (Character)

Post by Gyrth » Wed Mar 01, 2017 12:53 am

Something like

Code: Select all

array<int> movement_objects = GetObjectIDsType(_movement_object);
for(uint i = 0; i < movement_objects.size(); i++){
    DeleteObjectID(movement_objects[i]);
}

User avatar
Osa__PL
Posts: 3
Joined: Tue Feb 28, 2017 5:15 am

Re: Hide/Delete Movement Object (Character)

Post by Osa__PL » Wed Mar 01, 2017 2:21 am

It works, but not for my purpose.
The problem is that I need to delete one MO, while keeping the other one, but after deleting it your way, the game crashes by prompting "There is no movement object with <id>". I do that by waiting for a player input, and then doing something like:

Code: Select all

void RemovePlayers(){
	array<int> movement_objects = GetObjectIDsType(_movement_object);
	for(uint i = 3; i > player_number-1; i--){ //player_number always is 1-4
		DeleteObjectID(movement_objects[i]);
	}
}
of even something easier:

Code: Select all

DeleteObjectID(movement_objects[3]);
Deleting all of the MO seems to not crash, and editor just spawns a new one where camera is placed.

User avatar
Gyrth
Posts: 225
Joined: Sat Sep 10, 2011 12:49 pm

Re: Hide/Delete Movement Object (Character)

Post by Gyrth » Wed Mar 01, 2017 12:52 pm

If you want to delete every NPC you can check if it's controlled

Code: Select all

array<int> movement_objects = GetObjectIDsType(_movement_object);
for(uint i = 0; i < movement_objects.size(); i++){
    MovementObject@ current_mo = ReadCharacterID(movement_objects[i]);
    if(!current_mo.controlled){
        DeleteObjectID(movement_objects[i]);
    }
}

merlyn
Posts: 373
Joined: Fri Aug 26, 2016 2:41 pm
Contact:

Re: Hide/Delete Movement Object (Character)

Post by merlyn » Wed Mar 01, 2017 5:20 pm

Osa__PL wrote:It works, but not for my purpose.
The problem is that I need to delete one MO, while keeping the other one, but after deleting it your way, the game crashes by prompting "There is no movement object with <id>". I do that by waiting for a player input, and then doing something like:

Code: Select all

void RemovePlayers(){
	array<int> movement_objects = GetObjectIDsType(_movement_object);
	for(uint i = 3; i > player_number-1; i--){ //player_number always is 1-4
		DeleteObjectID(movement_objects[i]);
	}
}
of even something easier:

Code: Select all

DeleteObjectID(movement_objects[3]);
Deleting all of the MO seems to not crash, and editor just spawns a new one where camera is placed.
Can't really comment on this technique in our game, but in general programming, relying on a specific ID to match a specific object is pretty risky, especially across different versions of the software. You might want to look for a custom property or type on the objects you want to delete instead, if that is possible. The best way to accomplish that properly depends on what exactly you're trying to do with your script though.

User avatar
Thomason1005
Posts: 713
Joined: Sat Apr 20, 2013 9:44 am
Location: GerMany

Re: Hide/Delete Movement Object (Character)

Post by Thomason1005 » Sat Mar 04, 2017 1:17 pm

merlyn wrote: Can't really comment on this technique in our game, but in general programming, relying on a specific ID to match a specific object is pretty risky, especially across different versions of the software. You might want to look for a custom property or type on the objects you want to delete instead, if that is possible. The best way to accomplish that properly depends on what exactly you're trying to do with your script though.
Well isnt that exactly what an id is for?
It is quite constant in og, i mean it is written into the level xml and only changed when the object itself is deleted

The crash occurs because the character controller relies on the other characters to be constant. I think it loops a list of other characters to handle interactions.idk if theres a solution to that.

merlyn
Posts: 373
Joined: Fri Aug 26, 2016 2:41 pm
Contact:

Re: Hide/Delete Movement Object (Character)

Post by merlyn » Mon Mar 06, 2017 1:37 pm

Thomason1005 wrote:Well isnt that exactly what an id is for?
It is quite constant in og, i mean it is written into the level xml and only changed when the object itself is deleted
The way IDs work in Overgrowth, they're assigned by the level editor. They're safe at that point, and probably won't be re-assigned, unless you edit the level a lot, and remove/re-add that character.

If you bind an ID in a hot spot parameter, then that's fine, cause that's a per-level thing. The problems would occur if you hard code a specific ID into AS. In that case, good luck using the script on any other level :) For example - assuming the player characters is always ID 1...

Anyhow, sorry to derail. I think you're not quite assuming IDs at this point. You're looking it up through movement_objects

DoctorGester
Posts: 44
Joined: Fri Apr 29, 2011 4:22 am

Re: Hide/Delete Movement Object (Character)

Post by DoctorGester » Sat Mar 11, 2017 8:29 pm

Pretty sure the crash occurs if you delete the player if any enemies saw the player.

It's because of a bug in playercontrols.as

Post Reply