2spooky2play
2spooky2play
CC#
Created by 2spooky2play on 5/2/2024 in #help
Branching paths for a text based adventure game (language agnostic)
How would i create a system of branching paths for a text based adventure game? i dont want it to devolve into a ton of if-statements because i have done that before and it is a mess to keep track of and maintain
16 replies
CC#
Created by 2spooky2play on 4/22/2024 in #help
✅ Cannot see source code of the standard library
No description
6 replies
CC#
Created by 2spooky2play on 4/19/2024 in #help
✅ Allowing unsafe in a project
How do I allow the use of the unsafe keyword in my project? i am not using visual studio so there isnt an option for that. do i need to edit the csproj file?
7 replies
CC#
Created by 2spooky2play on 4/15/2024 in #help
✅ confused by this error
class Player(Vector2 position, Vector2 size) {
public Vector2 Position { get; } = position;
public Vector2 Velocity { get; private set; } = Vector2.Zero;
public Vector2 Size { get; } = size;

public Rectangle GetRect() {
return new(Position, Size);
}

public void Input() {
float dt = GetFrameTime();
Velocity.X = 0.0f;
}
}
class Player(Vector2 position, Vector2 size) {
public Vector2 Position { get; } = position;
public Vector2 Velocity { get; private set; } = Vector2.Zero;
public Vector2 Size { get; } = size;

public Rectangle GetRect() {
return new(Position, Size);
}

public void Input() {
float dt = GetFrameTime();
Velocity.X = 0.0f;
}
}
Cannot modify the return value of 'Player.Velocity' because it is not a variable in the Input method all i am doing is modifying the field of the struct, why is that a problem?
6 replies
CC#
Created by 2spooky2play on 4/15/2024 in #help
✅ Strange output of my code
var query = Enumerable.Range(1, 1000)
.Where(x => x % 2 == 0)
.Aggregate((x, y) => x * y);

Console.WriteLine(query);
var query = Enumerable.Range(1, 1000)
.Where(x => x % 2 == 0)
.Aggregate((x, y) => x * y);

Console.WriteLine(query);
why does this output 0? is it due to overflow, and if it is, why is an exception not thrown?
5 replies
CC#
Created by 2spooky2play on 4/6/2024 in #help
✅ `T` always value for `nameof`
int id = nameof(T).GetHashCode();
Console.WriteLine(nameof(T));
int id = nameof(T).GetHashCode();
Console.WriteLine(nameof(T));
how come nameof(T) always returns T instead of the type of the generic argument?
3 replies
CC#
Created by 2spooky2play on 4/5/2024 in #help
✅ Pass in arguments to a generic constructor
public T AddComponent<T>() where T: Component, new() {
Component component = new T(this);
return (T)AddComponent(component);
}
public T AddComponent<T>() where T: Component, new() {
Component component = new T(this);
return (T)AddComponent(component);
}
i want to be able to create new instances of T in the method, but i get the error 'T': cannot provide arguments when creating an instance of a variable type. how can i make this work? one precondition is that all child of Component will only have one argument in their constructor
13 replies
CC#
Created by 2spooky2play on 4/5/2024 in #help
✅ Get type of current instance in a static method
public static int GetTypeId() {
return typeof(TypeOfInstance).Name.GetHashCode();
}
public static int GetTypeId() {
return typeof(TypeOfInstance).Name.GetHashCode();
}
how can i get the current type of the current class? this class will be inherited by other classes, and i need to get the hash code of the name of the class
69 replies