# Class constructors

Redscript does not have natively support constructors and to set the data of class fields you would have to either set them manually

```swift
public class CustomClass{
    //all the variables 
    public let myInt: Int32;
    public let myString: String;
}
```

```swift
let myCustomClass = new CustomClass();
myCustomClass.myInt = 1;
myCustomClass.myString = "Hello";
```

&#x20;or if you want to do it with a single clean line, you can define a static helper method

```swift
public class CustomClass{
    //all the variables 
    public let myInt: Int32;
    public let myString: String;
    
    public static func Create(inputInt: Int32, inputString: String) -> ref<CustomClass>{
        //you create the new instance of your class here instead of in your code
        //and set its variables
        let self = new CustomClass();
        self.myInt = inputInt;
        self.myString = inputString;
        return self;
    }
}
```

and how to use it

```swift
let myCustomClass = CustomClass.Create(1,"Hello");
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.redmodding.org/redscript/references-and-examples/common-patterns/class-constructors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
