Value as a string from a void function

Hello,i have these two functions in the end of a code and i call into the draw() the function displayinformation() to show in the screen of Android the characteristics(Name, age,…) everytime i select a specific choice from a list. My problem is that after this procedure i want to send an OscMessage with this characteristics and i do not know how can i add the Information from the void Information function as a string.

void displayinformation(){
  if (selection.equals("1")) {
    Information("John", 30);
  }
  if (selection.equals("2")) {
    Information("Melanie", 40,);
  } 
}

void Information (String name, int age) {
  textSize(60);
  fill(0); 
  text("Name:"+name, 800,500);
  fill(0);
  text("Age:"+age, 850, 600);
}

For example i want to put in my code this function but i can not use information as a Sting value:

OscMessage myMessage = new OscMessage ( "Characteristics" + information );
      myMessage.add(information);
    oscP5.send(myMessage, remoteLocation);

If you need something out of a function, it can’t return void (nothing)! :wink: You could return a String.
And method (function) names should start lower-case by convention.

String information (String name, int age) {
  textSize(60);
  fill(0); 
  text("Name:"+name, 800,500);
  fill(0);
  text("Age:"+age, 850, 600);
  return "Name: " + name + "\nAge: " + age;
}

I have also tried the string function but when i put the name as as string in the function myMessage.add(name) into draw the console shows me that the variable name does not exist.

what do you mean with ‘‘should start lower-case by convention’’ ???

https://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html

2 Likes

ok i understood what does this mean and i am doing all these above, but the problem still exists…
Please help me…

Is there a way that i can add in the OscMessage the function displayinformation()???
i just want to send wireless in my PC via oscP5 library whatever is into display() method into draw().
Something like :

OscMessage myMessage = new OscMessage ( "Characteristics" + information );
      myMessage.add(displayinformation);
    oscP5.send(myMessage, remoteLocation);

not this way, you use in the creation of “myMessage”
information
displayinformation
in the wrong way.

  • displayinformation does not return a string
  • information might if you call it correctly
    if using @neilcsmith example:
    information(“Anna”,77)
    could do the job by returning “Name: Anna\nAge: 77”
    and put it also to the canvas window.
    this mix might not be wanted.

if i use the @neilcsmith example the problem still exists as i said
i fix the code like this:

void displayinformation(){
  if (selection.equals("1")) {
    Information("John", 30);
  }
  if (selection.equals("2")) {
    Information("Melanie", 40,);
  } 
}

String information (String name, int age) {
  textSize(60);
  fill(0); 
  text("Name:"+name, 800,500);
  fill(0);
  text("Age:"+age, 850, 600);
  return "Name: " + name + "\nAge: " + age;
}
}

i cant change the format of displayInformation() to string because i call this method into draw() to show me the information(nam, age ,…) in the Android screen.

so, why you do this?
and not
myMessage.add(information(“Anna”,77));

i know that this wrong but i want to explain you that i want to send with OscMessage whatever is inside the displayinformation, because everytime i change the selection there is another name… I dont want to send one specific name, i want everytime i choose selection 1 to send the name John, everytime i choose the selection 2 to send the name Melanie(etc…)

so buffer it:

String thisOne = "";


void displayinformation(){
  if (selection.equals("1")) {
    thisOne = information("John", 30);
  }
  if (selection.equals("2")) {
    thisOne = information("Melanie", 40);
  } 
}

//....
myMessage.add(thisOne);
1 Like

Finally worked fine…Thank you so much @kll …It was so simple and easy eventually…
Ι am so grateful!!! :wink::blush::grinning::grin:

One more question based on these:
after this procedure i want to take only the value of age and make an if statement inside draw() with the value of age but i don’t know how…
Because in the example above i declared as

String thisOne = “”;
both name and age and if i write into draw() for example if info<40 (i mean if age<40) there is an error about : The operator <= is undefined for the argument type(s) String, int

Any ideas???
@kll @neilcsmith

in that case it makes no sense to remember it as a string, like i suggested last time.

String thisOne = "";
String thisName = "";
int thisAge=0;

void displayinformation(){
  if (selection.equals("1")) {
    //thisOne = information("John", 30);
   thisName="John";
   thisAge=30;
  }
  if (selection.equals("2")) {
   // thisOne = information("Melanie", 40);
   thisName="Melanie";
   thisAge=40;

  } 
}

//....
thisOne = information(thisName,thisAge);
myMessage.add(thisOne);


//... draw
if ( thisAge > 40 ) { .. }
1 Like

You are perfect…Thank you so so much…You have helped me unconditionally…:grinning::blush::wink::heart_eyes: