You can better just only add the registry reading to OnEvent_Signin, that will always work because initialize usually won't know the uid yet, and only write out count on OnEvent_Signout, that will cut down on a lot of registry writing, and errors when initializing:
EDIT: Added Initialize too, now it will also read the correct number when resetting the script.
code:
var RaadselId = Array();
var teller = 0;
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind)
{
var Message=Message.toLowerCase();
if (MessageKind == 1 && Message.substr(1,4) == "druk")
{
var ranNum = Math.floor(Math.random() * Raadsel.length);
RaadselId[ChatWnd.handle] = ranNum;
ChatWnd.SendMessage(Raadsel[ranNum]);
teller++;
}
if(MessageKind == 1 && Message.substr(0,7) == "ik wens" || Message.substr(0,8) == "antwoord" || Message.substr(1,9) == "antwoord")
{
ChatWnd.SendMessage(Antwoord[RaadselId[ChatWnd.handle]]);
}
}
function OnEvent_Initialize(MessengerStart)
{
if (!MessengerStart)
{
if (Messenger.MyStatus != 0)
{
OnEvent_Singin(Messenger.MyEmail);
}
}
}
function OnEvent_Signin(Email)
{
try
{
count = ReadRegistry("count");
}
catch(e)
{
Debug.Trace("Reading Settings Failed, Defaulting to zero");
count = 0;
}
}
function OnEvent_Signout(Email)
{
try
{
WriteRegistry("count", count, "REG_DWORD");
}
catch(e)
{
Debug.Trace("Writing to Registry Failed, Settings could not be saved");
}
}
function WriteRegistry(key, value, type)
{
if (type == undefined){ type = "REG_SZ"; }
var Shell = new ActiveXObject("WScript.Shell");
return Shell.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key, value, type);
}
function ReadRegistry(key)
{
var Shell = new ActiveXObject("WScript.Shell");
return Shell.RegRead(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key);
}