# Value as a string from a void function

**URL:** <https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243>\
**Category:** Libraries\
**Created:** [October 8, 2018, 9:34am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243 "2018-10-08T09:34:01Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 8, 2018, 9:34am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/1 "2018-10-08T09:34:01Z")

</div>

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.

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 8, 2018, 9:40am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/2 "2018-10-08T09:40:57Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [October 8, 2018, 11:06am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/3 "2018-10-08T11:06:43Z")

</div>

> [@netphysicist](#):
>
> void Information function as a string.

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

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 8, 2018, 11:21am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/4 "2018-10-08T11:21:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 9, 2018, 7:36am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/5 "2018-10-09T07:36:37Z")

</div>

> [@neilcsmith](#):
>
> And method (function) names should start lower-case by convention.

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

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 9, 2018, 8:22am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/6 "2018-10-09T08:22:16Z")

</div>

[https://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html](https://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html)

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 9, 2018, 9:28am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/7 "2018-10-09T09:28:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 9, 2018, 10:48am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/8 "2018-10-09T10:48:19Z")

</div>

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 :

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

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 9, 2018, 11:46am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/9 "2018-10-09T11:46:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 9, 2018, 11:53am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/10 "2018-10-09T11:53:00Z")

</div>

> [@netphysicist](#):
>
> 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); }

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

```auto
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;
}
}

```

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 9, 2018, 11:54am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/11 "2018-10-09T11:54:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 9, 2018, 11:58am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/12 "2018-10-09T11:58:53Z")

</div>

> [@netphysicist](#):
>
> myMessage.add(displayinformation);

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

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 9, 2018, 12:01pm UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/13 "2018-10-09T12:01:01Z")

</div>

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…)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 9, 2018, 12:06pm UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/14 "2018-10-09T12:06:18Z")

</div>

so buffer it:

```auto
String thisOne = "";

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

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

```

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 10, 2018, 10:40am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/15 "2018-10-10T10:40:26Z")

</div>

Finally worked fine…Thank you so much @kll …It was so simple and easy eventually…  
Ι am so grateful!!! 😉😊😀😁

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 23, 2018, 10:59am UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/16 "2018-10-23T10:59:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 23, 2018, 4:44pm UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/17 "2018-10-23T16:44:51Z")

</div>

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

```auto
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 ) { .. }

```

---

<div class="post-metadata">

**Author:** ![netphysicist](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@netphysicist](https://discourse.processing.org/u/netphysicist)\
**Post date:** [October 23, 2018, 8:50pm UTC](https://discourse.processing.org/t/value-as-a-string-from-a-void-function/4243/18 "2018-10-23T20:50:36Z")

</div>

You are perfect…Thank you so so much…You have helped me unconditionally…😀😊😉😍
