Roundcrisis

About Contact me Presentations 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”

EndInCore

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>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <StartAction>Program</StartAction>
    <StartProgram>Pathto\where\editor\is\DualityEditor.exe</StartProgram>
    <StartWorkingDirectory>Pathto\where\editor\is</StartWorkingDirectory>
  </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <StartAction>Program</StartAction>
    <StartProgram>Path\to\DualityEditor.exe</StartProgram>
    <StartWorkingDirectory>Path\to\where\the\game\is</StartWorkingDirectory>
  </PropertyGroup>

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

open Duality
open System

[<Serializable>]
type ScoreComponentF() = 
    inherit Component()
    let mutable score =0

    member this.Score = score
    
    member this.IncreaseScore amount =
        score <- score + amount  

Categories:   programming   development   Duality

Want to discuss this post? the best place right now for me is mastodon, please message me @roundcrisis@types.pl with your comment or question.