0 votes

I use this code below for this action. I tried to use a Boolean to show the button has been pressed but it just makes both the if and the elif true. My understanding was that with an if/elif statement, if the if is true, it ignores the rest but that doesn't seem to be the case. Help me :)

my code

Godot version 3.4
in Engine by (12 points)

2 Answers

0 votes

The if / elif construct will indeed only execute one of the variants depending on the condition, however your function might be triggered more often than you would expect. Depending on how you wire the function, it might respond to mouse releases or mouse motion, which you might detect as instantaneous. Try putting the if event is InputEventMouseButton and if event.is_pressed() conditions outside of the filled check.

by (1,259 points)
0 votes

It's probably reacting to a different input event (such as InputEventMouseMotion and executing immediately after.
You should move the whole code block into the "if event i InputEventMouseButton:" block.

  if event is InputEventMouseButton && event.is_pressed():
       the rest of your code here

Also, you should store the textures in a variable and use preload instead of load... otherwise you're loading the texture each time you click.

var YellowVialTexture = preload ("res://......" )
by (1,258 points)
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.