Quantcast
Channel: Programming (In-game)
Viewing all 645 articles
Browse latest View live

String CenterAlign

$
0
0
I wonder how this code affects perfomance on servers used to build up to 50 string lines per tick every 10-th tick
Code:
#region String Extensions
		static string CenterAlign(string source, int space)//centers string space wide
		{
			if (source == "" || space <= 0) return "";//input empty or no space? return empty		 
			else
			{
				int length = source.Length; //source length
				if (space == length) return source;//return source if its length == space
				else if (space > length) return...
String CenterAlign

Getting GasLevel from IMyInventoryItem.

$
0
0
I would like to get GasLevel value from hydrogen bottle. I already found my bottle in a container, so I have a reference to IMyInventoryItem. IMyInventoryItem have a Content property which in this case is an instance of MyObjectBuilder_GasContainerObject. MyObjectBuilder_GasContainerObject have a GasLevel variable that I would like to read, but the type MyObjectBuilder_GasContainerObject isn't allowed in ingame scripts.
Which extensions or interfaces can I use instead?

IMyProjector and Programming? Is it possible?

$
0
0
I have a small problem trying to alter the offset and rotation of a projection from a projector. Here's my code. Any help to get it working would be greatly apprecieted.

Code:
public void Main(string argument, UpdateType updateSource)

{

	var defaultLargeVertex = new List<int>{2,0,-1,0,0,0};

	// Horizontal Offset, Vertical Offset, Forward Offset,  Pitch, Yaw, Roll

	var defaultSmallVertex = new List<int>{0, -28, -3, 90, 0, 180};

	// Horizontal Offset, Vertical Offset, Forward Offset,...
IMyProjector and Programming? Is it possible?

Gravity aligning thrusters

$
0
0
Hello, I wanted to try and create a script that uses thrusters on rotors to rotate them to match gravity for a modular miner I was going to try and build. I was wondering if anyone here had tried a project like this and how you went about it, since I was thinking about making it where you feed the gravity vector into the rotor and have it rotate the thruster to match the angle (or the inverse of it).

I attempted to look at the Gravity Aligned Camera script to see how he was rotating the...

Gravity aligning thrusters

[API Request] An Interface for block state for IMyTerminalBlock

$
0
0
I have also submitted this to the API Requests Thread and I am posting it separately here so that it can have it's own discussion.

I would like an Interface that is connected to IMyTerminalBlock that gives access to all the blocks non-modifiable block information (example: like rotor angle for rotors, or piston extension for pistons) without the need for downcasting from IMyTerminalBlock.

Currently we have "ITerminalProperty" and "ITerminalAction" that give us access to the properties and...

[API Request] An Interface for block state for IMyTerminalBlock

Save and load variable?

$
0
0
So I'm trying to automate mining on my ship, I have pistons that need to go after each other in order to not break the drills. So I created a simple program.

Code:
public void Main(){
   IMyPistonBase Piston_up_one = (IMyPistonBase) GridTerminalSystem.GetBlockWithName("Mining - Piston up 1");
   IMyPistonBase Piston_up_two = (IMyPistonBase) GridTerminalSystem.GetBlockWithName("Mining - Piston up 2");
   IMyPistonBase Piston_down_one = (IMyPistonBase)...
Save and load variable?

Block scripts requests thread

$
0
0
As programmable blocks came to SE, and not all players are programmers, I guess a thread with block requests is reasonable.

Basically, if you want a script on your block, post explanation here. Other programmers and I (Although I'm generally a busy person so maybe not often) will be more than happy to program it for you. Of course I still suggest you to learn programming, but you might not want to, and it's all fine. Other people like other things.
(Yes, I wanted to create website for that,...

Block scripts requests thread

Using Echo in separate class

$
0
0
Hello,

I have the Main method and I want to call another class. Inside the separate class (being a full script with it's own methods and class variables), I want to use Echo to display an output to the console.

I'm getting an error that 'Echo' isn't referenced / available in the separate class (called from main). I'm referencing the separate class as ??? xclass = new ???();

Is there a way to use Echo in another class and if so, how do I do it?

Thanks

UpperLimitDeg = UpperLimitRad

$
0
0
IMyMotorAdvancedStator

UpperLimitDeg behaves like UpperLimitRad.
UpperLimitRad behaves normally.

LowerLimitDeg behaves normally.
LowerLimitRad behaves normally.

Suspension Strength per Tonne

$
0
0
Does anyone have a more accurate formula to adjust suspension strength?

I've dabbled with the following formula:
0.0036x² - 0.1x + 6

[​IMG]

Be careful with it, because it becomes increasingly inaccurate over 17500 kg. Of course, it is also inaccurate at values lower than 17500 kg.

PHP:
// Only tested on small grids between 17500 and 50000 kg
float massTonnes vehicleMassTotal 1000;
suspension.Strength 0.0036f * (float)Math.Pow(massTonnes2) -...
Suspension Strength per Tonne

Accessing GridTerminalSystem from Sub-class without statics?

$
0
0
Sorry if this is a really obvious question but I couldn't find an answer elsewhere.

Since I started in-game scripting, I've always created a static reference to the master Program - something I almost certainly copied from someone else - at the top of the main script:

Code:
static Program me;

public Program()
{
	me = this;
}
I can then access GridTerminalSystem from anywhere via me.GridTerminalSystem.

Malware has frequently said that statics are bad, mmkay. As I'm just a hobbyist...

Accessing GridTerminalSystem from Sub-class without statics?

Autogenerated API index

$
0
0
This index contains all types and members available to ingame scripting - with exception to the .NET types, because including those would have made the listing far too big. There will be links to Microsoft's own documentation for those types where appropriate.

https://github.com/malware-dev/MDK-SE/wiki/Api-Index

Interface extension

$
0
0
Instead of doing this.

PHP:
class InventoryTable
{
    public 
IMyInventory Inventory getset; }
    public 
VRage.MyFixedPoint PreviousMass getset; }
}

I was thinking of doing this.

PHP:
interface IMyInventoryManager IMyInventory
{

    
VRage.MyFixedPoint PreviousMass getset; }
    
}

But, I'm getting an assembly error when I try to update PreviousMass.

PHP:
var inventory cargoContainer.GetInventory() as IMyInventoryManager;
inventory.PreviousMass = new...
Interface extension

PB Scripting Guide: How To Use Self-Updating

$
0
0
Greetings engineers! As you all have (hopefully) read in last week's update post, the PB now has some fancy new self-updating features which means you no longer need timer blocks!

This self-update system is relatively straightforward, but does require a bit of explanation, so let's get into it!


Update Frequency:
The self-update system is controlled through the Runtime.UpdateFrequency property. Those of you who are familiar with GameLogic components should recognize...

PB Scripting Guide: How To Use Self-Updating

New way to read inventory?

$
0
0
I got this error on test, in the EasyAPI code (which I had updated to handle currently live changes but that hasn't been pushed to github or the store).

There is no argument that corresponds to the required formal parameter `items` of `IMyInventory.GetItems(List<IMyInventory>, Func<MyInventoryItem, bool>`)
Adjusting to use MyInventoryItem instead of IMyInventoryItem, error:

'MyInventoryItem' does not contain a definition for 'Content' and no extension method...​

New way to read inventory?

New to coding, need a little help :-)

$
0
0
Hi there!
So I've *just* yesterday started coding, so complete newbie here.
Read up on the basics for C# and started to try it out ingame with a few trial program blocks, started with just turning on lights / opening doors, combining it, writing the results on lcd's etc. to kinda get the hang/feel for it.

So I wanted to up the stakes, but I can't find why my current script isn't working... the compiler gives a solid "succes" but nothing happens :(
(also guessing there is an easier way to...

New to coding, need a little help :)

IMyMechanicalConnectionBlock throw exception only when loading session

$
0
0
Hi o/

I face a strange behavior with IMyMechanicalConnectionBlock object.

Here's a code who works on function main() script; but not on program() only when call 1st time after loading a game, if I recompile after first exception all become fine again.


Code:
	// Identify and Rename Subgrids
	List<IMyMechanicalConnectionBlock> _MechConn = new List<IMyMechanicalConnectionBlock>();
	GridTerminalSystem.GetBlocksOfType<IMyMechanicalConnectionBlock>(_MechConn, x => SatisfyGridPolicy(x) &&...
IMyMechanicalConnectionBlock throw exception only when loading session

Quick Introduction to Space Engineers Ingame Scripts

My first ingame script [help]

$
0
0
Error In line 72 which is:
"GridTerminalSystem.SearchBlocksOfName("[Mining stop]", Alerts);"

Error CS1503 Argument 2: cannot convert from 'System.Collections.Generic.List<SpaceEngineers.Game.ModAPI.Ingame.IMySoundBlock>' to 'System.Collections.Generic.List<Sandbox.ModAPI.Ingame.IMyTerminalBlock>' MinerCargocheck
--- Automerge ---
Hello guys,

I finally got some time to start learning C# and try to make my first ingame script. I am writting...

My first ingame script [help]

Getting a warning in script

$
0
0
Hi there, can someone tell me why am I getting a Warning after compiling this script? And does anyone know if it breaks something within the code?

Warning: 'IMyShipConnector.IsConnected' is obsolete: 'Use the Status property'

Code:
public void Save()
{
}

public void Main()
{
/*======================================| VARIABLES |=====================================*/

//THRUSTERS
    var thrusters = GridTerminalSystem.GetBlockGroupWithName("PF_W_S1 - Thrusters"); 
    List<IMyThrust>...
Getting a warning in script
Viewing all 645 articles
Browse latest View live