Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXED - Cannot read properties of null (reading 'previous_crashes') #6

Open
BustAces opened this issue Apr 20, 2023 · 3 comments
Open

Comments

@BustAces
Copy link

BustAces commented Apr 20, 2023

FIXED
I got the game running. I solved the issue this way.

1. At server.js add the following code after the MongoDB connection line:

const crashSchema = new mongoose.Schema(
{ round_number: Number,
active_player_id_list: [String],
multiplier_crash: Number,
b_betting_phase: Boolean,
b_game_phase: Boolean,
b_cashout_phase: Boolean,
time_now: Number,
previous_crashes: [Number],
round_id_list: [Number],
chat_messages_list: []
}
);

const Crash = mongoose.model(
'Crash', crashSchema
);

Crash.create({
round_number: 1,
active_player_id_list: [],
multiplier_crash: 0,
b_betting_phase: false,
b_game_phase: false,
b_cashout_phase: false,
time_now: -1,
previous_crashes: [],
round_id_list: 0,
chat_messages_list: []
})
.then(result => {
console.log(result)
});

Save it and run the server. It will now automatically generate the documents.
NOTE: The server will crash thats OK!

2. Now, copy the ID of the document and paste it in server.js at GAME_LOOP_ID.
3. Go to /models/game_loop.js and change:
const game_loop = new mongoose.Schema => const crashSchema = new mongoose.Schema
mongoose.model("game_loop", game_loop); => mongoose.model("Crash", crashSchema);

4. In the root folder, create an .evn file with the following line:
PASSPORT_SECRET = "YOURPASSWORDHERE"

5. Go back to server.js and delete or comment out the code you added in step 1.
6. Restart the server and enjoy. This is how it worked for me.

Original message:
Noticed the other issues claiming the same but without a clear answer still.. App does connect to my mongodb, i can see it in the connections list, however.. schema's arent generated even though the app has permission. Adding the game_loop schema manually also not solves the problem

@BustAces
Copy link
Author

BustAces commented Apr 21, 2023

To double check that the connection to mongodb is successfully, i added a console log. No errors and connection is successfull, yet.. still same error.

@mbebs
Copy link

mbebs commented Jul 4, 2023

I have same issue. Anyone knows how to create schemas on the MongoDB?

@SWS-5007
Copy link

I am getting the same error.
How to fix this?

[email protected] start
nodemon server.js

[nodemon] 2.0.18
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting node server.js
E:\Online-Crash-Gambling-Simulator\backend\server.js:412
io.emit('crash_history', theLoop.previous_crashes)
^

TypeError: Cannot read properties of null (reading 'previous_crashes')
at loopUpdate (E:\Online-Crash-Gambling-Simulator\backend\server.js:412:40)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Timeout._onTimeout (E:\Online-Crash-Gambling-Simulator\backend\server.js:351:3)
[nodemon] app crashed - waiting for file changes before starting...

@BustAces BustAces changed the title Cannot read properties of null (reading 'previous_crashes') FIXED - Cannot read properties of null (reading 'previous_crashes') Nov 9, 2023
This was referenced Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants