What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Whats wrong with that var declaration?

Pages: (2): « First [ 1 ] 2 » Last »
Whats wrong with that var declaration?
Author: Message:
SmashD
Junior Member
**

Avatar

Posts: 50
Reputation: 1
Joined: Aug 2004
O.P. Huh?  Whats wrong with that var declaration?
code:
function OnEvent_Timer(slider){
if (Messenger.MyStatus == 3){
var x_img = x_img + 1;
if(x_img == 1) {
Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online2.jpg";
}
else if(x_img == 2)
{
Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online3.jpg";
}
else if(x_img == 3)
{
Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online4.jpg";
}
else if(x_img == 4)
{
Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online.jpg";
var x_img = 0;
}
  MsgPlus.AddTimer("slider", 20000);
  return Message; 
}
}

It's triggered by an AddTimer - works nicely, but I am unable to figure out why the x_img variable isn't correct... :(
08-17-2006 01:12 PM
Profile E-Mail PM Find Quote Report
mickael9
Full Member
***


Posts: 117
Reputation: 3
33 / Male / Flag
Joined: Jul 2005
RE: Whats wrong with that var declaration?
code:
var x_img = 0;

function OnEvent_Timer(sTimerId)
{
    if (sTimerId == "slider" && Messenger.MyStatus == 3)
    {
        x_img++;
       
        if(x_img == 1)
        {
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online2.jpg";
        }
        else if(x_img == 2)
        {
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online3.jpg";
        }
        else if(x_img == 3)
        {
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online4.jpg";
        }
        else if(x_img == 4)
        {
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online.jpg";
            x_img = 0;
        }
        MsgPlus.AddTimer("slider", 20000);
    }
}
:D

This post was edited on 08-17-2006 at 01:18 PM by mickael9.
08-17-2006 01:18 PM
Profile PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Whats wrong with that var declaration?
code:
var x_img = 0; //set x_img as a global variable

function OnEvent_Timer(sTimerId) //sTimerId is a variable not what timer is being initiated
{
    if (sTimerId == "slider" && Messenger.MyStatus == 3)//make sure it is the right timer being initiated AND the status you wanted
    {
        x_img++;//add 1 to x_img
       
        if(x_img == 1)
        {
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online2.jpg";
        }
        else if(x_img == 2)//used "else if" as this links if statements and only oe can be true
        {
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online3.jpg";
        }
        else if(x_img == 3)
        {
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online4.jpg";
        }
        else if(x_img == 4)
        {
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online.jpg";
            x_img = 0;
        }
        MsgPlus.AddTimer("slider", 20000);
    }
}
I added some note so you can understand the changes that have been made by mickael9.  I hope this gives you more understanding of what is happening.
[Image: markee.png]
08-17-2006 01:24 PM
Profile PM Find Quote Report
SmashD
Junior Member
**

Avatar

Posts: 50
Reputation: 1
Joined: Aug 2004
O.P. RE: Whats wrong with that var declaration?
Oh, it's more like PHP than I guessed. Just fiddling around with that scripting since some minutes. Thanks, I'll try and report if that works.

EDIT: Works like a charm. Thanks alot.

EDIT2: Oh, one important thing. Once the timer event is fired the timer does not exist any longer, so I have to start a new one, right?
Of course I don't want to fill up my system with timers after some time. hehe

This post was edited on 08-17-2006 at 01:37 PM by SmashD.
08-17-2006 01:28 PM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Whats wrong with that var declaration?
code:
var x_img = 1;

function OnEvent_Timer(sTimerId) {
    if (sTimerId == "slider" && Messenger.MyStatus == 3){
        x_img++;
        if (x_img == 4) {
            x_img = 0;
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online.jpg";
        }
        else Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online" + x_img + ".jpg";
        MsgPlus.AddTimer("slider", 20000);
    }
}

Edit: Don't hate me because I streamline code :P

This post was edited on 08-17-2006 at 02:26 PM by RaceProUK.
[Image: spartaafk.png]
08-17-2006 02:24 PM
Profile PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Whats wrong with that var declaration?
quote:
Originally posted by RaceProUK
code:
var x_img = 1;

function OnEvent_Timer(sTimerId) {
    if (sTimerId == "slider" && Messenger.MyStatus == 3){
        x_img++;
        if (x_img == 4) {
            x_img = 0;
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online.jpg";
        }
        else Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online" + x_img + ".jpg";
        MsgPlus.AddTimer("slider", 20000);
    }
}

Edit: Don't hate me because I streamline code :P
That won't give what he was after, you will miss x_img = 1 at the begining.  Either make "var x_img = 0;" at the top or put "x_img++;" in the line after "MsgPlus.AddTimer("Slider",20000);" rather than where it is atm.
[Image: markee.png]
08-17-2006 02:32 PM
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Whats wrong with that var declaration?
quote:
Originally posted by markee
you will miss x_img = 1 at the begining
Oh boo-hoo. I only streamlined the code to show a few tricks.
[Image: spartaafk.png]
08-17-2006 08:38 PM
Profile PM Web Find Quote Report
hmaster
Senior Member
****

Avatar

Posts: 716
Reputation: 24
33 / Male / Flag
Joined: Nov 2004
RE: Whats wrong with that var declaration?
quote:
Originally posted by RaceProUK
code:
var x_img = 1;

function OnEvent_Timer(sTimerId) {
    if (sTimerId == "slider" && Messenger.MyStatus == 3){
        x_img++;
        if (x_img == 4) {
            x_img = 0;
            Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online.jpg";
        }
        else { Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\online" + x_img + ".jpg";
        MsgPlus.AddTimer("slider", 20000);
        }
    }
}
Edit: Don't hate me because I streamline code
Just to let you know if you are going to use that theres a missing '{'

This post was edited on 08-17-2006 at 09:03 PM by hmaster.
[Image: sig.png]
08-17-2006 08:44 PM
Profile PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Whats wrong with that var declaration?
quote:
Originally posted by hmaster
Just to let you know if you are going to use that theres a missing '{'
I assure you there isn't: I checked. The brace you added will not only change how the script works, but also break it totally.

I use indenting to pair up braces. In fact, I usually write both the opening and closing braces befor I write the statements inside. That way I rarely drop a brace.

I drop parentheses a fair bit though.

This post was edited on 08-17-2006 at 08:50 PM by RaceProUK.
[Image: spartaafk.png]
08-17-2006 08:48 PM
Profile PM Web Find Quote Report
hmaster
Senior Member
****

Avatar

Posts: 716
Reputation: 24
33 / Male / Flag
Joined: Nov 2004
RE: Whats wrong with that var declaration?
Oh! didn't know you could use it like that (Y)
[Image: sig.png]
08-17-2006 09:02 PM
Profile PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On