Scripting in SFD assumes you have a fair knowledge of C#. You should be able to declare variables, write your own functions and classes, you should know about inheritance and derived classes and know how to cast objects.
In this script I will show how to create a button at the start of the round and when pressed will display a popup message displaying the player's name and current time.
The script:
You can try this script in an empty map. Just copy-paste it into the script window and test run the map.
// OnStartup is run when the script starts running.
public void OnStartup()
{
// Create ground
CreateGround();
// Create button pole
Game.CreateObject("ButtonPole00", new Vector2(8f*(-2.5f), 8f*(-0.5f)), 0f);
// Create the actual button - Button00 implements IObjectButtonTrigger and IObjectTrigger.
IObjectButtonTrigger customButton = (IObjectButtonTrigger)Game.CreateObject("Button00", new Vector2(8f*(-2.5f), 8f*(0.5f)), 0f);
// Hook up method to run when the button is pressed
customButton.SetScriptMethod("ButtonPressed"); // ! ScriptMethod must be a public void method with param TriggerArgs !
}
// Will be run when the button is pressed
public void ButtonPressed(TriggerArgs args)
{
if (args.Sender is IPlayer)
{
string playerName = ((IPlayer)args.Sender).Name;
Game.ShowPopupMessage(string.Format("Button pressed by {0} at {1}", playerName, DateTime.Now.ToString()));
}
}
// Create some ground under the 0,0 coordinate of the world
private void CreateGround()
{
IObject ground = Game.CreateObject("Concrete07B", new Vector2(8f*(-4.5f), 8f*(-1.5f)), 0f);
Point sizeFactor = new Point(10, 1);
ground.SetSizeFactor(sizeFactor);
}