Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. glacier_chaser
G

glacier_chaser

@glacier_chaser

Chat Follow Unfollow
0
Reputation
1
Posts
784
Profile views
0
Followers
0
Following
Joined 11 Nov 2019, 13:57 Last Online 12 Nov 2019, 16:09

  • Profile
  • More
    • Continue chat with glacier_chaser
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups
glacier_chaser Follow

Posts made by glacier_chaser

"Types" of Undefined in Reflection.js error in Unity

Hey all,

Just started using colyseus and loving it! Though, since I'm pretty new, this might be a user error, but I was fighting an error from Reflection.ts as a result of having a null schema and thought I'd share in case someone else runs into it. I wasn't accessing anything in the schema, just attempting to instantiate it. I've lost the exact error syntax, but it was along the line of "cannot access "types" of undefined from Reflection.js line 98." Looking at that bit of code, I guess the for loop needs to include a null check before running. I was able to resolve the issue by adding a dummy variable to the schema and regenerating it. It was literally just a string that I didn't access, but it was enough to validate the if/else checks in Reflection.js I suppose.

Anyone else see this before? My guess is there's literally no reason for a null schema... unless you're a total noob who's butchering the example projects :).

Relevant reflections logic:

var buildType = function (currentType, schema) {
            for (var fieldName in schema) {
                var field = new ReflectionField();
                field.name = fieldName;
                var fieldType = void 0;
                if (typeof (schema[fieldName]) === "string") {
                    fieldType = schema[fieldName];
                }
                else {
                    var isSchema = typeof (schema[fieldName]) === "function";
                    var isArray = Array.isArray(schema[fieldName]);
                    var isMap = !isArray && schema[fieldName].map;
                    var childTypeSchema = void 0;
                    if (isSchema) {
                        fieldType = "ref";
                        childTypeSchema = schema[fieldName];
                    }
                    else if (isArray) {
                        fieldType = "array";
                        if (typeof (schema[fieldName][0]) === "string") {
                            fieldType += ":" + schema[fieldName][0]; // array:string
                        }
                        else {
                            childTypeSchema = schema[fieldName][0];
                        }
                    }
                    else if (isMap) {
                        fieldType = "map";
                        if (typeof (schema[fieldName].map) === "string") {
                            fieldType += ":" + schema[fieldName].map; // array:string
                        }
                        else {
                            childTypeSchema = schema[fieldName].map;
                        }
                    }
                    field.referencedType = (childTypeSchema)
                        ? childTypeSchema._typeid
                        : 255;
                }
                field.type = fieldType;
                currentType.fields.push(field);
            }
            reflection.types.push(currentType);
        };

Thanks!

posted in Questions & Help • 11 Nov 2019, 14:17

© 2023 Endel Dreyer