Skip to content
This repository has been archived by the owner on Feb 12, 2021. It is now read-only.

TypeError: Cannot read property 'PlayerControl' of undefined #24

Open
Rohit3523 opened this issue Dec 25, 2020 · 4 comments
Open

TypeError: Cannot read property 'PlayerControl' of undefined #24

Rohit3523 opened this issue Dec 25, 2020 · 4 comments

Comments

@Rohit3523
Copy link

Rohit3523 commented Dec 25, 2020

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

@2van
Copy link

2van commented Dec 25, 2020

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.

@Rohit3523
Copy link
Author

Can you give an example

@2van
Copy link

2van commented Dec 27, 2020

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

@5GameMaker
Copy link

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);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants