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.

Standard Protocol for Manipulating block.CustomData

Discussion in 'Programming (In-game)' started by not-a-cylon, Jan 5, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. not-a-cylon Trainee Engineer

    Messages:
    39
    It seems that scripts are starting to use the block.CustomData field to store vital program info. Myself, I've been using it extensively for the scrolling display component of my Quick Cargo Display script. Due to only the CustomData field being added only recently, conflicts are still relatively rare. However, when more and more scripts use the CustomData field, conflicts are bound to happen and will cause unexpected behaviours and/or crash scripts.

    Here I propose a (hopefully) standard way of accessing and manipulating CustomData. If every script uses this method, conflicts should be zero provided users create distinct enough tags.

    "Start" and "End" won't cut it, but #$MyScrollingScriptStart$# and #$MyScrollingScriptEnd$# are very unique.
    Below is a demonstration and at the very bottom is the class to add in your scripts.

    the goal is to find your data entry "this is my data" and manipulate only that entry
    if you look, every single data entry has a distinct start tag and end tag.


    Here is a script demonstrating the method. Try out in a programming block!


    Here is just the class to add to your own scripts


    using this method, you can also create your own subdata tags to search for within your data.
    your subtata within your greater data, which is stored among other program data, all in the same block and no conflicts!

    Please share your thoughts and discuss!
     
  2. Blargmode Trainee Engineer

    Messages:
    21
    Looks interesting. And the tags are completely custom? So I could use eg. "totally a start tag" as a start tag and "totally the end tag" as the end tag, while someone else uses "<stripedhorses>" and "</stripedhorses>"?
     
  3. not-a-cylon Trainee Engineer

    Messages:
    39
    yeah that is exactly the idea! I really do suggest adding non alphanumeric characters as well as that will most definitely prevent weird conflicts. you can even have something like this:

    Code:
    %%totally a start tag%%  *start1* [data entry1] *end1* *start2* [data entry2] *end2* *start3* [data entry3] *end3* %%totally the end tag%%
    next to someone else's tags, "<stripedhorses>" and "</stripedhorses>" to pull out your own [data entry1], [data entry2], and [data entry3].
     
  4. Wicorel Senior Engineer

    Messages:
    1,242
  5. not-a-cylon Trainee Engineer

    Messages:
    39
    I'm still new to programming, so the concepts behind an INI file are not yet intuitive to me. Is it important that the data entries are compatible with each other for the method I've created? If so, why? Or were you just simply stating that the non-compatibility is neither good nor bad?
     
  6. Malware Master Engineer

    Messages:
    9,601
    The format I use looks like this:

    Code:
    [category]
    key: value
    key2: another value
    thirdKey: |
        This is a key type that supports
        long and multiline values.
    
        The indent signifies that a line
        belongs to that key.
    
    [category2]
    MoreKeys: etc
    
    The format is a cross between ini and highly simplified yaml. I can search for blocks having a certain category.
     
  7. not-a-cylon Trainee Engineer

    Messages:
    39
    If I'm understanding you correctly:
    [category] is one program's CustomData and [category2] is another's?
    each key is a value that the program has set and saved within it's category?
     
  8. Malware Master Engineer

    Messages:
    9,601
    No, this is an example for a single CustomData. Each block can have several categories, for different scripts and/or functions. For instance, I have a category for airlock control, telling the script which blocks are which part of which airlock. Another category describes how this block should be displayed on a status screen etc.

    I don't use CustomData for storage if I can avoid it. This is a synchronized value so it will cause network traffic in multiplayer. I use CustomData primarily for behavior configuration only. I use the programmable block Storage for state, this is much more effective.
     
  9. not-a-cylon Trainee Engineer

    Messages:
    39
    Ah I totally did not know about the programmable block Storage field. I should have read the manual better :p That actually solves a lot of the issues that my method was originally addressing.

    in the other thread, you posted this:
    Code:
    timer: PBS.Airlocks.Timer
    airlocks:
        -  name: PBS.Airlock1
            innerDoors: PBS.Airlock1.Door.Inner
            outerDoors: PBS.Airlock1.Door.Outer
            buttonPanels: [PBS.Airlock1.ButtonPanel,PBS.Airlock1.ButtonPanel,PBS.Airlock1.ButtonPanel]
            airvents: PBS.Airlock1.Airvent
            displays: PBS.Airlock1.Display
    can you give me a quick rundown of how some of the information is accessed and how it is used?
     
  10. Malware Master Engineer

    Messages:
    9,601
    @not-a-cylon what you're seeing there is a complete yaml example. I've since moved to a simpler implementation that doesn't support the list and nested object system, it simply took too much code and as long as the character limits are what they are, this will have to wait. While I would love using such a system given it's readability and ease of use, it's not worth the cost atm.

    I'm at work so I can't give you a rundown right now.

    I will try to remember to get you the code when I get home. But my memory is rotten... :p
     
    Last edited: Jan 5, 2017
  11. not-a-cylon Trainee Engineer

    Messages:
    39
    ahaha work- that thing we all have to do. no worries! post it if you get the chance :D
     
  12. Acolyte Apprentice Engineer

    Messages:
    109
    @Malware.

    Apologies for the necro (I used search like I was supposed to :D ) but why do you use PB for state storage and not lcd text fields ?
     
  13. Malware Master Engineer

    Messages:
    9,601
    1. Performance. The PB storage does not synchronize (because it doesn't have to). Text panels and CustomData does.
    2. ^
    3. ^^
    4. Fewer blocks required. I don't need anything but a timer and a PB.
     
    • Agree Agree x 1
  14. Acolyte Apprentice Engineer

    Messages:
    109
    My train of thought was that a lcd is automatically persistent, whereas a PB must be made so with the Save() routine, which might not work if the game crashes, as it sometimes does.

    Are PBs good enough for critical system data ? (I'm thinking of a flight system that depends on correctly storing waypoint data on planets to avoid crashing the ship).
     
  15. Phoera Senior Engineer

    Messages:
    1,713
    you know, that you can save data in Storage var not only at Save callback?
     
  16. Acolyte Apprentice Engineer

    Messages:
    109
    Err, no, and I just googled "Storage var" and still don't know, I just get the pages for C# var.

    Do you mean the custom data part of the PB ?
     
  17. Phoera Senior Engineer

    Messages:
    1,713
    Code:
        /// <summary>
    
        /// Gets or sets the storage string for this grid program.
        /// </summary>
        string Storage { get; set; }
     
    • Like Like x 1
  18. Acolyte Apprentice Engineer

    Messages:
    109
    Ooo looks useful, is this something provided by SE ? or C# ? (SE I would guess)
    And what does it mean by "grid program" ? Does it mean there is only one such variable per grid ?

    Edit - Ok I found IMyGridProgram
     
    Last edited: Apr 21, 2017
  19. Phoera Senior Engineer

    Messages:
    1,713
    IMyGridProgram => Program this is your PB class.
    Storage provided by SE ofc.
     
  20. Ronin1973 Master Engineer

    Messages:
    4,800
    If every piece of custom data is on a separate return (line) and contains a key in it like "[MyData]" you can parse each line of the custom data and look for the key in it. If that key exists then grab that specific line and remove the key or read/change whatever information about the block you need. As long as everyone uses a different key, all data can exist without a problem. Though this will slow down the searching of blocks as it now has to read the contents of the customname data, parse it, and analyze each line in the string.
     
Thread Status:
This last post in this thread was made more than 31 days old.