WindowsTV

ActorID Pseudo code, Help Please

Jan 2nd, 2021 (edited)
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // There is a bug where I attempt to get an ActorID from an animation that was just remove and is assigned with that ID and then another new animation is added and it's assigned that same ID. I'm not sure if it's a timing thing or if I've made bad code
  2. //For more information please look at my tweet: https://twitter.com/WinderpTV/status/1345439896299855872?s=20
  3.  
  4. var actorsArr = [
  5.     {actorName: "Putt-Putt", actorID:1},
  6.     {actorName: "SomeRadomAnimation1", actorID:2},
  7.     {actorName: "SomeRadomAnimation2", actorID:3}
  8. ];
  9. function getNextActorID(){
  10.     var _loc1 = 0;//index
  11.     var _loc2 = 1;//ActorID
  12.     while (true) {
  13.         if(ACTOR ID FROM actorsArr IS IN USE){                      
  14.             continue;
  15.         }
  16.         //OTHERWISE GIVE ME USABLE ACTOR ID THAT'S NOT FOUND IN actorsArr
  17.         return _loc2;
  18.     }
  19.     //NOTHING TO GIVE
  20.     return -1;
  21. }  
  22.  
  23. function addActor(startingCostume, isIdle = false, isPlayer = false, roomOverride = undefined, startFrame = 0, target = undefined, color = ""){
  24.     //GET AVAIBLE ACTOR ID
  25.     //ADD ANIMATION SPRITE BASED ON ACTOR ID
  26.  
  27.     //What I done to achieve this...
  28.     var _actorID = this.getNextActorID();      
  29.     var _index = (this.actors.push(new com.wtv.Test(this, _actorID, isPlayer))) - 1;        
  30.  
  31.     return ({actor:this.actors[_index], actorID:_actorID});
  32. }// end of the function
  33.  
  34. function removeActor(actorID, doSplice = true, removeTarget = true) {
  35.     //REMOVE ACTOR FROM actorsArr BASED ON actorID GIVEN
  36.    
  37.     //What I done to achieve this...
  38.     var index = this.getActorIndexByID(actorID, 'removeActor2');
  39.     var actor = this.actors[index];
  40.     this.actors.splice(index, 1);
  41. }// end of the function
Add Comment
Please, Sign In to add comment