0 votes

I have a button that emits the signal "rolladice(0, 20)" and a number gets chosen from 0 to 20, but how do I get the "return roll" at the bottom of the "rolladice()" signal?

in Engine by (62 points)

2 Answers

0 votes

In the function, couldn't you just store the number chosen in a variable and then write
return rolledNumber or something like that?

by (192 points)

While signal callbacks can return a value, that returned value won't be passed back to the signals emitter. So no, that's no solution for this problem.

+1 vote

how do I get the "return roll" at the bottom of the "rolladice()" signal?

You don't! If your signal callback returns a value, that value won't reach the emitter. If you want to do that, don't use a signal but call the diceroll-function directly.

You can work around that as described here, e.g.:

signal roll_a_dice(min_val, max_val)

func _ready():
    connect("roll_a_dice", self, "_on_roll_a_dice")

    var roll = []
    emit_signal("roll_a_dice", 0, 20, roll)

func _on_roll_a_dice(min_val, max_val, roll):
    roll.append(randi() % max_val + min_val)

But unless you have very good reasons for it, I wouldn't recommend that.

by (10,467 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 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 webmaster@godotengine.org with your username.