Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Developing a script for SFD in Visual Studio

Share questions, scripts and tutorials related to the ScriptAPI in SFD.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1069
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 28

Developing a script for SFD in Visual Studio

Post by Gurt » Tue Feb 14, 2017 8:27 pm

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.
Last edited by Gurt on Mon Nov 13, 2017 6:46 pm, edited 1 time in total.
Reason: Added link to how to debug scripts
6 x
Gurt

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 97

Post by jamisco » Wed Feb 15, 2017 12:08 am

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
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1069
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 28

Post by Gurt » Thu Feb 16, 2017 5:54 pm

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.
1 x
Gurt

User avatar
ShutDownMan
Fighter
Fighter
Posts: 32
Joined: Sat Mar 19, 2016 7:17 pm
Title: Yeah, science!
SFD Alias: ShutDownMan, Devil Shut
Started SFD: 1.2.something
Location: Hu3, Brazil
Gender:
Age: 18
Contact:

Post by ShutDownMan » Sat Feb 18, 2017 4:58 pm

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.
0 x
~ShutDownMan

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1069
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 28

Post by Gurt » Sat Feb 18, 2017 8:25 pm

Yeah, you could call the class whatever but GameScript might fit better when demoing it I guess.
1 x
Gurt

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 97

Post by jamisco » Tue Feb 28, 2017 6:48 am

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.
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
ShutDownMan
Fighter
Fighter
Posts: 32
Joined: Sat Mar 19, 2016 7:17 pm
Title: Yeah, science!
SFD Alias: ShutDownMan, Devil Shut
Started SFD: 1.2.something
Location: Hu3, Brazil
Gender:
Age: 18
Contact:

Post by ShutDownMan » Tue Feb 28, 2017 7:09 am

jamisco wrote:... would they work in the in game script editor...
No.
3 x
~ShutDownMan

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 97

Post by jamisco » Sat Jun 24, 2017 2:39 am

which one is preferable .... .NET core, standard or framework
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
Islem mahmoud
Fighter
Fighter
Posts: 23
Joined: Mon Oct 31, 2016 9:06 am
Title: Producer of [RIOT] clan
SFD Account: El grim
SFD Alias: El grim
Started SFD: March 2012
Location: Algeria
Gender:
Age: 21
Contact:

Post by Islem mahmoud » Tue Nov 07, 2017 12:40 am

Is the the script that we use in the game is C#
Mr.gurt
0 x
Hell Man »»» El grim

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 327
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 19

Post by JakSparro98 » 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...
1 x

User avatar
Islem mahmoud
Fighter
Fighter
Posts: 23
Joined: Mon Oct 31, 2016 9:06 am
Title: Producer of [RIOT] clan
SFD Account: El grim
SFD Alias: El grim
Started SFD: March 2012
Location: Algeria
Gender:
Age: 21
Contact:

Post by Islem mahmoud » Tue Nov 07, 2017 4:13 pm

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 😘
0 x
Hell Man »»» El grim

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest