• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker How to bring c # code into the game

nikmirkin

Member
I am a web game developer and the problem is that my game needs c # code, but I don't know how to transfer it to game maker 2.
.If someone knows how to do this, I will be very grateful.
 

Binsk

Member
GameMaker does not natively support C#. It only supports its in-house language, GML.

You can write extensions for GameMaker that plug in and use code from other languages and while I'm sure you could do something like C# w/ a desktop platform I think HTML5 is limited to javascript. Don't quote me on that, though.
 

chamaeleon

Member
Using UnmanagedExports, DllExport, or DNNE, it might conceivably be possible to do this, however, the easiest solution to use, UnmanagedExports, has not been touched in years, DllExport (somewhat based on UnmanagedExports, possibly) seems complex and does some kind of project file changes behind the scenes using a GUI tool, and DNNE is in its infancy still.

A few years ago I made a test (not related to GMS at the time) using UnmanagedExports and, I think .NET framework 4.5.2
C#:
using System.Runtime.InteropServices;

namespace Adder
{
    public class Class1
    {
        [DllExport("add", CallingConvention = CallingConvention.Cdecl)]
        static public double add(double a, double b)
        {
            return a + b;
        }
    }
}
This exposed a function, add, which could be found by that name and called. I believe this would work.

Making a new copy of this project and changing int to double, allowed the definition of a GMSAdder extension, containing the DLL generated (using the same architecture as the GMS project, in my case x64), and mapping the DLL add function to GMSAdder_add.
GML:
show_debug_message("Adding 1 and 2 = " + string(GMSAdder_add(1, 2)));
Code:
Adding 1 and 2 = 3
The main pain point will most assuredly be with handling strings, and performing memory allocations and deallocations safely and correctly. I have no direct insight into the best way to achieve this, but presumably it will involve convoluted Marshal-related code.
 
I will probably state the obvious, but why don't you use a game engine that natively uses C#?
Like, say, the most used game engine on the planet?
Not my point to deter you from using GMS or giving props to Yoyo's competition at all, but you got to ask yourself if you're using the right tool for the job, given your skills...
 
Top