C# onready equivilent?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 9BitStrider
using System;
using Godot;
using Dictionary = Godot.Collections.Dictionary;
using Array = Godot.Collections.Array;

public class global_vars : Node
	onready var viewport = GetViewport();
	onready Vector2 gameSize = new Vector2(
	public Vector2 gameRes = new Vector2(256, 240);
	//Scale type for the game window.
	//0: Integer Height - 10:9
	//1: Integer Height - 4:3
	public int scaleType = 1;
	public void _Ready()
		viewport.Connect("size_changed", this, "resize_viewport");
	public void ResizeViewport()
		var newSize = OS.GetScreenSize();
		var scaleFactor;
		if(newSize.x < gameSize.x)
			scaleFactor = newSize.x / gameSize.x;
			newSize = new Vector2(gameSize.x * scaleFactor, gameSize.y * scaleFactor);
		if(newSize.y < gameSize.y)
			scaleFactor = newSize.y / gameSize.y;
			newSize = new Vector2(gameSize.x * scaleFactor, gameSize.y * scaleFactor);
		viewport.SetSizeOverride(true, newSize);

Very new to using Mono and C# so bear with me. I’m trying to port my current screen rescaling script to C# but I’m not having any luck. I can get the rest of the code to work, but I can’t get the right syntax for the onready function. Here’s the original code:

extends Node

onready var viewport = get_viewport()
onready var game_size = Vector2(

var game_res = Vector2(256, 240)

#Scale type for the game window.
#0: Integer Height - 10:9
#1: Integer Height - 4:3
var scale_type = 1

func _ready():
	viewport.connect("size_changed", self, "resize_viewport")

func resize_viewport():
	var new_size = OS.get_screen_size()
	var scale_factor

	if new_size.x < game_size.x:
		scale_factor = new_size.x / game_size.x
		new_size = Vector2(game_size.x * scale_factor, game_size.y * scale_factor)
	if new_size.y < game_size.y:
		scale_factor = new_size.y / game_size.y
		new_size = Vector2(game_size.x * scale_factor, game_size.y * scale_factor)
	viewport.set_size_override(true, new_size)

The error I get is as follows in Visual Studio Code. Yes, I have the 3 needed extensions installed.:

The type or namespace name 'onready' could not be found (are you missing a using directive or an assembly reference?)

9BitStrider | 2021-06-30 21:40

:bust_in_silhouette: Reply From: Yaann

As of now there’s no such things as a onready equivalent for C#, but there’s a pull request on the project’s repo discussing about it: Add OnReady annotation to C# · Issue #2425 · godotengine/godot-proposals · GitHub
However, you can do the same thing by initializing the onready variables and set them in the _Ready() function:

Viewport viewport;
Vector 2 gameSize;
public void override _Ready()
 viewport = GetViewport();
 gameSize = new Vector2 (ProjectSettings.GetSetting("display/window/size/width"),ProjectSettings.GetSetting("display/window/size/height"));
//Rest of _Ready()