user11154649
user11154649

Reputation:

I want to make something that i do not know what to call

I'm not sure what to say, i am new to coding and and i want to do something. I think the easiest way to tell you is to "show" you what i want to do.

// this is how I want something to look like

void method() {
  println(something.somestring1);
  println(something.somestring2);
  println(something.someint);
}

// this is where I want to make something that allows me to do what I just showed you.

void something() {
  String somestring1 = "hello";
  String somestring2 = "bye";
  int someint = 10;
}

// this should then print:

// hello
// bye
// 10

I dont know if what i want to do is even possible or if it has a name. If this is impossible and there is something similar that is working, then please tell me. I can live without this but it would make some things much easier.

I am coding in processing 3

Upvotes: 1

Views: 65

Answers (1)

Rabbid76
Rabbid76

Reputation: 210948

What you are searching for is called class.

Create a class Somthing with the attributes somestring1, somestring2 and someint:

class Something
{
    String somestring1 = "hello";
    String somestring2 = "bye";
    int someint = 10;

    Something() {
    }
}

Create an instance of the class:

void setup() {
  Something something = new Something();

  println(something.somestring1);
  println(something.somestring2);
  println(something.someint);
}

Upvotes: 3

Related Questions