Forum

Dynamic plugins, trouble with input pins and output data types

devvvv

#1

hi, i am trying to get into dynamic plugins. That is my first time experimenting with c# and the code editor. The code below is taken more or less from the web and it is kind of working but there are some points i can not figure out myself.

It is supposed to post to a facebook wall. This is working, but…

  1. I am able to read the facebook responses from tty only for now. I have tried to output them via FOutput pin but the code editor keeps telling me: “can not implicitly convert type char to string”. The used variable is declared as string. how am i supposed to convert it to the right data type?
    The code is running fine in sharpdevelop and the responses show up in the console “Console.Write(Response…)”

  2. I have tried to feed the post text from an Input pin but it does not work for me, so for now i have to “hardcode” the text (see “Test123”). I have replaced the “Test123” with the FinputText variable but then “VVVV.Hosting.Pins.Input.StringInputPin: InputText” is posted. is there something obvious i am doing wrong?

    FOutputi = FInputTexti;

for example works ok
I hope someone can give me some hints.

- region usings
using System;
using System.ComponentModel.Composition;

using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.VColor;
using VVVV.Utils.VMath;
using System.Net;
using System.Text;
using VVVV.Core.Logging;
- endregion usings

namespace VVVV.Nodes
{
	#region PluginInfo
	[PluginInfo(Name = "Testing", Category = "String", Help = "Basic template with one string in/out", Tags = "")](PluginInfo(Name = "Testing", Category = "String", Help = "Basic template with one string in/out", Tags = ""))
	
	#endregion PluginInfo
	public class StringTestingNode : IPluginEvaluate
	{
		#region fields & pins
		
		[Input("Bang", IsBang=true, IsSingle=true)](Input("Bang", IsBang=true, IsSingle=true))
        ISpread<bool> FInput;
		
		[Input("InputText")](Input("InputText"))
		ISpread<string> FInputText;
		
		[Output("Output")](Output("Output"))
		ISpread<string> FOutput;

		[Import()](Import())
		ILogger FLogger;
		#endregion fields & pins

		//called when data for any output pin is requested
		public void Evaluate(int SpreadMax)
		{
	
	byte[]() MessageToPost = null;
	byte[]() ResponseFromServer = null;
	string AccessToken = "XXXXXXXXXXXXXXXX";
	string GraphURL = "https://graph.facebook.com/me/feed";	
			
				
if (FInput[0](0)) 
			try {
	
	MessageToPost = Encoding.UTF8.GetBytes("message=" + "Test123"
  + "&access_token=" + AccessToken);
	
	System.Net.WebClient myWebClient = new System.Net.WebClient();
	
 	ResponseFromServer = myWebClient.UploadData(GraphURL, MessageToPost);
 
	string ResponseFromServerAsString = (System.Text.Encoding.UTF8.GetString(ResponseFromServer));
 	
	FLogger.Log(LogType.Debug, ResponseFromServerAsString);
				
	FOutput.SliceCount = SpreadMax;
	// for (int i = 0; i < SpreadMax; i++)
	// does not work-> FOutput[i](i) = ResponseFromServerAsString[i](i);
			
} catch (Exception ex) {FLogger.Log(LogType.Debug, ex.Message);}
				
		}
	}
}

#2

ResponseFromServerAsString is of type string or in other words a collection of characters.
ResponseFromServerAsStringi is of type char (the ith character of the response string).

FOutput is of type ISpread or in other words a collection of strings.
FOutputi is of type string (the ith string in the output spread).

what you’re trying todo, assigning a character to a string, is not possible as the compiler already told you. the types don’t match. a variable of type character can’t be assigned to a variable of type string and the other way round.

you have two options here:

  • remove the for loop and simply write FOutput0 = ResponseFromServerAsString
  • move the for loop a few lines up and generate a response string for each string contained in FInputText

#3

ok i see, thank you for explaining. i have got it working now that far. the input works too. much to learn… :)