Any idea why can't I use enum as a variable?

So maybe I just need an update?

by user 151660356224286721

yes - what i mentioned was added in 3.25

I see, thank you !

by user 151660356224286721

@Needle Engine Assistant

GetExistingPosition(): BoardArea {
const movementManager = GameManager.getInstance().movementManager;

    if (movementManager && movementManager.BoardArea2x2Matrix) {
        for (const column of movementManager.BoardArea2x2Matrix) {
            for (const boardArea of column) {
                if (boardArea.pieceInCurrentArea === this) {
                    console.log(boardArea.description);
                    return boardArea;
                }
            }
        }
    }
    throw new Error("BoardArea not found for the current piece.");
}

public OnSelect()
{
console.log(“OnSelect”);
Piece.selected = this;
this.GetExistingPosition();
//calculate posible position
//show them in UI
}

my function name is correct. but it keeps showing me this error.

EventList method:
Could not find method onSelect on object PawnLight_1. Please rename onSelect to OnSelect?
ƒ OnSelect() {
console.log(“OnSelect”);
_Piece.selected = this;
this.GetExistingPosition();
}
in script: Pawn {__context: undefined, __name: ‘Pawn’, gameObject: Mesh, guid: ‘5586818795571196987_8956883846352713136’, sourceId: ‘assets/noMarker.glb’, …}

by user 151660356224286721

Here is what I found for you :brain: Discord

It looks like there might be a case sensitivity issue with the function name. In javascript and, by extension, TypeScript used by Needle Engine, function names are case-sensitive. The error message suggests that the engine expects the function name to be OnSelect (with uppercase ‘O’ and ‘S’), while your function might be defined as onSelect (with a lowercase ‘o’) in some places.

Let’s make sure that the method name is consistent everywhere in your code, using the exact same casing as the engine expects. Here’s how you should define and refer to the function OnSelect:

public OnSelect() {
    console.log("OnSelect");
    Piece.selected = this;
    this.GetExistingPosition();
    // calculate possible positions
    // show them in UI
}

Call the method using the exact same case:

this.OnSelect();

Please ensure that wherever you are binding the OnSelect function to an event or calling it, you use the exact same casing. If the issue persists after making this adjustment, you might need to review the component documentation or lifecycle methods to ensure it is hooked up properly in the Needle Engine context.

4 messages left GPT 4
thread_MWfJTlQt2uenguWenl6kRuUz

@Needle Engine Assistant

import { Behaviour, EventList, IPointerClickHandler, PointerEventData, serializable } from “@needle-tools/engine”;

export class SyncedClick extends Behaviour implements IPointerClickHandler {

@serializable(EventList)
onClick!: EventList;

/* eslint-disable */
onPointerClick(_args: PointerEventData) { 
    console.log("CLICKED!");
    this.context.connection.send("clicked/" + this.guid);
    this.onClick?.invoke();
}
/* eslint-enable */

onEnable(): void {
    this.context.connection.beginListen("clicked/" + this.guid, this.onRemoteClick);
}
onDisable(): void {
    this.context.connection.stopListen("clicked/" + this.guid, this.onRemoteClick);
}


onRemoteClick = () => {
    console.log("RECEIVED CLICK");
    this.onClick?.invoke();

}}
I see “CLICKED!” in debug Terminal, but this.onClick?.invoke is not executing.

by user 151660356224286721

Thinking :cowboy_hat_face:

@Needle Engine Assistant
didn’t change a thing but my classes are not generated in c#

import { Behaviour, serializable} from “@needle-tools/engine”;
import { MovementManager } from “./MovementManager”;
import {Piece} from “./Piece/Piece”
import { BoardArea } from “./BoardArea”;
export {BoardArea};
export {Piece};
export {MovementManager};

export class GameManager extends Behaviour
{
private static instance: GameManager;

    public static getInstance(): GameManager {

        if (!GameManager.instance) {
            GameManager.instance = new GameManager();
        }
        return GameManager.instance;
    }

@serializable (Behaviour)
movementManager?: MovementManager;  

InitialPiecePlacement() {
    if (this.movementManager && this.movementManager.BoardArea2x2Matrix) {
        for (const column of this.movementManager.BoardArea2x2Matrix) {
            for (const boardArea of column) {
            const piece = boardArea.pieceInCurrentArea;
            if (piece) {
                piece.PlacePiece(boardArea.gameObject);
             }
             }
        }
    }
}

awake() {

    if (this.movementManager) {
        this.movementManager.InitBoardArea();
        this.movementManager.BoardArea2x2Matrix = [];
        this.movementManager.ConvertBoardArea();
    }
    else
    {
        console.error("Missing moveManager Reference");
    }

    this.InitialPiecePlacement();


}

}

by user 151660356224286721

Here is what I found for you :brain: Discord

To ensure the TypeScript to C# component compiler generates your classes correctly, you need to follow certain conventions and coding patterns that the Needle Engine for Unity recognizes. The code you’ve provided seems to not follow some of these patterns which could prevent the compiler from generating C# classes appropriately.

Let’s correct a few things to adhere to the expected formats and conventions:

  1. Avoid creating static instances of Behaviour-derived classes. Needle Engine does not support singletons pattern implemented this way.
  2. Ensure that the @serializable decorator is used correctly; it doesn’t need to reference Behaviour in this context as it’s for input serialization.
  3. Your code shouldn’t instantiate the Behaviour classes directly as the engine is responsible for creating instances. Remove the getInstance() method accordingly.

After making these changes, let’s verify the TypeScript code:

*thread_567y7ByPEJSt39JwcFVJgfKw*

typescript
import { Behaviour, serializable } from “@needle-tools/engine”;
import { MovementManager } from “./MovementManager”;
import { Piece } from “./Piece/Piece”;
import { BoardArea } from “./BoardArea”;

export class GameManager extends Behaviour {
@serializable
movementManager?: MovementManager;

InitialPiecePlacement() {
    if (this.movementManager && this.movementManager.BoardArea2x2Matrix) {
        for (const column of this.movementManager.BoardArea2x2Matrix) {
            for (const boardArea of column) {
                const piece = boardArea.pieceInCurrentArea;
                if (piece) {
                    piece.PlacePiece(boardArea.gameObject);
                }
            }
        }
    }
}

awake() {
    if (this.movementManager) {
        this.movementManager.InitBoardArea();
        this.movementManager.BoardArea2x2Matrix = [];
        this.movementManager.ConvertBoardArea();
    } else {
        console.error("Missing moveManager Reference");
    }

    this.InitialPiecePlacement();
}

}

*thread_567y7ByPEJSt39JwcFVJgfKw*

Evaluate the changes and test if the TypeScript compiler now generates the corresponding C# class. If you are still having issues, ensure your TypeScript files are located within the appropriate directory that the Needle Engine observes for compilation, as outlined in the Unity side of Needle Engine’s documentation.

4 messages left GPT 4
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!

@Needle Engine Assistant

GameManager.ts

import { Behaviour, serializable} from “@needle-tools/engine”;
import { MovementManager } from “./MovementManager”;
import {Piece} from “./Piece/Piece”
import { BoardArea } from “./BoardArea”;
export {BoardArea};
export {Piece};
export {MovementManager};

export class GameManager extends Behaviour
{
@serializable (Behaviour)
movementManager?: MovementManager;

InitialPiecePlacement() {
    if (this.movementManager && this.movementManager.BoardArea2x2Matrix) {
        for (const column of this.movementManager.BoardArea2x2Matrix) {
            for (const boardArea of column) {
            const piece = boardArea.pieceInCurrentArea;
            if (piece) {
                piece.PlacePiece(boardArea.gameObject);
             }
             }
        }
    }
}

awake() {

    if (this.movementManager) {
        this.movementManager.InitBoardArea();
        this.movementManager.BoardArea2x2Matrix = [];
        this.movementManager.ConvertBoardArea();
    }
    else
    {
        console.error("Missing moveManager Reference");
    }

    this.InitialPiecePlacement();


}

}

generated GameManager.cs

// NEEDLE_CODEGEN_START
// auto generated code - do not edit directly

#pragma warning disable

namespace Needle.Typescript.GeneratedComponents
{
public partial class GameManager : UnityEngine.MonoBehaviour
{
// public MovementManager @movementManager; → Could not resolve C# type
public void InitialPiecePlacement(){}
public void awake(){}
}
}

// NEEDLE_CODEGEN_END

by user 151660356224286721

Here is what I found for you :brain: Discord

It seems that the C# code is not being generated properly for the GameManager class. This could be due to the way the @serializable decorator has been used in the TypeScript code.

The issue lies with how the @serializable decorator is being used. It should not reference the Behaviour class within its parentheses for input serialization. Instead, it should directly annotate the movementManager property.

Let’s modify the TypeScript code with this correction and test again for C# generation:

import { Behaviour, serializable } from "@needle-tools/engine";
import { MovementManager } from "./MovementManager";
import { Piece } from "./Piece/Piece";
import { BoardArea } from "./BoardArea";

export class GameManager extends Behaviour {
    @serializable
    movementManager?: MovementManager;

    InitialPiecePlacement() {
        if (this.movementManager && this.movementManager.BoardArea2x2Matrix) {
            for (const column of this.movementManager.BoardArea2x2Matrix) {
                for (const boardArea of column) {
                    const piece = boardArea.pieceInCurrentArea;
                    if (piece) {
                        piece.PlacePiece(boardArea.gameObject);
                    }
                }
            }
        }
    }

    awake() {
        if (this.movementManager) {
            this.movementManager.InitBoardArea();
            this.movementManager.BoardArea2x2Matrix = [];
            this.movementManager.ConvertBoardArea();
        } else {
            console.error("Missing moveManager Reference");
        }

        this.InitialPiecePlacement();
    }
}

thread_567y7ByPEJSt39JwcFVJgfKw

Then, retest to check if the C# class for the GameManager is generated correctly after making this change. If issues persist, please ensure that the TypeScript file is located in the correct directory for the Needle Engine’s C# generation process to work properly.

3 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!

@Needle Engine Assistant can there be another cause for that? I don’t think @serializable is the reason.

by user 151660356224286721

Here is what I found for you :brain: Discord

There could be a variety of reasons why the C# code generation is failing. Here are some potential causes:

  1. Incorrect TypeScript Syntax: Ensure that the TypeScript code follows valid syntax and conventions. Any syntax errors or unsupported language features can lead to issues with the generation process.

  2. File Location: Verify that the TypeScript file is located within the appropriate directory that the Needle Engine uses for C# generation. The file must be in the expected location for the Needle Engine to recognize and process it.

  3. Project Configuration: Check the project’s configuration and settings for the Needle Engine. Ensure that the components and scripts are configured properly within the Needle Engine’s environment or Unity project.

  4. Correct Engine Version: Make sure that you are using the correct version of the Needle Engine for generating the C# code. If there are multiple versions, verify that you are working with the compatible version.

  5. Other Dependencies: If the TypeScript file relies on other custom classes, ensure that these are also correctly configured and compatible with the Needle Engine’s C# generation process.

I recommend addressing these aspects to troubleshoot the issue with the C# code generation. If after checking these points the issue persists, further investigation into the project and its setup may be necessary.

2 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw