Space Engineers

Space Engineers

Taleden's Inventory Manager
Lynnuxx 2017 年 3 月 12 日 上午 7:55
How to keep Custom Data of the PB running TIM
TIM overwrites the whole Custom Data of the programmable block on every execution.
To prevent this I've changed the code a bit:
// update persistent data after one full cycle string[] line = Me.CustomData.Split(NEWLINE, REE); Me.CustomData = ""; bool miss_ver = true; for(int k=0;k<line.Length;k++) { string[] kv = line[k].Trim().Split('='); if (kv[0].Equals("TIM_version", OIC)) { miss_ver = false; line[k]= "TIM_version=" + (lastVersion = VERSION) + "\n"; } Me.CustomData+=line[k]+"\n"; } if(miss_ver) Me.CustomData += "TIM_version=" + (lastVersion = VERSION);

@taleden You can delete this discussion if you decide to implement it in your script.
最后由 Lynnuxx 编辑于; 2017 年 3 月 12 日 下午 5:40
< >
正在显示第 1 - 4 条,共 4 条留言
taleden  [开发者] 2017 年 3 月 12 日 下午 5:26 
I figured it was a safe assumption that TIM could do with its own PB's custom data as it wished, and in theory I'd eventually like to support additional definitions there (such as for modded items).

What problem did it cause you for TIM to erase and rewrite it's own custom data?
Lynnuxx 2017 年 3 月 12 日 下午 5:51 
I use a programmable block to call all other programmable blocks. The custom data stores parameters like recurrence and the slot in which a PB is executed (enables load balance) as well as arguments passed to reset the script or in case the script needs one for its cyclic execution.
I've been planning to call TIM every 30 ticks but currently I still call it once per second.
最后由 Lynnuxx 编辑于; 2017 年 3 月 12 日 下午 5:54
taleden  [开发者] 2017 年 4 月 3 日 下午 1:18 
I think for the time being my stance is that a script ought to be able to assume that it can safely use the Custom Data field of it's own Programmable Block; if your scheduling script requires the use of the Custom Data field on every other Programmable Block, that seems to me like a problematic design which is bound to run into issues with any number of other scripst that also want to make use of Custom Data.
Lynnuxx 2017 年 4 月 4 日 下午 3:41 
Hence this routine posted above. It adds or overwrites only the info the script needs without changing the other entries. But I gave up the scheduler because the only advantage is load balancing and that's not necessary in most cases and can be achieved in a different way. No need to waste a PB for this and no need for this routine to be implemented in TIM, especially since it's at the character limit.

Anyways being able to use the custom data of a block by several scripts is clearly an advantage. I already do this but with several of my own scripts. Nonetheless they are tolerant for other entries in the custom data.
But in case of scripts being at the character limit like TIM I agree that there are more important features than to share the Custom Data of its own PB.
< >
正在显示第 1 - 4 条,共 4 条留言
每页显示数: 1530 50