If Script, Between this and that! [Solved]

Hi everyone! Sorry to bug you guys with a silly question (which I'm pretty sure is impossible) but is it possible to create a code that says number between "this and that"? For example,

if (player.skill 0>=<2 ) {
msg ("")
}
else if (player.skill 3>=<5) {
msg ("")
}

I know it probably isn't but I'm just curious if there is a trick I could pull off :) Thank you very much for you time!

Anonynn.


if (player.skill <=2 will check for all the numbers that are 2 and below

if the number isn't 0, 1, or 2, it'll move on to the first else:

if (player.skill <=5 since it wasn't 0, 1 or 2, now it checks to see if it's 3, 4 or 5 (actually, it also checks to see if it's 0, 1 or 2, but your code previously determined that it isn't - or we wouldn't be here)

and if it's something other than than0 - 5, it moves on to the second else

so
if (player.skill <=2) {msg("")}
else
if (player.skill <=5){msg("")}
else
{msg("skill out of range")}


if (player.skill >= 0 and player.skill <= 2 ) {
msg ("newbie")
}
else if (player.skill >= 3 and player.skill <= 5) {
msg ("veteran")
}

Although CrystalWiz's way is more elegant.


I was actually just trying to find a way of reducing the code. This was what I had...

if (player.meditskill <=3) {
}
else if (player.meditskill = 4)
}
else if (player.meditskill = 5)
}
else if (player.meditskill = 6)
}
else if (player.meditskill = 7)
}
else if (player.meditskill = 8)
}
else if (player.meditskill = 9)
}
else if (player.meditskill = 10)
}

But Dcoder's way saves code length! Thank you both of you. :) This is what I was aiming for.

if (player.meditskill >=0 and player.meditskill <=3) {
}
else if ( player.meditskill >=4 and player.meditskill <=6)
}
else if ( player.meditskill >=7 and player.meditskill <=9)
}
else if ( player.meditskill =10)
}

Thanks again!


it is possible, the trick is that you have to use 'and' to join the complete statements/expressions for each of the two conditions (the requirement of complete statements/expressions for both conditions is what trips up most people) in quest:

// including (being inside of) a range:

if (player.skill >= 0 and player.skill <= 2 ) { // did you want this: 0 < x < 2, or this: 0 <= x <= 2, ???
msg ("")
}
else if (player.skill >= 3 and player.skill <= 5) {
msg ("")
}

// and the same for excluding (being outside of) a range:

if (player.skill < 0 and player.skill > 2 ) {
msg ("")
}
else if (player.skill < 3 and player.skill > 5) {
msg ("")
}

@ Anonynn:

for this:

if (player.meditskill >=0 and player.meditskill <=3) {
}
else if ( player.meditskill >=4 and player.meditskill <=6)
}
else if ( player.meditskill >=7 and player.meditskill <=9)
}
else if ( player.meditskill =10)
}

it's not that a big of a deal likely for what you're doing, but there's still some unneccessary operations, we can make it even better, like this:

// high to low:

if (player.meditskill > 9) { // or the same operations (if value will never go above 10): if (player.meditskill = 10) { // or a bit more operations but much more human convenient (if value can/will go above 10): if (player.meditskill => 10) {
}
else if (player.meditskill > 6) { // or a bit more operations but much more human convenient: if (player.meditskill >= 7) {
}
else if (player.meditskill > 3) { // or a bit more operations but much more human convenient: if (player.meditskill >= 4) {
}
else if (player.meditskill > -1) { // or a bit more operations but much more human convenient: if (player.meditskill >= 0) {
}

// or, low to high:

if (player.meditskill < 4) { // or a bit more operations but much more human convenient: if (player.meditskill <= 3) {
}
else if (player.meditskill < 7) { // or a bit more operations but much more human convenient: if (player.meditskill <= 6) {
}
else if (player.meditskill < 10) { // or a bit more operations but much more human convenient: if (player.meditskill <= 9) {
}
else { // the 'else' is the same effect as: else if (player.meditskill >= 10) {, so use the 'else' unless for whatever reason, you HAVE to use the 'else if' for some reason...
}

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums