I'm working on an assignment for school in which we make a small game using monogame, with the added challenge of working in F#. The game logic is fully immutable F#, and the entrypoint is in C# by use of the Game class in monogame. I have however come across a weird problem concerning Record types in F#. In the logic (F#) I have something along the lines of:
...
module Vectors =
type Vector = {
x : double
y : double
}
let Zero : Vector = {x=0.0; y=0.0}
...
And in C# I have some code accessing Zero:
...
player.vector = Vectors.Zero;
...
Weirdly enough, when I try to now use player.vector, it comes up as null. When debugging Vector.Zero is also null. I've looked around for a few solutions, and it may be some trivial mistake, but I can't seem to find it.
When you build an F# project as an exe, but use it as a library, occasionally some initialisation code doesn't get called.
This can be fixed by changing the project to build as a library.
Solved - F# project was building as a console application. Changing it to be a class library fixed the issue.
Thanks @JohnPalmer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With