createParty(raidType) { if (this.sockets.length === 0) { console.log("No more…
- User
createParty(raidType) { if (this.sockets.length === 0) { console.log("No more connections available."); return; }
codelet numSocketsToAdd; if (raidType === "1by1") { numSocketsToAdd = 1; } else if (raidType === "xkey") { numSocketsToAdd = 3; } else { console.error("Invalid raid type."); return; } while (this.sockets.length > 0) { const party = []; const socketsToAdd = this.sockets.slice(0, numSocketsToAdd); // Copy the first numSocketsToAdd elements for (const socket of socketsToAdd) { const psk = socket.psk; party.push({ socket, psk, hasStash: false }); } console.log(`Party ${this.parties.length + 1} created with ${party.length} connections.`); this.parties.push(party); }}
There is a fundemental flaw with this script. The sockets are in this.sockets, which is inside altObjects, an object literal. Each socket has a socket.cloneId, and this script keeps making infintie parties and only creates it for the first socket, socket.cloneId is 1
- Assistant
- User
in the old code we used this.sockets.pop. This prevented a certain issue but caused the element to be removed from this.sockets. sockets.pop prevented us from creating infinite duplication for alts of the same id and also made it so we itreated through the entire sockets array properly
- Assistant
- User
Ignore what I jsut said, I just rad your code and there was a mistake
codeconst socket = this.sockets.shift(); // Remove the socket from the available list const psk = socket.psk; party.push({ socket, psk, hasStash: false });This is bad, it removes the elements from this.sockets which is needed to control the socketds
- Assistant
- User
now make it so I can clear these parties
- Assistant
If you want to clear the parties that you've created without affecting the original
this.altObjects.socketsarray, you'll need to just reset thethis.partiesarray to an empty array. You can create a method for this purpose. Here is an example of how you might implement it:javascriptclearParties() { this.parties = []; console.log('All parties have been cleared.'); }Make sure that the method is part of the same object (or class) where
createPartyis defined and wherethis.partiesis a property that stores the parties you've created.Now, whenever you want to clear the list of parties that have been created, you can call
clearParties()method:javascript// Assuming your class or object instance is called 'raidManager' raidManager.clearParties();This will reset the
this.partiesarray and effectively remove all the parties that were created previously. No other arrays or data structures are affected by this operation, so the original sockets in remain intact.