I'm trying to assign a numerical value to my var gameid
with the function initGame(red, black options)
.
unfortunately gameid will always return undefined.
async function startPendingRoom (red, black) {
var gameid = initGame (red, black, returnPendingRoomIfExists (red).options);
removePendingRoomIfExists (red);
removePendingRoomIfExists (black);
io.to (red).emit ('startOnlineGameRES', { gameid : gameid });
io.to (black).emit ('startOnlineGameRES' , { gameid : gameid });
console.log (red," vs. ", black, " gameid: ", gameid);
updatePendingRoomsCLIENT ();
}
function initGame (red, black, options, gameid) {
dbCon.connect(function(err) { if (err) throw err;
dbCon.query("INSERT INTO options "
+"VALUES ("
+"0 ,"
+ options.malusSize + ", "
+ options.sequenceSize +", "
+ options.throwOnWaste +", "
+ options.throwOnMalus +", "
+ "'"+options.variant+"'" +", "
+ options.turnsTimed +", "
+ options.timePerTurn +", "
+ options.roundsTimed +", "
+ options.timePerRound +", "
+ (options.roomName != "" ? "'"+options.roomName+"'" : "null" )+", "
+ (options.roomPassword != "" ? "'"+options.roomPassword+"'" : "null" )+");",
function (err, option) { if (err) throw err;
dbCon.query("INSERT INTO games "
+"VALUES ("
+"0 ,"
+ option.insertId + ", "
+ "'"+red+"'" + ", "
+ "'"+black+"'" +");",
function (err, game) { if (err) throw err;
return game.insertId;
});
});
});
}