C# : error: The name 'KEY_A' does not exist in the current context

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By catafest

How can solve this issue?
I create a scene with a sprite player and I add this scene to default scene.
I add the C# script to the sprite player:
I got this error:

error CS0103: The name 'KEY_A' does not exist in the current context

This is my script player:

using Godot;
using System;

public class Player : KinematicBody2D
{
	[Export]
	private Vector2 motion = new Vector2(0, 100);
    // Member variables here, example:
    // private int a = 2;
    // private string b = "textvar";
	public override void _Ready()
	{
        // Called every time the node is added to the scene.
        // Initialization here
		GD.Print("Hello");
	}
	
	public override void _PhysicsProcess(float delta)
	{
		MoveAndCollide(motion * delta);
	}

	public override void _Input(InputEvent ev)
	{
	    if (ev is InputEventMouse)
	    {
	        var mouseEvent = (InputEventMouse)ev;
	        Vector2 mousePos = mouseEvent.Position;
	    }
	    else if (ev is InputEventKey)
	    {
	        var keyEvent = (InputEventKey)ev;
	        bool aPressed = keyEvent.Pressed && keyEvent.Scancode == KEY_A;
	    }
	}
}
:bust_in_silhouette: Reply From: p7f

Im not C# programmer, but isn’t for that lamguage the correct syntax this?
eventKey.Scancode == (int)KeyList.A

“Multumesc!”

Thank you.
The C# is very versatile and the Godot API scripting (GD is more to LUA or VB programming).
Yes, the typecast return to the int and seem to be normal to return it to bool not an int like the C# public getScanCode ( ) : int.
and is the problem with ASP programming area.


The official page come with this error, the development team seam not very skilled to implement the C# Godot A.P.I. (I don’t see many tutorials or video tutorials with Godot and C#)
Introducing C# in Godot

catafest | 2019-01-03 13:29

that link is not official documentation, but an article. And it’s a bit old, idk if in previous versions it was like that and now it changed. You can use official docs and change script snippets to C# in ordert to see acutal correct syntax.

P.S: did my answer solved the issue?

p7f | 2019-01-03 14:00