GML Can I shorten this statement to one line?

Dr_Nomz

Member
Code:
  if scr_Info_Quest_Name(ds_list_find_value(global.quest_list,qu)) >= 1 &&
  scr_Info_Quest_Name(ds_list_find_value(global.quest_list,qu)) != 100 &&
  scr_Info_Quest_Name(ds_list_find_value(global.quest_list,qu)) != -1
Like, if I can just say if it's NOT 100 or -1 in the same line. Like if variable != -1 || 100
 

samspade

Member
There are a couple things you can do. First, assuming the script itself can't return a different number you could save the result in advance like this:

Code:
var value = scr_Info_Quest_Name(ds_list_find_value(global.quest_list,qu);
if (value >= 1) && (value != 100) && (value != -1) {
    //do thing
}
That is better already. You also don't need to check for -1 if you've already confirmed it is >= 1. So it can be:

Code:
var value = scr_Info_Quest_Name(ds_list_find_value(global.quest_list,qu);
if (value >= 1) && (value != 100) {
    //do thing
}
But no, you cannot do this: value != -1 || 100. (and even if that syntax was allowed it wouldn't be equivalent to your current check).
 

johnwo

Member
It's kinda unclear what this code is supposed to do.
Is it supposed to check if a value x is (x>=1 && x!=100), or check if x is within a certain range?
If it's the former, then @samspade's post is describes the best option; if it's the latter then you could do this:
Code:
var value = scr_Info_Quest_Name(ds_list_find_value(global.quest_list,qu);
var xx = 3;
var yy = 41;
if (value == clamp(value,xx,yy)) {
    // Variable "value" is such that xx <= value <= yy
}
 
Last edited:

TheouAegis

Member
if abs(scr_Info_Quest_Name(ds_list_find_value(global.quest_list,qu) - 50) < 50


As long as it can't return a value like 0.1, then that should work. lol
 

CloseRange

Member
I mean, you could just create a script and have it return true or false :)
honestly though, I like the idea of using floor(val / 100) == 0:
Code:
var value = sc_Info_Quest....
if(floor(value /100) == 0) {

}
i'd say use div because it's simpler but it doesn't work too well with negatives.
 

TheouAegis

Member
I mean, you could just create a script and have it return true or false :)
honestly though, I like the idea of using floor(val / 100) == 0:
Code:
var value = sc_Info_Quest....
if(floor(value /100) == 0) {

}
i'd say use div because it's simpler but it doesn't work too well with negatives.
Except in his code he doesn't want zero.

floor((val+1)/100)

Or floor((floor(val)+1)/100)
 
Top