- Edited
Hello!
I've looked around but can't find an answer for why this is not working. I'm using a C# library to handle OSC messages to interface with Supercollider and am trying to send a signal out with some data to a root node that controls the scene. Currently, I have access to the signal in the inspector but when I attempt to emit the signal I get an error. Here's my code:
`using Godot;
using System;
using System.Net;
using SharpOSC;
public partial class OSCServer : Node
{
[Signal]
public delegate void SendLightEventHandler(int val);
//private static UDPSender send;
private static UDPListener reciever;
public static int light_val;
public static int port = 8003;
public static string IPAddress = "127.0.0.1";
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
//send = new UDPSender(IPAddress,port);
reciever = new UDPListener(8004, callback);
//passing = GetParent.GetChild()GetNode<Node3D>("Sub");
}
HandleOscPacket callback = delegate(OscPacket packet)
{
var messageReceived = (OscMessage)packet;
// GD.Print(messageReceived.Arguments);
var light_val = messageReceived.Arguments[0];
//EmitSignal("Sendo", 2);
EmitSignal(SignalName.SendLight, 1);
};
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}
`
And here's the error when I attempt to build the project:
A field initializer cannot reference the non-static field, method, or property 'GodotObject.EmitSignal(StringName, params Variant[])'
Any help would be greatly appreciated.
Edit: Removing the emitting code from the OSC callback function seems to fix the compiler error. I've put it in the process function instead, which works until I try to convert the incoming OSC message to useable data.
New code:
` public override void _Process(double delta)
{
messageReceived = (OscMessage)receiver.Receive();
// GD.Print(messageReceived);
if (messageReceived == null)
{
var new_val = messageReceived.Arguments[0];
EmitSignal(SignalName.SendLight, new_val);
GD.Print("here");
}
}
`
And the new error:
Argument 2: cannot convert from 'object' to 'Godot.Variant'