This is a GECK forum question that's answered by pretty much any scripting tutorial on the GECK wiki.
Alystn's spot on, although a slightly neater & marginally more efficient way of arranging that script is:
short countshort doonebegin gamemodeif(doonce) if(count != ...) ;... endifelse set doonce to 1 set count to ...endifend