home about talks rss feed  rss

Writing Duality Components in FSharp

08 Sep 2014

Duality is a 2D game engine with an extensible editor (If you follow my blog you’ll see it mention it a few times), I added F# Scripting support a good while ago but I haven’t been posting too much about it, I probably should change that.

Scripting is not the only way to use F# on this engine, you can also create components with F# and it’s pretty simple.

When you run Duality on a folder that has no Data, it creates a solution for plugins by default in Source/Code with two projects: CorePlugin and EditorPlugin. Open the solution and add a F# project. Once it’s created open the project properties and change the assembly name so that it ends with “core”


open Duality

type BreakoutFSharpCorePlugin() = 
    inherit CorePlugin()

Lastly if you want to F5 to launch the editor you can add the following to the end of Editor.csproj.user file (replace DualityEditor.exe locations )

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">

####Example This is an example of a component

open Duality
open System

type ScoreComponentF() = 
    inherit Component()
    let mutable score =0

    member this.Score = score
    member this.IncreaseScore amount =
        score <- score + amount  
comments powered by Disqus