Hide/Delete Movement Object (Character)
Hide/Delete Movement Object (Character)
How can I delete or hide a character/Movement Object in my .as script?
Re: Hide/Delete Movement Object (Character)
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]);
}
Re: Hide/Delete Movement Object (Character)
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:
of even something easier:
Deleting all of the MO seems to not crash, and editor just spawns a new one where camera is placed.
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]);
}
}
Code: Select all
DeleteObjectID(movement_objects[3]);
Re: Hide/Delete Movement Object (Character)
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]);
}
}
Re: Hide/Delete Movement Object (Character)
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.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:of even something easier: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]); } }
Deleting all of the MO seems to not crash, and editor just spawns a new one where camera is placed.Code: Select all
DeleteObjectID(movement_objects[3]);
-
- Posts: 713
- Joined: Sat Apr 20, 2013 9:44 am
- Location: GerMany
Re: Hide/Delete Movement Object (Character)
Well isnt that exactly what an id is for?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.
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.
Re: Hide/Delete Movement Object (Character)
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.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
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
-
- Posts: 44
- Joined: Fri Apr 29, 2011 4:22 am
Re: Hide/Delete Movement Object (Character)
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
It's because of a bug in playercontrols.as