Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sanlem |
Hi! I have a trouble with autocomplete. I’m using Apple MacBook Air M1 2020 and Godot Engine v3.4.4.stable.official.419e713a2
First example:
extends MovementState
class_name GroundMovement
export(float) var _magnitude := 5.0
onready var _controls: PlayerControls = $"../../Controls" as PlayerControls
var _input_movement := Vector3.ZERO
var _movement := Vector3.ZERO
func should_enter() -> bool:
return true # _body.is_on_floor()
func should_exit() -> bool:
return false # !_body.is_on_floor()
func enter() -> void:
print("Entered Ground state!")
func exit() -> void:
print("Exited Ground state!")
func process_movement(delta: float) -> void:
# _input_movement = _controls. - no autocomplete
_input_movement = _controls.get_movement()
_movement = _input_movement * _magnitude
_body.move_and_slide(_movement, Vector3.UP, true)
Inside process_movement, when i type _input_movement = _controls. I get no autocomplete!
Here is PlayerControls source:
extends Node
class_name PlayerControls
var _movement := Vector3.ZERO
func get_movement() -> Vector3:
_movement = Vector3.ZERO
if Input.is_action_pressed("move_forward"):
_movement.z += 1.0
if Input.is_action_pressed("move_backward"):
_movement.z += -1.0
if Input.is_action_pressed("move_right"):
_movement.x += 1.0
if Input.is_action_pressed("move_left"):
_movement.x -= 1.0
return _movement.normalized()
Second example: I have a class that is supposed to be a movement state machine. Here is the code:
extends Node
class_name MovementStateMachine
var _current_state: MovementState = null
var _states := []
func _ready() -> void:
for child in get_children():
if child is MovementState:
var new_state := child as MovementState
_states.append(new_state)
print("Registered state %s" % new_state.name)
_current_state = _get_new_state()
if _current_state == null:
push_error("Failed to get initial MovementState!")
get_tree().quit()
func _get_new_state() -> MovementState:
var current_state: MovementState = null
for state in _states:
current_state = state as MovementState
# if current_state. - no autocomplete
if current_state.should_enter():
return current_state
return null
func _process(delta: float) -> void:
# _current_state. - no autocomplete
_current_state.process_movement(delta)
I’m using static typing and class_name, but autocomplete still doesn’t work! I will realy appreciate your help.
Maybe it’s a bug. Have you tried putting in code like this?
var _input_movement: Vector3 = Vector3.ZERO
var _movement: Vector3 = Vector3.ZERO
Ertain | 2022-04-20 23:35