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

@Needle Engine Assistant
show me an example using @dont-generate-componentin typescript

by user 151660356224286721

Certainly! The @dont-generate-component decorator in TypeScript is used to exclude a class from being generated as a component in the Needle Engine for Unity. Here’s an example of how you can use it:

import { Behaviour, dontGenerateComponent } from "@needle-tools/engine";

@dontGenerateComponent
export class HelperClass extends Behaviour {
    // Class implementation here
}

In this example, the HelperClass will not be generated as a component in the Needle Engine for Unity due to the @dont-generate-component decorator. This could be useful in scenarios where you have helper classes or utility classes that you don’t want to be treated as components in the Needle Engine’s code generation process.

2 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw

@Needle Engine Assistant

import { Piece,Piecetype } from “./Piece”;

export class Queen extends Piece
{
pieceType: Piecetype = Piecetype.Queen;

 awake()
 {
    super.pieceType= this.pieceType;
 }

}

but cs is not updated and shows

SourceFile
ImportDeclaration
ImportClause
NamedImports
ImportSpecifier
Identifier
ImportSpecifier
Identifier
StringLiteral
ClassDeclaration
Reading types file
Needle.Typescript.GeneratedComponents.Piece
Found class: Queen
NAMESPACE Needle.Typescript.GeneratedComponents
Queen inherits Needle.Typescript.GeneratedComponents.Piece
ExportKeyword
Identifier
HeritageClause
ExpressionWithTypeArguments
Identifier
PropertyDeclaration
Found variable pieceType: Piecetype = Piecetype.Queen;
Variable: pieceType
TypeReference: Piecetype
Piecetype
Child: TypeReference → Piecetype
EMIT member: “Piecetype” @pieceType Last type found: null
Identifier
TypeReference
Identifier
PropertyAccessExpression
Identifier
Identifier
MethodDeclaration
Identifier
Block
ExpressionStatement
BinaryExpression
PropertyAccessExpression
SuperKeyword
Identifier
FirstAssignment
PropertyAccessExpression
ThisKeyword
Identifier
Found codegen sections
Write to C:\UnityProjekt\KenSe\game\TestAR\Assets\Needle\Components.codegen/Queen.cs
EndOfFileToken

by user 151660356224286721

Here is what I found for you :brain: Discord

The code and output you’ve provided indicate that the TypeScript class Queen is attempting to set a property from its superclass Piece. The TypeScript code itself appears to be correct. However, the generated C# output is missing because you’ve only shared the console output, not the generated code itself.

Based on what you’ve shared, it looks like the TypeScript compiler recognizes the Queen class and identifies that it inherits from Piece with a property pieceType. However, without seeing the resulting Queen.cs file or the complete build log, it’s difficult to provide specific advice on why the C# class may not have been updated.

Here are some steps to consider:

  • Ensure that the Piecetype enum is correctly defined and exported in your TypeScript codebase, and the TypeScript to Unity component compiler knows how to handle it.
  • Verify that there are no conflicts in the project, such as another class with the same name or namespace issues that might prevent the updated Queen.cs from being generated.
  • Check the complete C# file Queen.cs and compare it to the intended TypeScript logic. If the property pieceType is not being set as expected, there might be an issue with how the compiler handles enum assignments or inheritance.
  • Make sure there are no errors during the build process that could prevent the C# file from being updated. Check the console log in Unity for any related errors or warnings.
  • If you’re using a version control system, ensure that the changes are being tracked, and there isn’t a mismatch between the local and remote repository states, which could mistakenly show an outdated version of the Queen.cs file.

If after taking these steps the issue remains, it may necessitate closer examination of both the TypeScript source and the C# output, alongside the Needle Engine’s documentation on class and component generation.

thread_567y7ByPEJSt39JwcFVJgfKw

4 messages left GPT 4
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!

@Needle Engine Assistant
import { Piece,Piecetype } from “./Piece”;

export class Rook extends Piece
{
pieceType: Piecetype = Piecetype.Rook;

 awake()
 {
    super.pieceType= this.pieceType;
 }

}

I am getting this message :
SourceFile
ImportDeclaration
ImportClause
NamedImports
ImportSpecifier
Identifier
ImportSpecifier
Identifier
StringLiteral
ClassDeclaration
Reading types file
Class type is unknown and will not generate a component: Rook

Piece.ts
import { Behaviour, getWorldPosition, serializable} from “@needle-tools/engine”;
import { Object3D, Vector3 } from “three”;
import { GameManager } from “…/GameManager”;

export enum Piecetype{
Default,
Pawn,
Knight,
Bishop,
Rook,
Queen,
King
}

export enum Color{
Black,
White
}

export class Piece extends Behaviour {
@serializable(Object3D)
public pieceTransform!: Object3D;

@serializable() 
public pieceType: Piecetype = Piecetype.Default;

@serializable() 
public color?: string;

CompareToOtherPiece(otherPiece : Piece): boolean
{
    return this.pieceTransform === otherPiece.pieceTransform &&
    this.pieceType === otherPiece.pieceType &&
    this.color === otherPiece.color;
}

PlacePiece(targetTransform : Object3D)
{
    const worldPos: Vector3 =  getWorldPosition(targetTransform);
    const loclConvertedPos: Vector3 = this.gameObject.parent!.parent!.worldToLocal(worldPos);
    this.gameObject.position.set(loclConvertedPos.x,loclConvertedPos.y,loclConvertedPos.z) ; 

}

GetAreaTransform()  
{

GameManager.getInstance().movementManager!.GetPieceBoardArea(this);
}

// SearchForMovableArea() : BoardArea
// {
// return
// }

}

by user 151660356224286721

Here is what I found for you :brain: Discord

Based on the code you provided, it appears that the Rook class is not being recognized as a component for generation. This can occur when the TypeScript to Unity component compiler is unable to infer the class type correctly for generation as a component.

Here are a few possible reasons this may be happening:

  1. Import and Visibility: Check if the Piece class is properly exported and accessible within the same context that Rook is being used.
  2. Enum Usage: Ensure that the Piecetype enum is correctly defined, imported, and used within the Rook class.
  3. Configuration: Verify that the TypeScript to Unity component compiler is set up to recognize and process the Rook class as a component.

To address this issue:

  • Ensure the correct export and import statements are used for the Piece class.
  • Confirm that the Piecetype enum is correctly imported and the property pieceType is of the correct type within the Rook class.
  • Double-check the project configuration or settings in the compiler to ensure that the Rook class is configured and recognized as a component for generation.

If the issue persists, consider reviewing the compiler’s documentation or reaching out to the support channels for the TypeScript to Unity component compiler to further investigate this issue.

3 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw

@Needle Engine Assistant
what is the correct import export for enum in this case ?

by user 151660356224286721

In TypeScript, importing and exporting enums follows a similar pattern to that of other types. Here’s the correct way to import and export the Piecetype enum:

In Piece.ts:

export enum Piecetype{
    Default,
    Pawn,
    Knight,
    Bishop,
    Rook,
    Queen,
    King
}

In the file where you want to use the Piecetype enum (e.g., Rook.ts):

import { Piecetype } from "./Piece";

This allows you to import the Piecetype enum into other TypeScript files so that it can be used as a type within those files. This is the typical approach for importing and using enums across multiple files in TypeScript.

2 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!

@Needle Engine Assistant
Debug :
SourceFile
ImportDeclaration
ImportClause
NamedImports
ImportSpecifier
Identifier
ImportSpecifier
Identifier
ImportSpecifier
Identifier
StringLiteral
ImportDeclaration
ImportClause
NamedImports
ImportSpecifier
Identifier
ImportSpecifier
Identifier
StringLiteral
EnumDeclaration
ExportKeyword
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumDeclaration
ExportKeyword
Identifier
EnumMember
Identifier
EnumMember
Identifier
ClassDeclaration
Found class: Piece
NAMESPACE Needle.Typescript.GeneratedComponents
Piece inherits UnityEngine.MonoBehaviour
ExportKeyword
Identifier
HeritageClause
ExpressionWithTypeArguments
Identifier
PropertyDeclaration
Found variable @serializable(Object3D)
public pieceTransform!: Object3D;
Variable: pieceTransform
TypeReference: Object3D
Child: TypeReference → UnityEngine.GameObject
EMIT member: “UnityEngine.GameObject” @pieceTransform Last type found: null
Decorator
CallExpression
Identifier
Identifier
PublicKeyword
Identifier
ExclamationToken
TypeReference
Identifier
PropertyDeclaration
Found variable @serializable()
public pieceType: Piecetype = Piecetype.Default;
Variable: pieceType
TypeReference: Piecetype
Reading types file
EMIT member: “Piecetype” @pieceType Last type found: null
Why can’t is pieceType: Piecetype = Piecetype.Default commented out?

by user 151660356224286721

Here is what I found for you :brain: Discord

It looks like the TypeScript to C# component compiler is having trouble parsing the @serializable decorator for the Piece class, specifically the pieceType: Piecetype = Piecetype.Default; line.

Based on this, I recommend the following steps to resolve the issue:

  1. Verify the Piecetype enum: Ensure that the Piecetype enum is correctly defined and accessible at the time and place where Piece is being declared.
  2. Review TypeScript syntax: Ensure that the TypeScript syntax, including the use of decorators and assignments, reflects valid TypeScript language features and conventions.
  3. Compiler configuration: Check the TypeScript to Unity component compiler configuration to see if there are any specific settings related to enum assignments within @serializable decorators.

By addressing these points, you may resolve the problem with parsing the @serializable decorator for the pieceType property. If you continue to encounter issues, it may be beneficial to consult the documentation for the TypeScript to Unity component compiler or seek support through their official channels for this particular issue.

1 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw

@Needle Engine Assistant
why is Piecetype not resolved in c#?

Piece.ts
import { Behaviour, getWorldPosition, serializable} from “@needle-tools/engine”;
import { Object3D, Vector3 } from “three”;

export enum Piecetype{
Default,
Pawn,
Knight,
Bishop,
Rook,
Queen,
King
}

export enum Color{
Black,
White
}

export class Piece extends Behaviour {
@serializable(Object3D)
public pieceTransform!: Object3D;

@serializable() 
public pieceType: Piecetype = Piecetype.Default;

@serializable() 
public color?: string;

CompareToOtherPiece(otherPiece : Piece): boolean
{
    return this.pieceTransform === otherPiece.pieceTransform &&
    this.pieceType === otherPiece.pieceType &&
    this.color === otherPiece.color;
}

PlacePiece(targetTransform : Object3D)
{
    const worldPos: Vector3 =  getWorldPosition(targetTransform);
    const loclConvertedPos: Vector3 = this.gameObject.parent!.parent!.worldToLocal(worldPos);
    this.gameObject.position.set(loclConvertedPos.x,loclConvertedPos.y,loclConvertedPos.z) ; 

}

}

Piece.cs
// NEEDLE_CODEGEN_START
// auto generated code - do not edit directly

#pragma warning disable

namespace Needle.Typescript.GeneratedComponents
{
public partial class Piece : UnityEngine.MonoBehaviour
{
public UnityEngine.GameObject @pieceTransform;
// public Piecetype @pieceType; → Could not resolve C# type
public string @color;
public void CompareToOtherPiece(object @otherPiece){}
public void PlacePiece(UnityEngine.GameObject @targetTransform){}
}
}

// NEEDLE_CODEGEN_END

public enum Piecetype
{
Default,
Pawn,
Knight,
Bishop,
Rook,
Queen,
King
}

public enum Color
{
Black,
White
}

by user 151660356224286721

Here is what I found for you :brain: Discord

The reason Piecetype is not resolved in the generated C# code for Piece is that the compiler is not recognizing the enum during TypeScript to C# code generation.

This issue could occur due to differences in how TypeScript and C# handle enums, or it may be related to the specifics of how the Needle Engine’s TypeScript to C# compiler interprets enums.

To address this, you can try the following:

  1. Run a Manual Check: Manually compare and examine the generated C# code for the Piecetype enum to ensure it has been appropriately generated and exported.
  2. Compiler Configuration: Investigate the TypeScript to C# compiler’s configuration in the context of enum resolution. There could be specific compiler settings related to enums that might need to be addressed.
  3. Consult the Documentation: Review the documentation or official resources for the Needle Engine’s TypeScript to C# compiler to understand how it processes enums and potential adjustments or special considerations that might need to be made.

By addressing these points, you may gain insights into why the Piecetype enum is not being resolved in the generated C# code, and identify the necessary steps to resolve the issue. If the problem persists, seeking support through official channels or forums specific to the Needle Engine’s TypeScript to C# compiler could provide valuable assistance.

0 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!

Dont generate component is added a the top of a class like this (as a comment) //@dont-generate-component

What i asked you to use is // @type YourNamespace.YourTypeName above a field.

I linked the docs in my post before. You should refer to the docs

thank you so much Marcel !

by user 151660356224286721