Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Get grid length, width, height

Discussion in 'Programming (In-game)' started by Concave, Jan 28, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Concave Apprentice Engineer

    Messages:
    104
    Is there a scripting method to get the volume of space a grid is occupying?
     
  2. Inflex Developer Staff

    Messages:
    397
    Of course it is.
    Code:
    void Main()
    {
    	var grid = this.Me.CubeGrid;
    
    	var min = grid.Min;
    	var max = grid.Max;
    
    	var size = max - min + Vector3I.One;
    	this.Echo($"Grid size: {size}");
    	this.Echo($"Grid volume: {size.Volume()}");
    
    	var sizeInMeters = size * grid.GridSize;
    	this.Echo($"Size: {sizeInMeters} m^3");
    	this.Echo($"Volume: {sizeInMeters.Volume()} m^3");
    }
    
     
    Last edited: Jan 28, 2017
    • Informative Informative x 1
  3. Concave Apprentice Engineer

    Messages:
    104
    Thank you!:carlton:
     
  4. plaYer2k Master Engineer

    Messages:
    3,160
    Just one addition to the code from inflex, you have to add Vector3I(1,1,1) because when the min = max, you would get a volume of 0, which isnt correct.
    Additionally the volume is given in blocks there and not m³. For the volume in m³ you got to multiply by GridSize³.
     
    • Agree Agree x 1
  5. Inflex Developer Staff

    Messages:
    397
    Yep, that is absolutely true. Thanks for that.
    I remember that I wanted to add both of these but I just forgot during writing. (Bad sclerotic space kitty :p)
     
  6. d4rky1989 Apprentice Engineer

    Messages:
    332
    If I remember correctly, the last time I tested it, it does not update if the grid shrinks in its size. So its like they are the maximum values the grid ever had (at least during the current session). Better you do a little test before relying on it
     
    Last edited: Jan 28, 2017
  7. Inflex Developer Staff

    Messages:
    397
    It is updated periodically every 30 seconds
     
    • Informative Informative x 1
  8. hellokeith Apprentice Engineer

    Messages:
    335
    Is based on all blocks or only terminal blocks?
     
  9. Inflex Developer Staff

    Messages:
    397
    It works for all blocks including armor and other non-terminal blocks.
     
Thread Status:
This last post in this thread was made more than 31 days old.