0 votes

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
    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

    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;
asked Jan 2, 2019 in Projects by catafest (41 points)

1 Answer

+1 vote
Best answer

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

answered Jan 2, 2019 by p7f (1,912 points)
selected Jan 4, 2019 by catafest


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#)

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?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.