Skip to main content
  1. About
  2. For Teams
Asked
Viewed 440 times
1

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.

1
  • 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
    –  Theraot
    2023-07-21 22:08:37 +00:00
    Commented Jul 21, 2023 at 22:08

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.