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.

Programmable Block Feedback Thread

Discussion in 'Programming (In-game)' started by rottielover, Jan 1, 2015.

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

    Messages:
    42
    pro - been waiting for both this block and several other blocks that have come out...

    con - i too am a not good programmer....which is going to be interesting to try...however i have seen screens and have attempted to try to program i hope to see auto complete and or something that has a drop down menu with the options of all the block id's that can be use....

    On a sidenote if this is going to be something that will be need for objects or AI's for both an enemy as well as workers on your side...i am going to be learning how to program really fast...
    i am look forward to the memeber of the commuity to make youtube videos of how toos
     
  2. shimonu Apprentice Engineer

    Messages:
    396
    I think He wanted to set piston lenght to exact number using script (right now we have IncreaseUpperLimit, DecreaseUpperLimi and similiar).
     
  3. DuneD Junior Engineer

    Messages:
    948
    So, I've been trying something simple, having 2 entities, one being the player, the other being a grav generator. Basically I want the generator to turn off when the player gets close:

    Code:
    void Main() {
    var MyGen = GridTerminalSystem.GetBlockWithName("GravGen");
    var myPlayer = myGen.OwnerId;
    var dist1 = myGen.Position
    var dist2 = myPlayer. ???
    }
    
    So usually, using the api, I would cast the player as IMyPlayer, which turns it into an entity so I can get its current position. I cant seem to do that now and any of the other functions, from .Position() to GetPosition, pos, trying to get the axis separated, nothing seems to work. Any idea on how to get the player as an Entity ?
     
  4. Bad_Idea Apprentice Engineer

    Messages:
    498
    I think you missed my point by a longshot. As mentioned above i'm talking about the MaxLength... aka the maximum distance the piston is allowed to extend. Maybe you should take some time to look at the question before you spit out an answer?
     
    Last edited by a moderator: Jan 1, 2015
  5. TheQuixote Apprentice Engineer

    Messages:
    119
    Is there an output console that we can print to?

    If not, that's a pretty major oversight. Pretty hard to figure out what's going on without it. Can't even do a "Hello World" tutorial.

    Other nice to haves would be
    • Access to inventory
    • Ability to move inventory.
    • The ability to register for sensor and timer events. ( One sensor and one programming block instead of having multiple senors that trigger multiple programming blocks )
    • The ability to register for some other events like on collision or on damage.
    • Ability to set field values. ( Increase and decrease seem to use frustratingly arbitrary values )
    • Programing blocks should maintain suit power levels while being accessed
    • Code hinting.
    • Auto Indenting
    Right now programming blocks don't seem to add anything other than a more complex way to implement timer blocks.
     
    Last edited by a moderator: Jan 1, 2015
  6. shimonu Apprentice Engineer

    Messages:
    396
    Did anyone found Delay option or do I have to use timer blocks?
    Is there any way to read sensor status? (if its detecting something).
     
  7. Arcturus Senior Engineer

    Messages:
    1,649
    It appears as if they didn't want client players writing anti-server logic bombs, so they took steps to prevent long-running, infinite, or recursion scripts.
     
  8. TheQuixote Apprentice Engineer

    Messages:
    119
    You can still create 100 timer blocks all triggering the script once a second. Doesn't mater if it's timer block or scripted timer that can only trigger itself once a second.

    Having scripted delays might be less of a load on servers than arrays of timer and programming blocks set up to achieve the same thing.
     
  9. DuneD Junior Engineer

    Messages:
    948
    You can still build a timer using a loop.
     
  10. Thedevistator Senior Engineer

    Messages:
    1,942
    I'm wondering can you do hot keys yet?
     
  11. Bad_Idea Apprentice Engineer

    Messages:
    498
    Unsure, experimenting with such events ATM, doesn't look very bright.
     
  12. Kuu Lightwing Senior Engineer

    Messages:
    1,503
    Umm... now I'm really confused - that's why I didn't like the idea of C# - it's... wordy. And I don't understand these constructions.

    I mean... why is it like this:
    Code:
    block.GetActionWithName("IncreaseUpperLimit").Apply(block);
    and not like this
    Code:
    block.IncreaseUpperLimit ();
    ?
     
    Last edited by a moderator: Jan 1, 2015
  13. chance Trainee Engineer

    Messages:
    22
    I'm pretty stoked about this, because I think it will add a ton a variety to the game even for non programmers, and it lets me bring my own type of engineering to bear :) I know this is a first pass, and is only exposing things you could mostly already accomplish, but I think the power of it will become much more apparent when more detailed data gets accessible.

    Things I would love to see happen:
    • Active power generation (actual and potential) of the current grid - maybe combined with the ability to trigger a script when going into / out of overload
    • Active Power Draw of the current Grid
    • Set Exact positions for pistons and rotors. (combine this with the top one and you get self aligning solar arrays)
    • List of signals received by an antenna, and the signal strength.
    • Trigger things when turrets detect hostiles
    • Trigger things when turrets detect meteors
    • So many things for antennas - this could make them really powerful and allow some was to be sneaky without breaking the game, I am very opposed to faction specific antenna broadcasts.
    Honestly, this makes it so updates to single blocks can add huge new capabilities to the game. Kinda like the emergent gameplay we already know and love with the physical portions of the game.

    PS: While I really see the appeal of a node based macro approach to scripting, which is what I feel most people were expecting, I think it is worth pointing out that making one of those work well is vastly more difficult than it appears on the surface. I think this approach, being much easier to implement, makes much more sense for Alpha and watching how we use the tools they just gave us will allow them to form better requirements for one, if they implement it in the future.
     
  14. a2457 Senior Engineer

    Messages:
    1,366
    once you get a hang of it, it will be easyer to use than visual stuff.
    been there, done that, and i even got a t-shirt.
     
  15. TheQuixote Apprentice Engineer

    Messages:
    119
    The verbose syntax has more to do with object oriented design and how this application is designed than C# specifically.

    Why it's like the way it is is little hard to explain, but basically it makes things like a modding API and the fact that 3rd party blocks will work with timers A LOT easier to implement.
     
  16. Kuu Lightwing Senior Engineer

    Messages:
    1,503
    Well, it's just not very beginner-friendly... I mean, I understand what is methods, but we also have some sort of "Actions" which are completely different things (are they classes?) and I don't even want to think how it really works...
     
  17. TheQuixote Apprentice Engineer

    Messages:
    119
    Basically, yes the "Actions" are a type of object. Blocks with actions are blocks that contain a group of those action objects. So you have to access those "Actions" through the block.

    You're right it's not beginner friendly at all, especially if you're not familiar with object oriented design principles.

    Start messing with the scripts that show up in the workshop. Not a great way to learn why things work but you should start to figure out how to get things done.
     
  18. a2457 Senior Engineer

    Messages:
    1,366
    i for one dislike oop for a number of reasons ..
    while i do not mind the c# style, the one that php uses would been a bit friendlier.
     
  19. Kasrith Trainee Engineer

    Messages:
    5


    While this doesn't directly fix the problem of the block not powering your suit, if you sit in a control console you can access the script interface for the programmable block, thereby keeping a full suit charge.
     
  20. RIPerKilla Apprentice Engineer

    Messages:
    140
    Pros: Well, finally a way to execute some difficult sequences with only one button.
    Cons: No clock - timer block is a slow clock, really. Noob in C# and can't find easy implementation of Lua wait() command. Can't set values and retrieve them directly.

    I personally compare this feature to Wiremod's CPUs. They have pretty easy Lua scripting, but great possibilities, much greater than we now have.
    Looking forward to future updates.
     
  21. Nillzie Trainee Engineer

    Messages:
    9
    Can anyone tell me what the best way to put a delay in a for loop in this, System.Threading.Thread.Sleep(200); isn't working/Allowed
     
  22. a2457 Senior Engineer

    Messages:
    1,366
    okay, so i been waiting for this psoiler for a long time now.

    those who say this programming stuff should have a drag and drop system, got news.
    it was allready in the game.
    with the timer blocks.
    bit nerfed, but still can do loops, change rotor / whatever setting, turn lights on and off, and so on.

    so now you can do a comparism wichone you will probably use.
    and stick to that version of you like :D
    (be it any of the two)
     
  23. mhalpern Senior Engineer

    Messages:
    2,119
    pros: cool things
    con: no non-Boolean fields yet or power related fields except the one used for battery semi auto behind the scenes which is a Boolean...
     
  24. Captain Lackwit Trainee Engineer

    Messages:
    25
    Sure this is a nice thing for certain players, but this just makes the increasingly complicated mechanics harder and harder for people like me to get into. When the game was called Space Engineers, I didn't think I would have to literally be an engineer of some sort to enjoy it.
    You're still missing ladders, and the game runs like ass. There has been zero optimization lately. Look, my machine shouldn't have a single problem with this game. The models are visibly low poly and such. So why am I having a hard time? Why can't you guys just optimize your damned game and fix the increasing number of bugs in it?
    I want to love this game as much as I did six months ago, when I was happily working on my ship, willing to learn new things about it.
    Not learn C++ and actually get my damn ships working after three months of learning how to do C++ normally. In which plenty of other overcomplicated updates will be added, I'm sure. I know it sounds crazy, but...
    Some of us just want to play a fun video game where you build stuff. In space.
     
  25. Malexion Trainee Engineer

    Messages:
    68
    Probably because they didn't add Inotify on any of the properties, all the properties are only good for is seeing the current state.

    To update something you have to do this convoluted thing:

    Code:
    var block = GridTerminalSystem.GetBlockWithName("gravity1");
    block.GetActionWithName("OnOff_On").Apply(block);
    
    Doesn't really make it easy to check enabled state either.
     
  26. Textor Junior Engineer

    Messages:
    775
    So do that. None of my friends know how to program in C# and they had a great time ignoring the programming block all day. I sat there figuring out the scripting system, and they continued on as if the update didn't even happen.

    Sorry, I meant they all stared at space engineers like drooling idiots because the programming block suddenly made every other part of the game worthless without it. I mean, piloting a ship manually? That is so 2014
     
    Last edited by a moderator: Jan 2, 2015
  27. Kasrith Trainee Engineer

    Messages:
    5
     
  28. CyberVic Apprentice Engineer

    Messages:
    106
    First of all, for those people complaining about how they gave us C# scripting in game... cry me a friggin river. Become an engineer or just be a builder / pilot. Not everyone can be software engineers, this is true, but for those who are this is the most amazing thing anyone has ever done to a game. So please, step back. As others have mentioned, with sensors, timers, buttons, and other blocks which all interact with one another, you have many different things you can do, more than most sandbox games these days without knowing any scripting. Also... seriously you can teach yourself C# in like a weekend, at least the basics of C#. Visual Studio Express is free. Start a console application project, add KSW references to it, use awesome intellisence in Visual Studio, copy and past code into game. Winning.

    EDIT: Apparently all the first things I tested are known issues with workarounds sorta... http://steamcommunity.com/sharedfiles/filedetails/?id=360966557


    Now let's get into some problems I've found.


    Let's examine this code. This entire script compiles.
    When calling test1 or test3 from main works just fine (for loop, while loop).
    When calling test2 and you get an error when running it (foreach loop).

    I imagine this is because for some odd reason KSW doesn't want us using foreach loops and prefers us to use for loops, but honestly I see while loops to be more dangerous so I assume this is some kind of bug in the "infinite loop" code. A foreach loop is explicitly finite.
    Code:
            void Main()
            {
                test1();
            }
            void test1()
            {
                var items = new List<int>();
                items.Add(100);
                items.Add(25);
                items.Add(3);
                int sum = 0;
                for (int i = 0; i < items.Count; i++)
                {
                    sum += items[i];
                }
            }
            void test2()
            {
                var items = new List<int>();
                items.Add(100);
                items.Add(25);
                items.Add(3);
                int sum = 0;
                foreach (int item in items)
                {
                    sum += item;
                }
            }
            void test3()
            {
                var items = new List<int>();
                int sum = 0;
                while (sum <= 100)
                {
                    sum += 10;
                }
            }
    
    Next, let's examine this code. It doesn't compile because there is a missing reference to System.Linq. Not sure why we don't have a reference to System.Linq unless the source is .Net 3.0 and not even 3.5... actually I think LINQ has been around since 3.0... and 5.0 is coming out soon. So I can only image that this is just a missing reference.

    Code:
    <div><div>void test4()
            {
                var items = new List&lt;int>();
                items.Add(100);
                items.Add(25);
                items.Add(3);
     
                var q = from item in items
                        where item > 10
                        select item;
     
                q.Sum();
            }
    </div>
    I will continue to test. Thank you again KSW. You have made me a very happy space software engineer.
    </div>
     
    Last edited by a moderator: Jan 2, 2015
  29. CyberVic Apprentice Engineer

    Messages:
    106
    Oh thank god, I think I figured out. Please KSW, add to your documentation that if using visual studio:
    https://www.youtube.com/watch?v=gAh1bNfRLPw

    Add this to your using statements:
    Code:
    using Sandbox.ModAPI.Ingame;
    Add this as a local variable of your script class
    Code:
    IMyGridTerminalSystem GridTerminalSystem;
    From there intellisence is magic.
     
    Last edited by a moderator: Jan 2, 2015
  30. CyberVic Apprentice Engineer

    Messages:
    106
    Pretty happy with the intuitive nature of the way interacting with grid objects works. Wish the interfaces had XML comments though so as we use insistence there was a bit more available there.

    Another feature request, it would be nice if these script blocks supported static classes so we can have extensions. If we can't build our own extensions and are limited to simple procedural programming, then could you at least put some basic extension methods like this on the base classes. That way it's a little easier for us to do the same basic stuff over and over and over without having to copy code all over the place.

    EDIT: After thinking about this more and how statics and extensions are treated by the compiler, I'm not sure if you can get this to work. Would be curious if you could.

    Overall though, like I said, I am pretty happy. I'm currently working on a pretty complex program to report on 1 minute interval (using timer) the status of key systems on our flagship.

    Code:
    <div><div>        List&lt;IMyTerminalBlock> blocks = new List&lt;IMyTerminalBlock>();
            void Main()
            {
                blocks.Clear();
                GridTerminalSystem.GetBlocksOfType&lt;IMyLightingBlock>(blocks);
     
                for (int i = 0; i &lt; blocks.Count; i++)
                {
                    ((IMyFunctionalBlock)blocks[i]).Enable();
                }
            }
     
            static class MyExtensions
            {
                static bool Action(this IMyTerminalBlock block, string action)
                {
                    var foundAction = block.GetActionWithName(action);
                    if (foundAction != null)
                    {
                        foundAction.Apply(block);
                        return true;
                    }
                    else return false;
                }
                static void Enable(this IMyFunctionalBlock block)
                {
                    block.Action("OnOff_On");
                }
                static void Disable(this IMyFunctionalBlock block)
                {
                    block.Action("OnOff_Off");
                }
                static bool Action(this IMyFunctionalBlock block, string action)
                {
                    var foundAction = block.GetActionWithName(action);
                    if (foundAction != null)
                    {
                        foundAction.Apply(block);
                        return true;
                    }
                    else return false;
                }
            }
    </div>
    </div>
     
    Last edited by a moderator: Jan 2, 2015
Thread Status:
This last post in this thread was made more than 31 days old.