Whats wrong with that var declaration? |
Author: |
Message: |
SmashD
Junior Member
Posts: 50 Reputation: 1
Joined: Aug 2004
|
O.P. 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 |
|
|
mickael9
Full Member
Posts: 117 Reputation: 3
33 / /
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);
}
}
This post was edited on 08-17-2006 at 01:18 PM by mickael9.
|
|
08-17-2006 01:18 PM |
|
|
markee
Veteran Member
Posts: 1622 Reputation: 50
36 / /
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.
|
|
08-17-2006 01:24 PM |
|
|
SmashD
Junior Member
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 |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
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
This post was edited on 08-17-2006 at 02:26 PM by RaceProUK.
|
|
08-17-2006 02:24 PM |
|
|
markee
Veteran Member
Posts: 1622 Reputation: 50
36 / /
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
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.
|
|
08-17-2006 02:32 PM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
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.
|
|
08-17-2006 08:38 PM |
|
|
hmaster
Senior Member
Posts: 716 Reputation: 24
33 / /
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.
|
|
08-17-2006 08:44 PM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
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.
|
|
08-17-2006 08:48 PM |
|
|
hmaster
Senior Member
Posts: 716 Reputation: 24
33 / /
Joined: Nov 2004
|
RE: Whats wrong with that var declaration?
Oh! didn't know you could use it like that
|
|
08-17-2006 09:02 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|