amongus-protocol icon indicating copy to clipboard operation
amongus-protocol copied to clipboard

TypeError: Cannot read property 'PlayerControl' of undefined

Open Rohit3523 opened this issue 4 years ago • 4 comments

When i host a game via your module and i try to join the lobby with my phone i get this error

Complete Error: (node:3380) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'PlayerControl' of undefined at Game. (file:///C:/Users/Rohit/Desktop/Other/AmongUS2/node_modules/amongus-protocol/js/lib/struct/Game.js:168:65) at Generator.next () at file:///C:/Users/Rohit/Desktop/Other/AmongUS2/node_modules/amongus-protocol/js/lib/struct/Game.js:7:71 at new Promise () at __awaiter (file:///C:/Users/Rohit/Desktop/Other/AmongUS2/node_modules/amongus-protocol/js/lib/struct/Game.js:3:12) at Game.setStartCounter (file:///C:/Users/Rohit/Desktop/Other/AmongUS2/node_modules/amongus-protocol/js/lib/struct/Game.js:156:16) at Game. (file:///C:/Users/Rohit/Desktop/Other/AmongUS2/node_modules/amongus-protocol/js/lib/struct/Game.js:189:22) at Generator.next () at file:///C:/Users/Rohit/Desktop/Other/AmongUS2/node_modules/amongus-protocol/js/lib/struct/Game.js:7:71

Rohit3523 avatar Dec 25 '20 06:12 Rohit3523

cus u didn't spawn host, and the host Player is null. if u spawn host Player, u have to recieve Message with SpawnID.GameData.

2van avatar Dec 25 '20 07:12 2van

Can you give an example

Rohit3523 avatar Dec 25 '20 12:12 Rohit3523

Unfortunately, it's impossible to create a host Player Object as far as I know.

2van avatar Dec 27 '20 09:12 2van

Same error. Code:

const cp = require('child_process');

async function sleep(ms) {
    return new Promise(res => {
        setTimeout(() => res(), ms);
    });
}

async function main() {
    console.log("Loading libraries...");

    const ap = await import('amongus-protocol');

    console.log("Initializing client...");

    const client = new ap.AmongusClient({
        debug: false,
    });
    
    /**
     * @param {[string, number][]} master
     */
    async function connectTo(master) {
        for (let i = 0; i < master.length; i++) {
            try {
                console.log(`Connecting to ${master[i][0]}:${master[i][1]}`);
                const promise1 = client.connect(master[i][0], master[i][1], "godmode");

                let connected = false;

                promise1.then(() => connected = true);

                await sleep(1000);

                if (connected) return;
                else {
                    console.log("Server down");
                }
            } catch (e) {}
        }
        console.log(`Failed to connect`);
        process.exit(1);
    }
    
    await connectTo(ap.MasterServers.AS);
    console.log(`Connected to ${client.ip}:${client.port}`);
    console.log(`Starting game...`);

    const code = (await client.host({
        language: ap.LanguageID.English,
    })).code

    console.log(`Server is running on ${cp.execSync(`./intToCode ${code}`).toString('utf8')}`);
    console.log(`Joining server...`);

    const game = await client.join(code, {
        doSpawn: true,
    });

    // game.me.on('spawn', () => {
    //     game.me.setColor(ap.ColourID.Black);
    //     game.me.setName("godmode");
    // });
}
main().catch(console.error);

5GameMaker avatar Jan 16 '21 11:01 5GameMaker