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.

Block Evaluation

Discussion in 'Programming Guides and Tools' started by mexmer, Apr 29, 2015.

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

    Messages:
    1,977
    seems there is lot confusion regarding block evaluation (values, accessors, fields etc.)
    most of this is covered in different ingame scripting guides, yet people struggle with this.

    this explanation might not be perfect and might seem not necessary for people who know "the thing" but yet, seems some beginners (regarding ingame pb programming) seems to need it.

    Block values (variables) can be evaluated in two different ways - directly or indirectly
    1) Direct evaluation
    a) In documentation (Tools\Documentation.chm - eg. SE ingame programming API refference) you might find "Properties" - this can be read, if they have "get" intergace, and changed, if they have "set" interface
    b) Each block that you can get from GridTerminalSystem.Blocks array (derived from base IMyTerminalBlock - please note i'm talking about ingame programming api, not modapi, not K# or C#) has also function GetProperties(List< ITerminalProperty>) which also can be evaluated and return respective value of their settings and can be changed using .SetValue<T>()
    2) Indirect evaluation
    a) each block has .DetailedInfo Property, which is string that can be parsed - there is topic covering this, as well at topic covering possible content of this property, therefore i will not delve into this in details
    b) Each block that you can get from GridTerminalSystem.Blocks array (derived from base IMyTerminalBlock - please note i'm talking about ingame programming api, not modapi, not K# or C#) has function function GetActions(List<ITerminalAction>)
    which also can be evaluated and return respective value of their settings and can be changed using Apply();

    1a)
    To evaluate Fields (see above), you just read IMyTerminalBlock.Field value with proper value cast
    for example
    Code:
    bool thrusterscontol = cockpitblock.ControlThrusters;
    
    1b)
    To evalue block properties you use following code
    Code:
    float volume = soundblock.GetProperty("VolumeSlider").AsFloat();
    
    note - when you get list of properties (using GetProperties) you can check for property value type by evaluating <ITerminalProperty>.TypeName
    single = float
    bool = bool
    color = Color
    string = string


    2a)
    see http://forums.keenswh.com/threads/guide-programmable-block-detailedinfo-output.7230123/

    2b)
    To evaluate action value you use following code for example (depends on which value you try to retrieve)
    for bools (eg. on/off actions, not sliders)
    Code:
    StringBuilder value;
    terminalblock.GetAction("OnOff").WriteValue(terminalblock, value);
    bool onoff = (value.ToString() == "On" ? true:false);
    
    for sliders
    Code:
    StringBuilder value;
    rotorblock.GetAction("IncreaseLowerLimit").WriteValue(terminalblock, value);
    int limit = Int32.ParseInt(value.ToString());
    
    be aware, that slider values return same value as you see in terminal GUI, eg. it's either integer, or some decimal float (not precise), also integer values are usualy rounded, therefore you can get 2 for sensor range, although it's set to 1.6 - general rule is, to use field or property value, and evalue action value only if necessary.
     
    Last edited: Jul 1, 2015
    • Like Like x 4
  2. mexmer Senior Engineer

    Messages:
    1,977
    adding list of properties and actions i got from blocks (list is not up to date, was compiled some time before, also not all properties have sample value)
    please not this list does not list "properties", that are directly exposed trough API (see documentation for respective block), only those that you can get by GetActions() or GetProperties() - you might find API property with different name altering same value as block property

    evaluation code, replace IMyMotorStator with desire block type you want to evaluate

    evaluation results
     
    Last edited: Aug 13, 2015
    • Like Like x 2
  3. Wicorel Senior Engineer

    Messages:
    1,262
    I have updated the code a little to check for the powerproducer and Batteryblock values. This will still work on any block.

    To change what block type you are looking at, just change the three locations of the type. In this code, the current type is IMyBatteryBlock.

    I have a world with the LCDs, program blocks and items I am interested in (basically, all of them) for saving the information.

     
    • Like Like x 1
  4. The Linking Tinker Trainee Engineer

    Messages:
    42
    O nice, This is exactly what I have been looking for! Especially the Tools\Doc. Now I can access a lot of the data without having to parse the detailed info. Thank you! :)
     
Thread Status:
This last post in this thread was made more than 31 days old.