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.

Mod Approved! Programmable Block - 1.085

Discussion in 'Programming (In-game)' started by Textor, Jun 4, 2015.

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

    Messages:
    775
    As tradition, here we discuss improvements. Looks like some decent improvements:

    - introduced a base class for programmable block programs (by LordDevious)
    - added modapi laserantenna interface (by mexmer)
    - fixed single and multiline textboxes (by LordDevious)
    - terminalproperty bool value (by mexmer)

    Thanks to Devious and Mexmer for their contributions!
     
  2. g4borg Apprentice Engineer

    Messages:
    271
    I am quite curious, what this new base class already allows, someone has examples?

    Albeit the biggest change I am waiting for is the event system based on this.

    Still, all in all, great additions! Keep it up!
     
  3. Textor Junior Engineer

    Messages:
    775
    I'm sure when LordDevious gets here he'll explain all of it, since he designed the base class.

    I also started working on some code updates in the actual game source, so if things go well I'll also be making some contributions. We have another thread that we can use for discussion of PB improvements via source code contributions here: http://forums.keenswh.com/threads/programmable-block-improvement.7361275/
     
  4. ArgumentNullException Trainee Engineer

    Messages:
    32
    The base class in this case is a big convenience helper and will enable additional features in the future. The biggest short term win here (at lest for me ATM) will be that when working with an IDE or other advanced toolset I don't need nearly as much "helper code" (as seen here) to make a block script testable or use it in other tools. Also it helps new users as a well written base can do a lot of basic wire-up and expose what options are available to the user in a way that is difficult to ignore and easy to reference. LordDevious being closer to the code than most will likely have an exhaustive list of where the gains will be.

    All in all, this is a good move.


    EDIT: Interface

    This seems to include a number of common and popular code tools/patterns

    With the interface involved this makes testing even more straight forward than I hoped. Nice commit LordD.
     
    Last edited: Jun 5, 2015
    • Like Like x 1
  5. hellokeith Apprentice Engineer

    Messages:
    335
    Code:
    Syntax
    
    public abstract class MyGridProgram : IMyGridProgram
    
    The MyGridProgram type exposes the following members.
    
    Properties
    
    Public property Echo Prints out text onto the currently running programmable block's detail info area. 
    Public property ElapsedTime Gets the amount of in-game time elapsed from the previous run. 
    Public property GridTerminalSystem Provides access to the grid terminal system as viewed from this programmable block. 
    Public property Me Gets a reference to the currently running programmable block. 
    Public property Storage Allows you to store data between game sessions. 
    
    
    Explicit Interface Implementations
    
    Explicit interface implementationPrivate property IMyGridProgram.Echo Gets or sets the action which prints out text onto the currently running programmable block's detail info area. 
    Explicit interface implementationPrivate property IMyGridProgram.ElapsedTime Gets or sets the amount of time elapsed since the last time this grid program was run. 
    Explicit interface implementationPrivate property IMyGridProgram.GridTerminalSystem Gets or sets the GridTerminalSystem available for the grid programs. 
    Explicit interface implementationPrivate property IMyGridProgram.HasMainMethod Determines whether this grid program has a valid Main method. 
    Explicit interface implementationPrivate method IMyGridProgram.Main Invokes this grid program. 
    Explicit interface implementationPrivate property IMyGridProgram.Me Gets or sets the programmable block which is currently running this grid program. 
    Explicit interface implementationPrivate property IMyGridProgram.Storage Gets or sets the storage string for this grid program. 
    
    
    Examples
    
    public void Main()
    {
        // Print out the time elapsed since the currently running programmable block was run
        // the last time.
        Echo(Me.CustomName + " was last run " + ElapsedTime.TotalSeconds + " seconds ago.");
    }
     
  6. mexmer Senior Engineer

    Messages:
    1,977
    MyTerminalPropertyExtension is not only way to get value of checkbox, but also to set it ;o)
     
  7. Sibz Apprentice Engineer

    Messages:
    361
    Awesome
     
  8. Sibz Apprentice Engineer

    Messages:
    361
    Deleted my post RE ProductionEnabled as doesn't appear to have made it into release.

    But, using mexmers' awesome MyTerminalPropertyExtension GetValueBool, can easily get recharge value now:
    Code:
    void Main(string argument) 
    { 
        var b = GridTerminalSystem.GetBlockWithName("Battery 2"); 
        var rechargeVal = b.GetValueBool("Recharge"); 
        Echo ("Battery Recharging:"+rechargeVal); 
    }
    
     
  9. Malware Master Engineer

    Messages:
    9,625
    Seems to me you've gotten the idea of that base class quite clearly :)
     
  10. mexmer Senior Engineer

    Messages:
    1,977
    hmm, didn't notice.

    i still prefer having direct fields over propertyextension, but in most cases direct fields are exposed read/only due sync issues. while propertyextesion is exposed for read/write since it uses getter/setter from control it belongs to, and those are synced (or should be)

    also, while i have added this, malware is also responsible for this. we were discussing this before :101:
     
    Last edited: Jun 5, 2015
  11. Malware Master Engineer

    Messages:
    9,625
    This is what I wrote in the pull request:

    But @ArgumentNullException got the full intent right as it also was intended to make it easy to mock up and test scripts in VS.

    @g4borg The event system you're asking for is still very much in the discussion phase as there are several issues which needs to be resolved. Right now the thinking is that it would be better to expose more actions as events rather than having a specific event system, because you can wire them up to run your PB with an argument to distinguish each event, and it would make the events available for nonprogrammers.
     
    • Like Like x 1
  12. mhalpern Senior Engineer

    Messages:
    2,119
    What I am wondering is how they did the "enemy detected" part of the update video, if they cheesed it with a timer or used a sensor or something, because if they didn't cheese it, that would mean there's an event trigger based on antennas.
     
  13. Tony Hughes Junior Engineer

    Messages:
    715
    I wondered the same thing. Suspect it was a sensor.
     
  14. g4borg Apprentice Engineer

    Messages:
    271
    Hehe. My comment was more of ancient expectations, since I actually read between the lines, that Keen realized, they want to shift the programmable block to something more event based :)
    And I wasn't targeting "user events" or "detailed event subscription" anyway, just basicly "event based programming"; Coming from the perspective of scripting in uo servers, plugin systems or window manager apis, e.g. PyQt4, it is quite common that you only have a set of events you can override, but no real way to completely register a specific function for a specific event; or even if you have the ability in theory, basicly give the user a set of overridable functions which get called in the underlying event handlers if they are present; This allows coders with little experience or solving common tasks an easy start using the most common events, while more complex events requires more code but also more knowledge of the coder, what he is doing. Even that however needs a clear perspective in how the event system is going to be designed later, so the solution how to give users at least a basic set of events they can react to, can be done in a way, which integrates in the event system created later on, and also does not create too much overhead. Therefore I find it is already a big step to have talks, and first drafts (which I did follow in the other thread :) )
     
Thread Status:
This last post in this thread was made more than 31 days old.