Space Engineers

Space Engineers

查看统计:
Glew 2017 年 11 月 20 日 上午 5:12
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.
最后由 Glew 编辑于; 2017 年 11 月 20 日 下午 12:37
< >
正在显示第 1 - 8 条,共 8 条留言
Thalyn 2017 年 11 月 20 日 上午 8:21 
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.
最后由 Thalyn 编辑于; 2017 年 11 月 20 日 上午 8:26
Glew 2017 年 11 月 20 日 上午 10:44 
Thank you!
spacewolfcub 2017 年 11 月 20 日 上午 11:27 
Thanks
Thalyn 2017 年 11 月 20 日 下午 8:15 
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 2018 年 8 月 4 日 上午 11:32 
what method does this run?
Dan2D3D  [开发者] 2018 年 8 月 4 日 上午 11:48 
C#

There is a video in this Guide, may help.

https://psteamcommunity.yuanyoumao.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://psteamcommunity.yuanyoumao.com/app/244850/discussions/0/810938810590486770/
ShadedMJ 2018 年 8 月 4 日 下午 12:19 
@Dan2D3D : You should talk to Steam and get all threads prior to 2017 locked or something.
Dan2D3D  [开发者] 2018 年 8 月 4 日 下午 12:28 
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.
< >
正在显示第 1 - 8 条,共 8 条留言
每页显示数: 1530 50

发帖日期: 2017 年 11 月 20 日 上午 5:12
回复数: 8