It is late, but I can't seem to find a way to do this. I was thinking of just breaking it into it's own if statement or doing the else commeand before the if, but all with the same result (well I couldn't find how to do a "does not contain" easily). I will try ot play with it some more at the office tomorrow.
Basically you are trying to declare @hostname twice. If you declare it at the beginning of the script and only assign values based on the condition it works.
script getHostname(NCM.Nodes @ContextNode )
string @dot = '.'
if (@ContextNode.SysName contains @dot)
int @suffix = indexof(@ContextNode.SysName,@dot) - 1
@hostname = substring(@ContextNode.SysName, 1, @suffix)
@hostname = @ContextNode.SysName