The difference in bind() between GDScript and C#
Asked Answered
S

2

0

In GDScript, I defined a signal a in A that has no parameters (which is important!). In B, I connect signal a to my event b (i: int), and I can easily bind the built-in properties in B, such as (A.a. connect (b. bind (count)))
But in C #, I don't know how to bind properties like this. Because I cannot set the parameter in signal a, once set, I must carry this parameter when sending the signal. However, I want my parameter to be obtained from B instead of being carried by A when sending the signal. What should I do?

Swen answered 20/2 at 13:46 Comment(0)
S
0

I am connecting under foreach, for example:
foreach(int i in arr){
A aIn = AScene.Instantiate() as A;
aIn.a += b;
}
b(int i){}

I don't know how to bind different i to method b

Swen answered 20/2 at 13:50 Comment(0)
S
0

I have fallen into a misunderstanding. The solution to this problem is actually very simple, which is to use nested methods like the following:
A.a += () => {b(i);};

I hope this answer can also help you who are also troubled!

Swen answered 20/2 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.