0 votes

So I am using a randomize() function to shuffle a music playlist in my game and am also using randomize() to shuffle a "treasure array" so that items picked up are never in the same spot. Problem is my music is shuffling anytime I shuffle the array. Pretty sure the RNG seeding is conflicting, causing my tracks to shuffle whenever my event is called - how would I go about fixing this? I have tried also creating a separate random number generator and am getting the same result.

Code for universal sound object:

    extends Node

## get nodes!
onready var _calm = get_node("Calm")
onready var _pursuit = get_node("Pursuit")
onready var _hidden = get_node("Hidden")
onready var _escape = get_node("Escape")
onready var _chance = get_node("ChanceMusic")
onready var _death = get_node("DeathMusic")
onready var _sfx = get_node("SoundEffects")

## rng containers
var _calmTrack = 0
var _chaseTrack = 0
var _nowPlaying = true
var _myrng = RandomNumberGenerator.new()

## resource enumerations
const _calmTracks = [

const _pursuitLoops = [

const _hiddenLoops = [

const _escapeShots = [
] ### one shots not loops!!!

const _sceneBGM = [

const _soundFX = [

## connect calm loop at ready
func _ready():
    var _reset_ = _escape.connect("finished",self,"_calm_music")
    var _calmLoop = _calm.connect("finished",self,"_calm_music")

## update music state each frame
func _process(_delta):
    if _nowPlaying:
        if Director._inPursuit == false and _calm.playing == false:

        if Director._inPursuit == true and Director._playerIsHidden == false and _pursuit.playing == false:
            if Director._nowDead == false:

        if Director._enemyHere == true and Director._playerIsHidden == true and _hidden.playing == false:

        if Director._chanceEvent == true and _chance.playing == false:

        if Director._nowDead == true and _death.playing == false:

    if _nowPlaying == false:

    if Director._eventFlag == true:

## calm or default music
func _calm_music():

    if _calm.playing == false and _escape.playing == false:
        var _myCalm = _calmTracks[_calmTrack]
        _calm.stream = load(_myCalm)
    if _calm.playing == false and _escape.playing == true:
        var _myCalm = _calmTracks[_calmTrack]
        _calm.stream = load(_myCalm)

    if Director._inPursuit == true:

    if _calm.playing == false:

## pursuit music
func _pursuit_music():
    if Director._chanceEvent == false:

    if _pursuit.playing == false:
        var _myStress = _pursuitLoops[_chaseTrack]
        _pursuit.stream = load(_myStress)

    if Director._playerIsHidden == true:

## hidden music
func _hidden_music():

    if _hidden.playing == false:
        var _mySuit = _hiddenLoops[_chaseTrack]
        _hidden.stream = load(_mySuit)

    if Director._playerIsHidden == false:

## escape function, one shot that connects back to calm loop
func _escape_music():
    var _myEsc = _escapeShots[_chaseTrack]
    _escape.stream = load(_myEsc)

## last chance bgm
func _chance_music():
    var _myChance = _sceneBGM[3]
    _chance.stream = load(_myChance)

## dead music, death screen
func _dead_music():
    var _myDeath = _sceneBGM[4]
    _death.stream = load(_myDeath)

### clunk at death screen (transition noise one-shot)
func _dead_noise():
    var _deathsound_ = "res://music/sfx/ambient_hit.ogg"
    _sfx.stream = load(_deathsound_)

## title theme, continues into game on start then loops back to start
func _title_music():
    var _myTitle = _sceneBGM[0]
    _calm.stream = load(_myTitle)

## stop all music
func _stop_bgm():

## rng function to change song pull
func _shuffle_bgm():
    _calmTrack = _myrng.randi_range(0,5)## this method avoids errors
    _chaseTrack = _myrng.randi_range(0,4) 

Then my "treasure" function.

    extends "res://events/BasicEventShell.gd"

onready var _look = $CanLook
onready var _text = $TextBox
export var _myKeyName : String ## set in editor or events consume each other. Gross.
export var _myText : String ## set dialogue message

# set key name and signals, remove prompt
func _ready():
    _myEventKey = _myKeyName
    var _p_on = self.connect("body_entered",self,"_prompt_on")
    var _p_off = self.connect("body_exited",self,"_prompt_off")
    _look.visible = false

## hide prompt when consumed
func _process(_delta):
    if _eventToggle:
        _look.visible = false

# randomize seed, pull treasure and toggle off
func _thisEvent():
    Director._eventFlag = true
    var _loot = StageHand._treasureArray.pop_front()
    _text._update_(str(_myText) + str(_loot) + "...")
    _eventToggle = true

## turning prompts on and off, and staying off when consumed
func _prompt_on(body):
    if body.name == 'Lydia' and _eventToggle == false:
        _look.visible = true

func _prompt_off(body):
    if body.name == 'Lydia':
        _look.visible = false

## remove text on second button press, do not allow until text is full
func _input(_event):
    if _eventToggle == true and _text._text_display == true:
        if Input.is_action_just_pressed("ui_accept"):
        if Input.is_action_just_pressed("ui_left"):
        if Input.is_action_just_pressed("ui_right"):
Godot version v3.4.3.stable.official [242c05d12]
in Engine by (548 points)

1 Answer

0 votes

Nevermind on that, I decided on a different format for my music. Since all of Godot's RNG uses a seed generator, I am giving myself too much work trying to segregate these. I also just noticed the randomize is in the process function, which is probably the cause.

by (548 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 Frequently asked questions and 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 [email protected] with your username.