say you're wanting to use a switch for picking a random number between 1-20
so you do
switch(1,20)
if(5 to 6)
blah blah blah
is this efficient?
compared to just doing this
proc/blah
var/randomnumber=rand(1,20)
if(randomnumber>=5 && randomnumber <=6)
????
is switch ok to use?
ID:268066
Mar 1 2004, 4:27 pm
|
|
In response to Yota
|
|
hmm well the problem is I'm going to be using one or the other quite a few hundred times throughout the game... and lately I've been having problems with code that I was thinking might relate to switch so I was hoping someone would post something about what to do and what not to do with switch lol :)
|
In response to Jon Snow
|
|
OK. switch has only one paramiter.
switch(val)
Next, the following block are all if() (and maybe an else at the end) statements. switch(val) switch(val) |
In response to Jon Snow
|
|
if(rand(1,20) <= 5)
This doesn't require a variable to be called, you can use less code by excusing the switch statement and the preceding if statements, and it checks the value too. The only problem is that you can't check more than one value. For example. This would not work. if(rand(1,20) == 5 || 6) In order for that to work you would have to define a variable. var/rand = rand(1,20) if(rand == 5 || rand == 6) |
Considering that would crash the procedure, I'd say the latter is more efficient.
If you ment 'switch(rand(1,20))', then I'm not sure. Declaring a variablt, setting, and checking? Or the way 'switch' is been programmed. If I've seen BYOND's source code I could give you a direct answer.
Try a check like this...