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.

Ingame Programming missing API and functions and known issues

Discussion in 'Programming (In-game)' started by mexmer, Apr 23, 2015.

Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.
  1. Malware Master Engineer

    Messages:
    9,404
    I'm not. I mean, Save, fine. Constructor, not so much. I need my scripts to control the timers, not the other way around. This is how I intended the constructor to be used :(
    --- Automerge ---
    Then please make a proper bug report, not here because this might not be read.

    [Edit] Actually, I think Rexxar might know of this already... but to be on the safe side...
     
  2. krypt-lynx Apprentice Engineer

    Messages:
    175
    > This is how I intended the constructor to be used

    Well... Probably user started action before game save load. And timer already started (in ideal SE) So, it does not matter. You only need restore script state where.
    --- Automerge ---
    To be clear: I'm sure 3/4 of my reports it not processed. Linked there, for example, was not. So, I don't want to play in Russian roulette. If @rexxar will read it there it have much more chances to be processed then real bug report. So, if you want to create bugreport - feel free to do it.
     
  3. Malware Master Engineer

    Messages:
    9,404
    Hah.

    You think that is Russian Roulette and you want to gamble on things written here being done something about... :D

    I'm on vacation, I don't have a computer capable of running SE.
     
  4. krypt-lynx Apprentice Engineer

    Messages:
    175
    I know what Russian Roulette is. Actually, I know how you can always win (aka not to die)
    But somehow it become used in this way. At least, in my experience. Looks like I was wrong. Well, I'm not a native speaker, I'm Russian :D
     
  5. Malware Master Engineer

    Messages:
    9,404
    That's not what I meant :p I know you know what it is, I was saying - if you compare that to russian roulette, as in difficult to get through (which it really isn't, although you might never get a response - it's still read), and you were expecting posts here to get more attention, which is far less likely... Anyway, I think Rexxar already knows about this issue.
     
  6. krypt-lynx Apprentice Engineer

    Messages:
    175
    Oh...

    > you were expecting posts here to get more attention
    It was not about getting more attention there, it was about summoning Rexxar in the topic :)
    Because I see attempts to post something about programming API related reports to the bugreports subforum as useless. To be noticed where topic must be commented by 3-4 guys at least. And nobody comments programming related topics. So, yes, almost zero chances to be noticed there is still greater then chances to be noticed in bugreports subforum.
    --- Automerge ---
    I will create proper bugreport. One more last time.
     
  7. Malware Master Engineer

    Messages:
    9,404
    I see - and grant - your point. But still ;)
     
  8. Wicorel Senior Engineer

    Messages:
    1,239
    St
    By experimentation, Start works, TriggerNow does not.

    Code:
    IMyTimerBlock theTriggerTimer = null;  
    
    
    public Program() {
    
        // The constructor, called only once every session and 
        // always before any other method is called. Use it to 
        // initialize your script.  
        //      
        // The constructor is optional and can be removed if not 
        // needed.
    
    	List<IMyTerminalBlock> timersList= new List<IMyTerminalBlock>(); 
    	GridTerminalSystem.GetBlocksOfType<IMyTimerBlock>(timersList); 
        if (timersList.Count > 0) 
            theTriggerTimer = timersList[0] as IMyTimerBlock; 
    
        if (theTriggerTimer != null) 
        { 
    //       theTriggerTimer.ApplyAction("TriggerNow"); 
    //        Echo("Triggering:" + theTriggerTimer.CustomName); 
    
            theTriggerTimer.ApplyAction("Start"); 
            Echo("Starting:" + theTriggerTimer.CustomName); 
        } 
        else 
            Echo("No Timer found"); 
    
    }
    
    
    
     
  9. krypt-lynx Apprentice Engineer

    Messages:
    175
    Your program in empty world works for me also. I need to test it more.
    And my script works in empty world
    Also your script works in my test world
    But my script in my test world does not works.
    --- Automerge ---
    I don't understand anything anymore.
    youtube link
    First save/load: timer was not started
    Second save/load: timer was started

    Output generated by this code:
    github link
    Except line #49 was commented.
    --- Automerge ---
    Malware, can I disable protection in local world somehow? I want to do System.Threading.CurrentThread.Sleep()
    --- Automerge ---
    Stuff ever weirder: link
    So, looks like we have race condition there. Or I have really strange issue in my code.
    --- Automerge ---
    P.S.: I want salary as tester. And to sleep. :D
     
    Last edited: Jul 13, 2017
  10. Malware Master Engineer

    Messages:
    9,404
    I'm afraid not.
    --- Automerge ---
    Then apply for a job, they're always hiring ;)
    --- Automerge ---
    @Wicorel Well, that explains why it hasn't been fixed yet, if it can't be reproduced properly... :(
     
  11. krypt-lynx Apprentice Engineer

    Messages:
    175
    > if it can't be reproduced properly...
    I can upload grid from the last video. It stable not working. But I have no simple script to demonstrate it.
    --- Automerge ---
    So. Current theory:
    Looks like "Start" does nothing if at saving moment timer was triggered by "TriggerNow".

    At least I found workaround:
    Configure Timer actions in this way:
    - run pb;
    - start timer;
    - trigger timer;
    --- Automerge ---
    So, I found.

    This code does not the starts timer after game load:
    Code:
    public Program() {
        var timer = this.GridTerminalSystem.GetBlockWithName("timer");
        timer.ApplyAction("Start");
    }
    
    public void Main(string argument) {
        var timer = this.GridTerminalSystem.GetBlockWithName("timer");
        timer.ApplyAction("TriggerNow");
    
        Echo(DateTime.Now.ToString());
    }
    
    Timer must be configured to start pb
    --- Automerge ---
    @Wicorel, can you confurm it?
    --- Automerge ---
    Also it happens then grid is pasted in world. Just noticed while creating grid for bugreport.
     
    Last edited: Jul 13, 2017
  12. Inflex Developer Staff

    Messages:
    396
    There is actually pretty easy way to do it.

    Simply make a mode that will expose custom terminal property for PB of any type you want. In this case, it may be for example `Action<int>`, delegate that will internally call your desired `Sleep`.
    Query this property in your script and call it.
    Profit
     
  13. Malware Master Engineer

    Messages:
    9,404
    Are you saying Sleep is available to mods? I thought it wasn't. My bad!
     
  14. Inflex Developer Staff

    Messages:
    396
    Well, there is not really much mods can't do at the moment, including access to game's parallelization engine and full fat .NET Timers, so I was naturally expecting free access to `Thread` class too.
    Silly me. It's forbidden, I just tested.
    So you need to go one step further, make a plugin, load it into the game, expose terminal property to PB, tada tada tada ... ;)
     
  15. Malware Master Engineer

    Messages:
    9,404
    I wonder, with a plugin, couldn't you actually whitelist the types directly? I think so...
     
  16. Inflex Developer Staff

    Messages:
    396
    You definitely could, but for that you need little bit of knowledge on how the whitelister works and how to use it.
    Everyone knows how to expose terminal property so it is easy for'em to accept such solution, but if you tell them to go into whitelister and do something in there, the'll probably just leave it be and go away for some other fun :p
     
  17. Malware Master Engineer

    Messages:
    9,404
    Oh, I dunno, I don't think it's that hard.
     
  18. Inflex Developer Staff

    Messages:
    396
    You made it :D
     
  19. krypt-lynx Apprentice Engineer

    Messages:
    175
    I want to have ingame music player, I need access to file system and sound api :D
     
  20. Inflex Developer Staff

    Messages:
    396
    You have moddable Sound Block. Deal with it ;)
     
    • Funny Funny x 1
  21. krypt-lynx Apprentice Engineer

    Messages:
    175
    It looks like a challenge. Well... I'm already dealt with unmodable fonts... I don't want to, I don't want to do yet another impossible thing :D
     
  22. krypt-lynx Apprentice Engineer

    Messages:
    175
    Not actually an issue, but.. I need to log it for the history.
    IMySensorBlock returns useless data about character orientation while they stay on surface.

    I'm created script a while ago:
    http://steamcommunity.com/sharedfiles/filedetails/?id=948506635
    It trying to track player camera orientation and to translate it to lcd screen coordinates.
    But it does not works while character is standing, because IMySensorBlock returns orientation of character model. Which is right, but useless.
     
  23. Malware Master Engineer

    Messages:
    9,404
    While I'm immensively grateful for your contribution of the monospace font - immensively doesn't even really cover it - I just wish you'd have chosen a slightly prettier font :p
     
    • Agree Agree x 1
  24. krypt-lynx Apprentice Engineer

    Messages:
    175
    Well... I'm already know your opinion about it :)
    There is no actually suitable monospaced font with suitable license.
    Anyway, At least it is immersive. At least for me: Text panels feels like text terminals :) And this font is readable at low sizes (you can use it on 0.3 font size).

    Also, there was some limitations with is not exists anymore: at moment of creation font height was required to be 37px. This is bad size, because it is prime number.
    --- Automerge ---
    > And this font is readable at low sizes (you can use it on 0.3 font size).
    Ooops. Not anymore. (1.182.018)
    Reducing font brightness dies not reduce glowing now.
     
    Last edited: Jul 22, 2017
  25. Regn Trainee Engineer

    Messages:
    74
    IMyAirVent - a method to retrieve the room's volume, similar to GetOxygenLevel(), unless the air vent does not calculate pressure from volume to begin with. Finding out how much oxygen a room can- and does contain (in liter) ends in unreliable results when reverse-engineering from percent. I consider this a non-important / commodity method. Just putting it out there.

    Is my presumption correct in that we cannot program IMyJumpDrive (set coordinates and jump) because of potential combat imbalance issues?
     
    • Like Like x 1
  26. Wicorel Senior Engineer

    Messages:
    1,239
    That's what we've been told.
     
  27. krypt-lynx Apprentice Engineer

    Messages:
    175
    Last edited: Jul 29, 2017
  28. Inflex Developer Staff

    Messages:
    396
    Hey,
    fist of all, there were no changes to PB API whitelist in near past, especially not one that would relate to `CharEnumerator` in any way so I highly doubt it ever worked with fixed version of whitelist checker after last year's "Roslyn update".

    Secondly, never use C# enumerators directly like that, unless you have really good reason for that and know what are you doing, which based on your code you don't.
    (Hint: Undisposed enumerators and unchecked collection range may cause you serious issues). In this case, you'd be much better using traditional `for` and strings's indexer to access one character at the time. Your code would look much more readable and you would not need to use parts of the language that are, probably for a good reason, forbidden.
     
  29. krypt-lynx Apprentice Engineer

    Messages:
    175
    > Undisposed enumerators
    Well... I is C#'s CG THAT bad? I believed then method execution is ended enumerator is no longer visible and must be collected.
    What about length check.. It is intentional. It is just precalculated data and decoder for it. Unfortunately, code length in SE is a thing. Anyway, probably better to use "while" loop there.

    > I highly doubt it ever worked with fixed version of whitelist checker after last year's "Roslyn update".
    Github says gist was created 9 months ago. Is it was before Roslyn update? I don't remember when exactly it happened.

    Also, I have better example there CharEnumerator was required:
    https://github.com/krypt-lynx/SE-Sequencer2/blob/master/Sequencer2/Script/neighbours/Parser.cs#L109
    Execution of this thing can be splitted between multiple runs.
     
  30. Inflex Developer Staff

    Messages:
    396
    No, it's not about GC being bad, unable to release the allocated enumerator object. It actually doesn't have to do anything with memory, usually. It's just that some collections may need to lock or allocate some internal resources, some non memory related which may GC not be aware of. Since C# doesn't have deterministic destructor behavor like C++, it has to offer some way to provide so called "scope guard" pattern. In C#, it's called "disposable pattern", provided by disposable objects.

    Imagine concurrent collection that will lock itself from external modifications while you iterate it. When you use foreach, it will dispose the enumerator for you and everything works fine, but when you take this responsibility on you and forget to dispose it, you just effectivelly locked yourself from that collection.

    You may pass along with undisposed enumerator for most collections in some particular versions, disposing methods are usually empty for simple collections, but that can change in any update. More on that in documentation of IEnumerator#Dispose method and using statement.
     
Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.