[Guide] Setting up Visual Studio for Programmable Block Scripting

Discussion in 'Programming' started by CyberVic, Jan 2, 2015.

  1. CyberVic

    CyberVic Well-Known Member VIP

    First watch this video. The important parts to watch are till 3:35.


    In addition to the using statements they include in this video, you also need to include this:
    Code:
    using Sandbox.ModAPI.Ingame;
    Add this as a local variable of your script class
    Code:
    IMyGridTerminalSystem GridTerminalSystem;
    From there intellisence is magic.

    A sample c# class should look like below.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Sandbox.Common;
    using Sandbox.Common.Components;
    using Sandbox.Common.ObjectBuilders;
    using Sandbox.Definitions;
    using Sandbox.Engine;
    using Sandbox.ModAPI.Ingame;
    using Sandbox.Game;
    
    namespace Scripts
    {
        class StatusReport
        {
            IMyGridTerminalSystem GridTerminalSystem;
            //http://steamcommunity.com/sharedfiles/filedetails/?id=360966557
    
            void Main()
            {
                var blocks = new List<IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(blocks);
                if (blocks.Count > 0)
                    blocks[0].SetCustomName("Hello, Galaxy!");
            }
        }
    }
    
    When copying and pasting from Visual Studio to in game
    • Do not copy any of the using statements
    • Do not copy the namespace
    • Do not copy the class
    • Do not copy the "IMyGridTerminalSystem GridTerminalSystem;" line
    • Basically just copy any local variables, the main method, and any other sub-methods you make
    • Makes sure to not include any closing curly braces for the class / namespace

    Example:
    Code:
            void Main()
            {
                var blocks = new List<IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(blocks);
                if (blocks.Count > 0)
                    blocks[0].SetCustomName("Hello, Galaxy!");
            }
    
     
    Slebert likes this.