Space Engineers

Space Engineers

View Stats:
Glew 20 Nov, 2017 @ 5:12am
How to fix/time your programmable blocks!
Add:

Runtime.UpdateFrequency = UpdateFrequency.None; // Disable self-execution.
Runtime.UpdateFrequency = UpdateFrequency.Once; // Run on the next tick, then remove.
Runtime.UpdateFrequence = UpdateFrequency.Update1; // Every tick.
Runtime.UpdateFrequency = UpdateFrequency.Update10; // Every 10th tick.
Runtime.UpdateFrequency = UpdateFrequency.Update100; // Every 100th tick.

:To your programmable blocks and they will run themselves.
Last edited by Glew; 20 Nov, 2017 @ 12:37pm
< >
Showing 1-8 of 8 comments
Thalyn 20 Nov, 2017 @ 8:21am 
The code you've listed is superfluous. The first line sets it to every 100th tick plus whatever it was before (presumably nothing since that's the first-run function), the second removes the flag for every 10th tick (which wasn't set), and the last removes the flag for every tick (which also wasn't set), so you may as well have just done the first line as a hard assignment instead of a bitwise OR and skipped the rest.

Runtime.UpdateFrequency = UpdateFrequency.None; // Disable self-execution.
Runtime.UpdateFrequency = UpdateFrequency.Once; // Run on the next tick, then remove.
Runtime.UpdateFrequence = UpdateFrequency.Update1; // Every tick.
Runtime.UpdateFrequency = UpdateFrequency.Update10; // Every 10th tick.
Runtime.UpdateFrequency = UpdateFrequency.Update100; // Every 100th tick.

The script will only run once at any given time, but it passes flags you can read back so you can perform different routines on every tick, every 10, every 100 and the bonus (once), without setting up your own accumulators. eg:

if ((updateSource & UpdateType.Update100) != 0) <something for every 100 ticks>
if ((updateSource & UpdateType.Once) != 0) <special one-off stuff>

You can also freely change between them during the script. Might be useful for things which don't always require per-tick timing, like a radar script which only kicks into "high sensitivity" mode when it actually detects something.
Last edited by Thalyn; 20 Nov, 2017 @ 8:26am
Glew 20 Nov, 2017 @ 10:44am 
Thank you!
spacewolfcub 20 Nov, 2017 @ 11:27am 
Thanks
Thalyn 20 Nov, 2017 @ 8:15pm 
I should also mention that you can combine those, which is going to be essential to use the "if" statements later. So if you want a program to run every tick with a special trigger every 100 ticks, you'd use:

Runtime.UpdateFrequency = UpdateFrequency.Update1 | UpdateFrequency.Update100;

That | in the middle performs a bitwise OR, so you end up with both values effectively set at the same time. You can add or remove other values with bitwise OR or AND statements, such as:

Runtime.UpdateFrequency &= ~UpdateFrequency.Update100; // Bitwise AND with NOT 100.
Runtime.UpdateFrequency |= UpdateFrequency.Once; // Bitwise OR with Once.

This would remove the flag telling it to update every 100 ticks, followed by setting the "Once" flag, without changing anything else either time. Presumably you coudl also use standard addition and subtraction, but the logical comparitors are the officially referenced way to go about it and I haven't tested otherwise.

Also, be aware that the 10-tick and 100-tick modes aren't exact, so you'll need to use your own accumulators if you need that kind of precision. The game will dynamically separate PB execution to reduce per-update load, meaning they can actually occur more or less quickly if you're adding or removing running programs.
Cynic 4 Aug, 2018 @ 11:32am 
what method does this run?
Dan2D3D  [developer] 4 Aug, 2018 @ 11:48am 
C#

There is a video in this Guide, may help.

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=368213720&searchtext=programable+block


Note

2017 thread
The game is not the same anymore so maybe ask in the "in-game-programming" Channel on Keen Discord server, all the best are online every days and like to help on programming.

Join here, the link is in the first comment :
https://steamhost.cn/steamcommunity_com/app/244850/discussions/0/810938810590486770/
ShadedMJ 4 Aug, 2018 @ 12:19pm 
@Dan2D3D : You should talk to Steam and get all threads prior to 2017 locked or something.
Dan2D3D  [developer] 4 Aug, 2018 @ 12:28pm 
Devs and moderator can do this.

Usually I lock right away but sometimes I will help and specify that it is better to create new Discussion when a forum thread is old because the game changes.. Still in making so not the same anymore.

I will not lock if it's relevent but I may lock this one later.
< >
Showing 1-8 of 8 comments
Per page: 1530 50

Date Posted: 20 Nov, 2017 @ 5:12am
Posts: 8