You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Steps to Reproduce (for bugs) relevent code is below
Execute a command to update state
command calls a function (generateRoll) that returns a 'Roll' schema
Adding breakpoint on return of generateRoll shows 'dice' ArraySchema having a value/members (pic attached)
Adding a breakpoint after the variable the return of generateRoll was assigned to shows 'dice' ArraySchema being empty.
^3 pic
^4 pic
RollDice Command
import {Command} from "@colyseus/command";
import {GameRoom} from "../index";
import {generateRoll} from "./helpers";
export class RollCommand extends Command<GameRoom, {
length: number
}> {
execute({length} = this.payload) {
let currentRound = this.state.currentRound
let lastRoll = currentRound.currentRoll;
let roll = generateRoll(length);
currentRound.busted = roll.isBust
if (lastRoll) {
this.state.currentRound.rollHistory.push(lastRoll)
}
this.state.currentRound.currentRoll = roll
this.state.currentRound.busted = roll.isBust
}
}
.helpers/generateRoll
export const generateRoll = (length: number = 5): Roll => {
let dice = new ArraySchema<number>();
let isBust: boolean;
let uuid: string = uuid4();
for (let i = 0; i < length; i++) {
const roll = generateRandom(MIN_ROLL, MAX_ROLL)
dice.push(roll)
}
console.log(dice.toJSON())
isBust = determineBust(dice)
return new Roll({
dice,
isBust,
length,
uuid
})
}
relevent schema
export class Round extends Schema {
@type(Roll) currentRoll: Roll;
@type(PlayerState) currentPlayer: PlayerState;
@type(SetAside) setAside: SetAside;
@type([Roll]) rollHistory = new ArraySchema<Roll>();
@type([SetAside]) setAsideHistory = new ArraySchema<SetAside>();
@type("number") score: number;
@type("number") roundNumber: number;
@type("boolean") busted: boolean;
}
export class Roll extends Schema {
@type(["number"]) dice = new ArraySchema<number>();
@type("boolean") isBust: boolean;
@type("number") length: number;
@type("string") uuid: string
}
Context
This is currently keeping me from having dice rolls generated in my game server which is the main functionality of the game. I may be able to get around with by using the functionality in generateRoll in my command rather than call a function, but I would rather keep it compartmentalized.
The rest of my Roll schema keeps its value assigned in generateRoll.
Your Environment
Colyseus Version: ^0.14.13",
Node.js Version: 16.3.2
Operating System and version: Windows 10
The text was updated successfully, but these errors were encountered:
Hi @PandaPalumbo, it would save us some time if you can provide a repository that we can quickly reproduce. Not sure what may be wrong in your code, my only suggestion would be to use new Roll().assign({...}) instead of new Roll({...}). Cheers
Steps to Reproduce (for bugs) relevent code is below
^3 pic
![image](https://user-images.githubusercontent.com/54112798/184549993-f28d5249-5598-4a4a-a38b-25c867dfadcc.png)
![image](https://user-images.githubusercontent.com/54112798/184550027-3fc2c03c-ff1a-4265-850d-ff360e667177.png)
^4 pic
RollDice Command
.helpers/generateRoll
relevent schema
Context
This is currently keeping me from having dice rolls generated in my game server which is the main functionality of the game. I may be able to get around with by using the functionality in generateRoll in my command rather than call a function, but I would rather keep it compartmentalized.
The rest of my Roll schema keeps its value assigned in generateRoll.
Your Environment
Operating System and version: Windows 10
The text was updated successfully, but these errors were encountered: