Page 1 of 1

Developing a script for SFD in Visual Studio

Posted: Tue Feb 14, 2017 8:27 pm
by Gurt
If you want a full IDE with intellisense for larger scripts I suggest you do the following:
1: Download and install Microsoft Visual Studio Community.
2: Create a new C# console project.
3: Add a new reference and browse to the SFD.GameScriptInterface.dll file and select it in the SFD installation folder.
4: Create and add the following class to your project:

Code: Select all

// All available system namespaces in the ScriptAPI (as of Alpha 1.0.0).
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using SFDGameScriptInterface;

namespace ConsoleApplication1
{

    class GameScript : GameScriptInterface
    {
        /// <summary>
        /// Placeholder constructor that's not to be included in the ScriptWindow!
        /// </summary>
        public GameScript() : base(null) { }

        /* SCRIPT STARTS HERE - COPY BELOW INTO THE SCRIPT WINDOW */

        // Run code before triggers marked with "Activate on startup" but after players spawn from SpawnMarkers.
        public void OnStartup()
        {
            HelloWorld();
        }

        // Run code after triggers marked with "Activate on startup".
        public void AfterStartup()
        {
        }
        
        // Run code on map restart (or script disabled).
        public void OnShutdown()
        {
        }

        void HelloWorld()
        {
            Game.ShowPopupMessage("Hello World!");
        }

        /* SCRIPT ENDS HERE - COPY ABOVE INTO THE SCRIPT WINDOW */
    }
}
5: Start coding with full intellisense and live error checking inside the comments. Copy your code between the "SCRIPT STARTS HERE" and "SCRIPT ENDS HERE" comments into the ScriptWindow and try running the code in SFD.
 ! Message from: Gurt
For a tutorial how to set this up and with some easy copy-paste support see viewtopic.php?f=15&t=1662 by ShutDownMan.
This was first a reply in viewtopic.php?f=12&t=816 but I now lift it as it's own topic.

See how to debug scripts in SFD.

Re: Developing a script for SFD in Visual Studio

Posted: Wed Feb 15, 2017 12:08 am
by jamisco
Hey Mr Gurt, is there a way to directly run your script from visual studio? meaning i can compile my script in visual studio then directly run the game in map editor instead of copying and pasting ... if so can you please post another topic on how to do it

Re: Developing a script for SFD in Visual Studio

Posted: Thu Feb 16, 2017 5:54 pm
by Gurt
jamisco wrote:Hey Mr Gurt, is there a way to directly run your script from visual studio? meaning i can compile my script in visual studio then directly run the game in map editor instead of copying and pasting ... if so can you please post another topic on how to do it
Nope - not possible. You need to copy the content into the script window in the map editor.

Re: Developing a script for SFD in Visual Studio

Posted: Sat Feb 18, 2017 4:58 pm
by ShutDownMan
Gurt wrote:

Code: Select all

// All available system namespaces in the ScriptAPI (as of Alpha 1.0.0).
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using SFDGameScriptInterface;

namespace ConsoleApplication1
{

    class MyScript : GameScriptInterface
    {
        /// <summary>
        /// Placeholder constructor that's not to be included in the ScriptWindow!
        /// </summary>
        public MyScript() : base(null)
        {
        }

        /* SCRIPT STARTS HERE - COPY BELOW INTO THE SCRIPT WINDOW */


        /* SCRIPT ENDS HERE - COPY ABOVE INTO THE SCRIPT WINDOW */
    }
}
i Wonder why not use this:

Code: Select all

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using SFDGameScriptInterface;


namespace SFDScript
{

	public partial class GameScript : GameScriptInterface
	{
		/// <summary>
		/// Placeholder constructor that's not to be included in the ScriptWindow!
		/// </summary>
		public GameScript() : base(null) { }

		/* SCRIPT STARTS HERE - COPY BELOW INTO THE SCRIPT WINDOW */

		/* SCRIPT ENDS HERE - COPY ABOVE INTO THE SCRIPT WINDOW */


	}
}
As it corresponds to what the parent classes on what the script will be run on are...

OBS: If you "print" any method in the script it will show it's parent classes, so no peeking into game code for that info.

Re: Developing a script for SFD in Visual Studio

Posted: Sat Feb 18, 2017 8:25 pm
by Gurt
Yeah, you could call the class whatever but GameScript might fit better when demoing it I guess.

Re: Developing a script for SFD in Visual Studio

Posted: Tue Feb 28, 2017 6:48 am
by jamisco
Yo, been wondering, so like i downloaded Microsoft xna framework for "texture purposes" ;) ... found it in some tutorial anyways, in the file folder i realized there were a bunch dlls that looked similar to that of SFDGameScriptInterface and since the game was made using the framework i figured i could reference it in visual studio for "texture purposes" ;) just as the way u were able to reference SFDGameScriptInterface, i haven't started to fully utilize it because I'm not really sure how ... yet ... but....I'm wondering is there like a limit to what one can reference. So say i were to add a reference like so ....

Code: Select all

 using Microsoft.Xna.Framework; 
and Say i were to use the methods, objects and all that other good stuff provided by this extra reference in which i do not know what they are ...yet... would they work in the in game script editor and is it a safe practice in the sense that, by using this references (from the xna framework) i can write code that the script editor can identify or code that wont give me errors like, i don't know this object or method is etc.

Re: Developing a script for SFD in Visual Studio

Posted: Tue Feb 28, 2017 7:09 am
by ShutDownMan
jamisco wrote:... would they work in the in game script editor...
No.

Re: Developing a script for SFD in Visual Studio

Posted: Sat Jun 24, 2017 2:39 am
by jamisco
which one is preferable .... .NET core, standard or framework

Re: Developing a script for SFD in Visual Studio

Posted: Tue Nov 07, 2017 12:40 am
by Islem mahmoud
Is the the script that we use in the game is C#
Mr.gurt

Re: Developing a script for SFD in Visual Studio

Posted: Tue Nov 07, 2017 3:55 pm
by JakSparro98
Islem mahmoud wrote:
Tue Nov 07, 2017 12:40 am
Is the the script that we use in the game is C#
Mr.gurt
Yes, with some limitations due for few namespaces available.
There is also a dedicated interface that is basically the script API in itself, you can use it to handle game objects, perform player commands, etc...

Re: Developing a script for SFD in Visual Studio

Posted: Tue Nov 07, 2017 4:13 pm
by Islem mahmoud
JakSparro98 wrote:
Tue Nov 07, 2017 3:55 pm
Islem mahmoud wrote:
Tue Nov 07, 2017 12:40 am
Is the the script that we use in the game is C#
Mr.gurt
Yes, with some limitations due for few namespaces available.
There is also a dedicated interface that is basically the script API in itself, you can use it to handle game objects, perform player commands, etc...
Tnx dude 😘