Shoutbox

problem with Arrays - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: problem with Arrays (/showthread.php?tid=71475)

problem with Arrays by darkriven on 02-07-2007 at 04:25 PM

hi :)
I'm working on something like a bot.
It worked to answer people, but he simply answered everytime someone wrote a message. Now I've created the function GetStatus and the Array botstatus to save who i have answered this message yet. The bot should simply answer the sentence the first time someone wrote something.
(It should answer again if the state changed since the first answer)

Here is the code:
I don't work anymore :(

code:
var gChatWnd;
var wo = "weg";
var back = "";
var botstatus = new Array();

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    var tmpstatus;
    tmpstatus=GetStatus(ChatWnd.Handle);
    if(Messenger.MyName != Origin)
    {
    if(tmpstatus==0)
    {
          switch(Messenger.MyStatus)
            {
           case 7:
               ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist gerade " + wo + ". Er ist voraussichtlich wieder da um:" + back );
               break;
           case 8:
               ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist gerade am Telefon. Das dauert voraussichtlich bis um:" + back);
               break;
           case 4:
               ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist gerade beschäftigt. Er hat voraussichtlich wieder Zeit um:" + back);
               break;
           case 9:
               ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist gerade beim essen. Er ist voraussichtlich wieder da um:" + back);
               break;
           case 5:
               ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist mal kurz " + wo + ". Er ist voraussichtlich wieder da um:" + back );
               break;
          }
    }
    }

}


function GetStatus(windowhandle){
    var Status=0;
    for ( String arg : botstatus ){
    if(arg==windowhandle)
    Status=1;
    }
    if(Status==0)
    botstatus[botstatus.length]=windowhandle;
    return Status;
}


RE: problem with Arrays by Squelettor on 02-08-2007 at 02:23 PM

quote:
Originally posted by darkriven

code:
for ( String arg : botstatus )



code:

for (var i=0; i<botstatus.length; i++ )


The all script :

code:
var gChatWnd;
var wo = "weg";
var back = "";
var botstatus = new Array();

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
  Debug.Trace("OnEvent_ChatWndReceiveMessage : beginning");
  if(Messenger.MyName != Origin)
  {
    var tmpstatus=GetStatus(ChatWnd.Handle);
    if(tmpstatus==0)
    {
      switch(Messenger.MyStatus)
      {
        case 7:
          ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist gerade " + wo + ". Er ist voraussichtlich wieder da um:" + back );
          break;
        case 8:
          ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist gerade am Telefon. Das dauert voraussichtlich bis um:" + back);
          break;
        case 4:
          ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist gerade beschäftigt. Er hat voraussichtlich wieder Zeit um:" + back);
          break;
        case 9:
          ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist gerade beim essen. Er ist voraussichtlich wieder da um:" + back);
          break;
        case 5:
          ChatWnd.SendMessage("[Automessage] Hi " + Origin + "! Flo ist mal kurz " + wo + ". Er ist voraussichtlich wieder da um:" + back );
          break;
      }
    }
  }
  Debug.Trace("OnEvent_ChatWndReceiveMessage : end");
}

function GetStatus(windowhandle)
{
  Debug.Trace("GetStatus : beginning");
  var Status=0;
  for (var i=0; i<botstatus.length; i++ )
  {
    if(botstatus[i]==windowhandle)
    {
      Status=1;
    }
  }
  if(Status==0)
  {
    botstatus[botstatus.length]=windowhandle;
  }
  Debug.Trace("Status : " + Status);
  Debug.Trace("GetStatus : end");
  return Status;
}


RE: problem with Arrays by darkriven on 02-08-2007 at 02:55 PM

thanks :D
now it works fine :)