Jonny Boi
Jonny Boi
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
This is a good challenge, still working on it, but learning lots, even if don't finish, will still make presentation video and submit 💪
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
Same issue though, going to try your suggestion and make a players table
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
Thanks!
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
ahh gotcha, I made the correction
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
I pass in the ID of the getWaitingRoom result in order to update it
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
export const updateRoomCapacity = mutation({
args: { id: v.id("rooms")},
handler: async (ctx, args) => {
const { id } = args;

await ctx.db.patch(id, {capacity: 2, status: GameStatus.InProgress, player2Ready: true});
const updatedRoom = await ctx.db.get(id);
return updatedRoom;
},
})
export const updateRoomCapacity = mutation({
args: { id: v.id("rooms")},
handler: async (ctx, args) => {
const { id } = args;

await ctx.db.patch(id, {capacity: 2, status: GameStatus.InProgress, player2Ready: true});
const updatedRoom = await ctx.db.get(id);
return updatedRoom;
},
})
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
and this is the mutation that updates the capacity to 2, it is triggered when a second player enters a room and getWaitingRoom returns a value
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
export const getWaitingRoom = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query("rooms").filter((q) => q.eq(q.field("capacity"), 1)).first();
},
});
export const getWaitingRoom = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query("rooms").filter((q) => q.eq(q.field("capacity"), 1)).first();
},
});
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
This is the query that gets a room with capacity 1, meaning a player is waiting for another player
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
will share mutation too
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
Nevermind same issue after update
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
going to correct and see if works
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
I put WaitingForPlayers instead of InProgress
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
that's the enum ^^
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
enum GameStatus { WaitingForPlayers = 'Waiting for players', InProgress = 'In progress', Completed = 'Completed', }
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
but as I copied the code I realize my mistake
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
That's the query that gets a game that is ready
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
export const getGameReady = query({
args: { },
handler: async (ctx) => {
return await ctx.db.query("rooms").filter((q) => (q.eq(q.field("player1Ready"), true) && (q.eq(q.field("player2Ready"), true) && (q.eq(q.field("status"), GameStatus.WaitingForPlayers))))).first();
},
});
export const getGameReady = query({
args: { },
handler: async (ctx) => {
return await ctx.db.query("rooms").filter((q) => (q.eq(q.field("player1Ready"), true) && (q.eq(q.field("player2Ready"), true) && (q.eq(q.field("status"), GameStatus.WaitingForPlayers))))).first();
},
});
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
I have a query that gets game's in the ready state after a player joined the room, but your suggestion sounds more optimal
114 replies
CCConvex Community
Created by jamwt on 3/11/2024 in #support-community
Building a Game on Convex
Roger, going to re-work to get a query more so like that
114 replies