Skip to content

How do I declare a signal? #95

Answered by Splizard
nii236 asked this question in Q&A
Feb 5, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

If you just need to Emit values from Go to the engine/GDScript, you can use Go send-only channels for signals that send a single value, this has an example that works

https://github.com/grow-graphics/eg/blob/master/1d/signals/signals.go

package main

import (
	"time"

	"graphics.gd/classdb"
	"graphics.gd/startup"
	"graphics.gd/variant/Object"
	"graphics.gd/variant/Signal"
)

type Signals struct {
	classdb.Extension[Signals, Object.Instance]

	Something chan<- struct{} `gd:"something"`

	Generic Signal.Solo[int] `gd:"generic"`
}

func (s *Signals) DoSomething() {
	go func() {
		time.Sleep(time.Second)
		s.Something <- struct{}{}
		s.Generic.Emit(22)
	}()
}

func main() {
	classdb.Register[S…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Splizard
Comment options

@nii236
Comment options

Answer selected by Splizard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants