0 votes

I don't know why it behaves like this. The type is printed out correct but does not matter what the type number is, the ActiveSlot03 animation gets to play all the time. Is that any thing wrong with my code? Thank you.

if event.is_action_released("ui_accept"):
    if type == 1 || 4:
    if type == 2 || 5:
    if type == 3 || 6:
Godot version v3.2.3
in Engine by (260 points)

1 Answer

+1 vote
Best answer

You can't compare a variable to two other values with an or like that. You need to write two comparisons.

by (7,769 points)
selected by

Thank you for your help, I took your advice and as I put if type == 1 || type == 4: it works now. There are still some thing about this I don't quite understand.

With my code in the question, why it could till run and play the ActiveSlot03 all the time?What is the logic behind that?

I used to use write two comparisons before, but once I tried without it, and found out it still works fine. In fact, in the sam script, I have follow code without any issue when running. So I am a bit confused, but I will stick to two comparisons just to be safe.

if slotSelection == 4 || 5:

It's casting the second integer to a Boolean. Every int except 0 casts to true and since your last if statement plays active slot 03 it will always play.

That makes sense now, thank you for making things clear to me.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.