Try explaining everything about the problem you’re having and also the whole related code.
(Edit: ignore the “test” member as it’s something unrelated I had in the same script by mistake)
This is my player script and my only script, I am making a duel game where to ready your gun you click either up or down and to shoot you either click left or right and after every successful shot I want it to randomize the up, down, left, right or 1,2. Every time I try to randomize ready_button and shoot_button with randi_range(1,2) it doesn’t change the value, only the arrows I have ingame change. So I am wondering how do I randomize the value of shoot and ready button variables.
extends Node2D
var another_shot: bool = false
var good_ready: bool = false
var good_shoot: bool = false
var failed: bool = false
var can_fire: bool = false
var _ready_button = 1
var _fire_button = 1
var completed: bool = false
func _ready() -> void:
_ready_button = randi_range(1, 2)
_fire_button = randi_range(1, 2)
func fire():
_ready_button = randi_range(1, 2)
_fire_button = randi_range(1, 2)
print("BAM!!!")
func _process(_delta: float) -> void:
if not failed and $Prepare.is_stopped():
if can_fire:
if _ready_button < 2:
$CanvasLayer/ColorRect/Down.visible = true
if Input.is_action_just_pressed("ready_down"):
$Lone.play("ready")
good_ready = true
print("Aha!")
$CanvasLayer/ColorRect/Down.visible = false
elif Input.is_action_just_pressed("ready_up"):
$Lone.play("idle")
failed = true
print("Argh I failed")
$CanvasLayer/ColorRect/Down.visible = false
if _ready_button > 1:
$CanvasLayer/ColorRect/Up.visible = true
if Input.is_action_just_pressed("ready_up"):
$Lone.play("ready")
good_ready = true
print("Aha!")
$CanvasLayer/ColorRect/Up.visible = false
elif Input.is_action_just_pressed("ready_down"):
$Lone.play("idle")
failed = true
print("Argh I failed")
$CanvasLayer/ColorRect/Up.visible = false
if good_ready and not failed:
$CanvasLayer/ColorRect/Up.visible = false
$CanvasLayer/ColorRect/Down.visible = false
if _fire_button < 2:
$CanvasLayer/ColorRect/Left.visible = true
if Input.is_action_just_pressed("fire_left"):
$Lone.play("fire")
fire()
print("Aha!")
completed = true
$CanvasLayer/ColorRect/Left.visible = false
$CanvasLayer/ColorRect/Right.visible = false
elif Input.is_action_just_pressed("fire_right"):
$Lone.play("idle")
failed = true
print("Argh I failed")
$CanvasLayer/ColorRect/Left.visible = false
$CanvasLayer/ColorRect/Right.visible = false
if good_ready and not failed:
$CanvasLayer/ColorRect/Up.visible = false
$CanvasLayer/ColorRect/Down.visible = false
if _fire_button > 1:
$CanvasLayer/ColorRect/Right.visible = true
if Input.is_action_just_pressed("fire_right"):
$Lone.play("fire")
fire()
print("Aha!")
$CanvasLayer/ColorRect/Right.visible = false
$CanvasLayer/ColorRect/Left.visible = false
completed = true
elif Input.is_action_just_pressed("fire_left"):
$Lone.play("idle")
failed = true
print("Argh I failed")
$CanvasLayer/ColorRect/Right.visible = false
$CanvasLayer/ColorRect/Left.visible = false
func _on_prepare_timeout() -> void:
print("I can shoot")
can_fire = true
$TimeToShoot.start()
$Lone.play("idle")
another_shot = false
func _on_time_to_shoot_timeout() -> void:
if completed:
can_fire = false
good_ready = false
another_shot = true
$CanvasLayer/ColorRect/Right.visible = false
$CanvasLayer/ColorRect/Left.visible = false
print("Yippee Ki-Yay!")
$Lone.play("ready")
$Prepare.start()
if failed:
print("AHhhhhhHHHhhH!!!")
$Blood.visible = true
$StartDead.start()
if not completed:
print("Too Slow!!! >:D")
$Blood.visible = true
$StartDead.start()
func _on_start_dead_timeout() -> void:
$CanvasLayer/ColorRect/Down.visible = false
$CanvasLayer/ColorRect/Up.visible = false
$CanvasLayer/ColorRect/Left.visible = false
$CanvasLayer/ColorRect/Right.visible = false
$Blood.visible = false
$Lone.play("dead")
can_fire = false
failed = true
Your range is 1 to 2, it will never be less than 1, and never be more than 2, so your conditions will always be true. Apologies I thought this was randf_range for floating point values.
What are you expecting to happen and what really happens?
Lets zoom out, how did you happen upon this issue? Why do you think the value isn’t being assigned? Surely you expected something to happen in-game, and it didn’t play out that way. What did you expect to happen in your game, and what really happened?
My sprite is connect to the randomization and it showed left so i clicked left but it said i got it wrong. I don’t know why the value is being assigned, when randomized. I expected the directions of arrows to change. When i click the arrow that it displays my character will pull out his gun. The quick time event happens again and I shoot after hitting the arrow key it tells me to.