Godot Version
4.2.1
Question
I am trying to recreate an old quiz program that I previously wrote in a Flash based language - using Godot as it seems the easiest for me to get my head around - or so I thought lol
2 of the rounds require music to be played for each question (12 questions in each round)
In my old system, the audio files were in a folder and numbered sequentially - the program would then load the file - file name being created by concatenating a String (i.e “R5_Q”) and the current question number.
I’ve managed to do this using load() but was wondering if this was the best way to do this, or if I’m missing something.
I know I could put them into a AudioStreamRandomizer - but that will only play sequentially and not let me skip back if I need to (as far as I can tell).
I’ll put the code I’ve been testing with below (new to the engine, so please don’t laugh too much lol) but all I was doing in there was seeing if I could skip backwards and forwards with tracks.
Hope this makes sense - my wife says that I don’t very often - and thanks in advance
extends Node2D
@onready var music_player: AudioStreamPlayer = $AudioStreamPlayer
@onready var music_stream: AudioStream
@onready var next: Button = $ButtonNext
@onready var prev: Button = $ButtonPrev
var music_length: float
var music_time: float
var line_scale: float
var music_int: float
var temp: int = 0
var temptxt
var music_counter: int = 0
var music_counter_prev: int = 0
func _ready():
pass
func _process(delta):
if music_player:
music_time = music_player.get_playback_position()
$Label.text = "%.1f" % [(music_length - music_time)]
line_scale = music_time/music_length
$Line2D.scale.x = line_scale
func _on_button_next_pressed():
temp = music_counter
music_counter += 1
if music_counter == 5:
music_counter = 1
play_music()
func _on_button_prev_pressed():
temp = music_counter
music_counter -= 1
if music_counter == 0:
music_counter = 4
play_music()
func play_music():
temptxt = load("res://MusicTemp/R5_EN_Q"+ str(music_counter)+".mp3")
music_player.stream = temptxt
music_player.play()
music_length = music_player.stream.get_length()