0

Iam making a simple game in godot and I have 2 scripts for my plaer: movement and shooting. I would like to combine them somehow but IDK how. Also Im new to godot so I would appreciate if someone explained it to me with simple temrs. Thanks!!!

I tried to combine them manually with pasting everything into _ready and _process but it doesnt work like that.

  • I don't know why you had problem combining your scripts. You see "doesn't work" is not a good problem descriptor. I don't even know if it fails to parse, causes an error in runtime, or behaves incorrectly. My guesses are that It it was some indentation problem (failing to parse) or some early exit `return` that you need to work around (wrong behavior). – Theraot Jul 21 '23 at 22:08

1 Answers1

1

Without knowing the details of your problem, this is the only solution that comes to mind:

  • Copy the methods but give them a suffix. For example _ready_movement and _ready_shooting, and _process_movement and _process_shooting.

  • Call them both from when appropriate. For example:

    func _ready() -> void:
        _ready_movement()
        _ready_shooting()
    

    And:

    func _process(delta:float) -> void:
        _process_movement(delta)
        _process_shooting(delta)
    

That should avoid problems of either early exit of one of the methods making the other not run (resulting in incorrect behavior), or some conflict between the naming of local variables (which would fail to parse).

It should also minimize the chances that you introduced some indentation issue when copying and pasting the code.

You might also be interested in: What's the appropiate way to achieve composition in Godot?

Theraot
  • 31,890
  • 5
  • 57
  • 86
  • Hi. I am sorry that I didint say enough about my problem. I am not a proffesional programmer and I started learning gd a few weeks ago. Ill try to explain one again. Ihave 2 scripts: PlaerShooting and PlaerMovement and I would like to make them work at the same time. I have no idea how to combine them. Could you please explain how to combine scripts in godot if you were trying to teach it to a little kid lmao. – give skeet Jul 22 '23 at 15:49