Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access from dialogue manager to a dictionary updated on runtime (on ready) #563

Closed
santifaster opened this issue May 8, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@santifaster
Copy link

Describe the bug
Error: Invalid get index 'char_name' (on base: 'Dictionary').
res://addons/dialogue_manager/utilities/builtins.gd:29 - at function:resolve_property

char_name is a key of the dictionary I'm trying to access
Affected version

  • Dialogue Manager version: v2.39.0
  • Godot version: 4.2.1.stable

To Reproduce
Steps to reproduce the behavior: Trying to access to a variable on a dictionary updated on runtime, on ready

I have an autoloaded script in the dialogue manager called dialogue_state in which I'm trying to store a dictionary with all the variables of every character in the scene.
var char_dict = {}

Then, I have a class character, that on ready it stores itself on the dictionary of dialogue_state, it is done this way to store only dynamically the characters on this scene.

class_name character

@onready var dialogue_state = %"Dialogue state"

#Dialogue stats
@export var character_name : String 
var times_talked : int = 0

func _ready():
	dialogue_state.char_dict[character_name] = self
	pass

And in the dialogue, I try to access the dictionary variables.

~ start

if char_dict.char_name.times_talked == 0:
	Name: Hello

So when I try to access a variable on the dictionary I get this error
imagen

Expected behavior
To be able to access times_talked of the desired character.

I'm able to access them from the script dialogue_state even if I can't from the dialogue manager

func _on_timer_timeout():
	print_dict()

func print_dict():
	for i in char_dict:
		print(char_dict[i].character_name)
	print(char_dict.char_name.times_talked)

But if I define the class in the definition of the dictionary instead of in the character, it works as it should be.

var char_dict = {"char_name": character.new()}

Thank you for your time.

@santifaster santifaster added the bug Something isn't working label May 8, 2024
@nathanhoad
Copy link
Owner

Can you provide a minimal reproducible project that demonstrates the issue?

@santifaster
Copy link
Author

Yes, of course, here you have it

A 2D scene where clicking on the godot sprite in game makes to start a dialogue

bug_dictionary_updated_runtime.zip

@nathanhoad
Copy link
Owner

You have two copies of your game state - an autoload (the correct one) and one in the local scene (the one you are accidentally editing in that example). You should remove the state node in the scene and then in your _ready function, update the global state instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants