|
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
|
07-19-2006 09:44
In the link_message and listen events, I often use "if"s to sort out various messages. In one case, I have a message that will come through once (sort of an initialization) and other messages that can come multiple times. Is there any appreciable difference which if statement might go first? That is, will it slow or bog things down if the script has to check the initialization "if" condition every time it gets another message passed? Or, short of changing states, is there anyway that the initialization check can be essentially eliminated? in more concrete terms: listen(channel,......) { if (channel == init_channel) //happens once {
} else if (channel == other_channel) //happens frequently {
} }
would it be any different to listen(channel,......) { if (channel == other_channel) //happens frequently {
} else if (channel == init_channel) //happens once {
} }
Thanks, Baron H.
|
|
Jade Bard
Registered User
Join date: 7 Jul 2004
Posts: 106
|
07-19-2006 09:58
Yeah i just started realizing this with my link messages as well. I would have like 7-8 if/else-if statements all in one, all you need to do is just have the number that comes in be a sortor. link_message ( integer sender_num , integer num , string str , key id ) { if ( num == 1 ) //most often { if ( str == "Blah" ) statement; else if ( str == "bleh" ) statement; } else if ( num == 2 ) //rarely { if ( str == "etc" ) statement; } }
Well i'm sure you get it, it's basically what he posted above. save lag, and do this 
|