Quantcast
Channel: Programming (In-game)
Viewing all articles
Browse latest Browse all 645

Simple way to avoid null pointer when showing terminal blocks on hud?

$
0
0
Not all terminal blocks have the "ShowOnHUD" value to set, and thus if you do

foreach(IMyTerminalBlock block in blocklist) {
if (damaged) block.SetValue("ShowOnHUD", true);
}

it will invariably throw a null pointer or whatever.

Is there a simple way to use IMyTerminalBlock.GetProperties or whatever to easily tell if a block has that function before I try to apply it?

I tried enclosing the action in a try catch, but the execution would still fail.

Viewing all articles
Browse latest Browse all 645

Trending Articles