func _on_h_slider_value_changed(value):
if value == 4 || value == 5 || value == 6:
height_global == true
func _on_h_slider_2_value_changed(value):
if value == 5 || value == 6 || value == 7:
frequency_global == true
Question
I am receiving an error of âInvalid operands âboolâ and âintâ in operator â==â.â in
if value == 5 || value == 6 || value == 7:
I am quite new so I am struggling, I wanted to know how to fix it! Thank you all!
And frequency_global is set to false, which is a boolean.
That means that in this function:
func _on_h_slider_2_value_changed(value):
if value == 5 || value == 6 || value == 7:
frequency_global == true
Weâve passed in a bool as the value parameter, which you then try to compare to various integers. The error message is telling you that that doesnât make sense.
Which value is it you actually want to compare to those numbers?
I want to compare the values of my horizontal slider so that if it falls within the specified range of 5-7 it will return true and if it returns true on the other horizontal slider with another range it will change colors.
If that does not make sense please let me know and Iâll be happy to clarify!
It does make sense, but⌠Ok, so this code is attached to a Sprite2D node, right? At least it says extends Sprite2D at the top, so I assume it must.
So, is _on_h_slider_2_value_changed meant to be called when a signal is sent from the slider itself? If so, why are you calling it in the _ready function on the Sprite2D? What is supposed to happen there?
_on_h_slider_2_value_changed(7) # or whatever number you want
Or you can just set those boolean values directly.
Also, I just noticed that you said you wanted to check whether the value is within a range - for that, youâll need to use comparison operators like <, <=, >= or >, rather than ==. Some examples:
if x == 5 || x == 7:
print("x is exactly 5 or exactly 7")
if x >= 5 && x <= 7:
print("x is between 5 and 7 (inclusive on both ends)")
if x > 5 && x <= 7:
print("x is greater than 5 and is smaller than or equal to 7")
You can paste code between three tick marks. Press the </> button on a new like so
```
type or paste code here
```
Your new screenshot doesnât include some vital lines. The two global variables you want to change were changed by calling this function, nothing special needed to happen.
func _on_h_slider_value_changed(value):
if value == 4 || value == 5 || value == 6:
height_global == true #should be one equals sign for assignment
func _on_h_slider_2_value_changed(value):
if value == 5 || value == 6 || value == 7:
frequency_global == true #also should be one equals sign
After calling these functions, if the passed value parameter was 5 < x < 7 your globals would be set to true. These functions do not return anything so they cannot be used as conditions in an if statement.
func _ready() -> void:
_on_h_slider_value_changed(7)
_on_h_slider_2_value_changed(8)
if frequency_global and height_global:
texture_rect.modulate = Color.YELLOW
The confusing part is where 7 and 8 come from, what values do you really want? where do these values come from?
func _ready() -> void:
_on_h_slider_value_changed(6)
_on_h_slider_2_value_changed(6)
if height_global and frequency_global:
texture_rect.modulate = Color.YELLOW
func _on_h_slider_value_changed(value):
if value >= 5 && value <= 7:
height_global = true
return height_global
func _on_h_slider_2_value_changed(value):
if value >= 5 && value <= 7:
frequency_global = true
return frequency_global
This is what I have now, I see what you meant by needing that code. My only issue is that it immediately turns yellow when the game begins and I want it to wait for the userâs input of say 6 and 6 on the sliders to turn yellow.
You probably want to change the color as part of the connected signal, not _ready
func _on_h_slider_value_changed(value):
if value >= 5 && value <= 7:
height_global = true
if height_global and frequency_global:
texture_rect.modulate = Color.YELLOW
func _on_h_slider_2_value_changed(value):
if value >= 5 && value <= 7:
frequency_global = true
if height_global and frequency_global:
texture_rect.modulate = Color.YELLOW