Trying to send an additional boolean signal to members in a group already receiving signals

Godot Version

Godot 4

Question

Hi everyone,

I am making a custom DND character sheet in Godot basically for coding practice, as I am pretty new to it. As of right now, I have functions determining ability mods based on changing values from a score spinbox, and a function to add a proficiency bonus with a signal from a button toggle. Right now, the setup looks like this:

## Parent container for Stats and Skills, one example stat
func _ready() -> void:
  $Stats.supplies_mod_changed.connect(Skills.supplies_skill_mod)

##Stats, set modifier

func _on_supplies_score_value_changed():
var supplies_mod = (new_value - 10) / 2
var prof_bonus = %ProfBonus.value ## int = 2
$SuppliesMdd.value = supplies_mod
supplies_mod_changed.emit(supplies_mod)

##Skills

## Applies supplies_mod to supplies skills
func supplies_skill_mod(supplies_mod):
var  supplies_skill = get_tree().get_nodes_in_group("SupSkill")
for skill in get_children():
 for member in supplies_skill:
  for mod in member.get_children():
   if mod is SpinBox:
    mod.value = supplies_mod

##Applies prof_bonus based on toggle
func proficiency(is_toggled_on: bool, button_reference: Button):
var prof_bonus = %ProfBonus.value
var skill = button_reference.get_parent()
for mod in skill.get_children():
 if mod is SpinBox:
  if is_toggled_on:
   mod.value += prof_bonus
  else:
   mod.value -= prof_bonus

The problem I’m having is that if the button is already toggled, and then I adjust the score, supplies_mod doesn’t apply prof_bonus.

I think the fix I can do for this is to send a boolean argument to on_supplies_score_value_changed to check if the button is toggled, but I am pretty lost on how I would go about implementing that. I know I would need to send the argument to all of the nodes in the group, but do I check for that argument in the proficiency function and then send it as a separate signal? Do I even need the proficiency function?

Any and all help on this would be greatly appreciated, I am happy to clarify things if need be - I hope I have explained this properly.

How does proficiency() function get called?

Best to add add the %ProfBonus.value in supplies_skill_mod() so you wouldn’t need proficiency() method.

it’s called on button toggle, so could I combine those two functions?

You might find this post helpful/interesting as I used D&D as an example:

Specifically, take a look at the discussion of setters. You don’t necessarily need to be sending more signals, you just need to be setting values when certain things change.

I also go into how to use Resources to add modifiers so you don’t have to hardcode them in.

So, I’d say read that post (it’s long), and then let me know if you have questions. Because frankly, you’re already going in the wrong direction and things are going to get more complicated for you as you try to add new things.

To me it looks like you don’t need the emit at all. Just call func supplies_skill_mod(supplies_mod): from func _on_supplies_score_value_changed():

But the confusing part is how you expect the profbonus to do. What are the rules for adding it in? Do you need to preserve it between score changes or clear it and start again. In either case you need to test the is_toggled.

I would say write out some pseudo code/comments of what the logic is for your use case.