# Need help; String\[\] and Methods

**URL:** <https://discourse.processing.org/t/need-help-string-and-methods/3564>\
**Category:** Beginners\
**Created:** [September 16, 2018, 12:06am UTC](https://discourse.processing.org/t/need-help-string-and-methods/3564 "2018-09-16T00:06:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SolDrakibane](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/soldrakibane/32/1810_2.png) [@SolDrakibane](https://discourse.processing.org/u/SolDrakibane)\
**Post date:** [September 16, 2018, 12:06am UTC](https://discourse.processing.org/t/need-help-string-and-methods/3564/1 "2018-09-16T00:06:06Z")

</div>

Hi, for my study i had a task which i have already completed (code below) i needed to draw four different names using a method. What i’ve made below works however how can i improve the method?

Code below doesn’t work its to illustrate what i want to achieve. Basically i want the new method to call an index number which stores the string and display that word so i can keep everything in one array.

```auto
String[] words = { "bla", "argh", "woohoo" };

void draw () {
 newMethod(wordNumber[1], 10, 10);
 println(newMethod);

}

// new method
void newMethod(String[] wordNumber, float x, float y) {
wordNumber = words;

}

```

To add to the stuff above: i’ve dabbled in Coding train concerning String array’s , split, join functions and using the for loop. However i’m still at banging at a wall for the thing i want to achieve.

This is my task.

```auto
PFont 
  myFont;
float 
  x, y, cX, cY, 
  hoeken, cHoeken, 
  linksX, linksY, rechtsX, rechtsY;

String 
  hallo, groet, n;

String[] 
  naam;

void setup() {
  size(600, 400);
  background(20);
  myFont = createFont("Georgia", 16);
  x = width;
  y = height;
  cX = x/2;
  cY = y/2;
  hoeken = sq(5);
  linksX = cX-cX+hoeken;
  linksY = cY-hoeken;
  rechtsX = cX+hoeken;
  rechtsY = cY+cY-hoeken;

  hallo = "Hallo ";
  groet = " hoe gaat het met je?";
  n = "Harry, Marianne, Ludo, Maaike";
  naam = split(n, ",");
}

void draw() {
  textFont (myFont);  
  naam0(linksX, linksY);
  naam1(rechtsX, linksY);
  naam2(linksX, rechtsY);
  naam3(rechtsX, rechtsY);
}

void naam0(float naamX, float naamY) {  
  text(hallo+naam[0]+groet, naamX, naamY);
}

void naam1(float naamX, float naamY) {  
  text(hallo+naam[1]+groet, naamX, naamY);
}

void naam2(float naamX, float naamY) {  
  text(hallo+naam[2]+groet, naamX, naamY);
}

void naam3(float naamX, float naamY) {  
  text(hallo+naam[3]+groet, naamX, naamY);
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [September 16, 2018, 12:38am UTC](https://discourse.processing.org/t/need-help-string-and-methods/3564/2 "2018-09-16T00:38:39Z")

</div>

🍍 Consider this example code:

```auto
String[] words = { "bla", "argh", "woohoo" };

void setup(){
  size(200,200);
  fill(255);
}

void draw () {
 background(0); 
 newMethod(1, 10, 10);
 newMethod(2, 40, 80);
}

void newMethod(int index, float x, float y) {
 text( words[index], x, y );
}

```

Notice that the index into the array is passed to the new function. There is no need to pass the array itself because it is in the global scope and can already be accessed inside the function.

---

<div class="post-metadata">

**Author:** ![SolDrakibane](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/soldrakibane/32/1810_2.png) [@SolDrakibane](https://discourse.processing.org/u/SolDrakibane)\
**Post date:** [September 16, 2018, 12:01pm UTC](https://discourse.processing.org/t/need-help-string-and-methods/3564/3 "2018-09-16T12:01:38Z")

</div>

Haha no way. I thought it would’ve been very complex. Thanks for the information i really appreciate it!
