Hey everyone!
I just made a custom evented Cooking Game, where the player can choose up to 8 items to put together to cook.
I do this by setting each Item chosen's ID# to 8 CookSlot variables, then I then put all 8 variables together in an array.
So far, everything's working out great!
BUT
I've run into an issue where I need to check this array of 8 values for any numbers in a specific range, but don't know how to do so.
For example:
all the meat items are ID# 51-59
and all the fish are ID# 61-69
and all the mushrooms are ID# 71-79
etc
So, I figured an easy way to check if the player's Ingredients array contained any fish, is to check if any values in the array contain a number between 60 and 70(because all fish items are between those numbers).
Then I can trigger a switch 'contains fish?' to ON or something.
Problem is, I can't seem to find an easy way of doing this!
-I can check if ONE value is inside the array with a conditional:
-And I can check if multiple values are inside an array:
^^But I can't figure out how to check if there's a number that falls between a specific range of numbers!
--
I've been looking around, and dug up some other ways people have done similar things, for example:
#1
(Explanation: It retrieves text from variable 1, extracts the first match of a four-digit number, and store it in variable 2.
Note that if it's not within range, it will return 0.)
forums.rpgmakerweb.com
-but I'm not sure how to get that to work with an array 🙁
=========================
#2
@caethyril also had something neat here as well:
(Explanation: "true iff the values of game variables 2, 3, 4, and 5 are all < the value of game variable 1".)
forums.rpgmakerweb.com
^^This one looks really promising, but again, not sure how to apply that to an array!
Can this be done? Can you search an entire array for any numbers between a certain range?
If I don't come up with something it'll get messy, because there's quite a few ranges I'll need to check, fish was just one example. (ie, check ranges to see if Contains: 'Fruit/Vegetables/Mushrooms/Berries/Spices/Dairy' etc!
I just made a custom evented Cooking Game, where the player can choose up to 8 items to put together to cook.
I do this by setting each Item chosen's ID# to 8 CookSlot variables, then I then put all 8 variables together in an array.
So far, everything's working out great!
BUT
I've run into an issue where I need to check this array of 8 values for any numbers in a specific range, but don't know how to do so.
For example:
all the meat items are ID# 51-59
and all the fish are ID# 61-69
and all the mushrooms are ID# 71-79
etc
So, I figured an easy way to check if the player's Ingredients array contained any fish, is to check if any values in the array contain a number between 60 and 70(because all fish items are between those numbers).
Then I can trigger a switch 'contains fish?' to ON or something.
Problem is, I can't seem to find an easy way of doing this!
-I can check if ONE value is inside the array with a conditional:
JavaScript:
$gameVariables.value(ArrayVarId).includes(61)
-And I can check if multiple values are inside an array:
JavaScript:
$gameVariables.value(ArrayVarId).includes(61) && $gameVariables.value(ArrayVarId).includes(62) && $gameVariables.value(ArrayVarId).includes(63) etc -it gets way too long aaaa
^^But I can't figure out how to check if there's a number that falls between a specific range of numbers!
--
I've been looking around, and dug up some other ways people have done similar things, for example:
#1
JavaScript:
var year = parseInt($gameVariables.value(1).match(/\d{4}/)[0]);
$gameVariables.setValue(2, (year>=1920 && year <= 2020) ? year : 0);
(Explanation: It retrieves text from variable 1, extracts the first match of a four-digit number, and store it in variable 2.
Note that if it's not within range, it will return 0.)
Check a range of numbers in a string
Hi there, I'm using a free input text plugin which can store a string in a variable. I need to check in script box of a conditional branch if in that string there is a numeric value in a range and, if there is, store it in another variable. In a more practical way it can be used for birthdays...
forums.rpgmakerweb.com
-but I'm not sure how to get that to work with an array 🙁
=========================
#2
@caethyril also had something neat here as well:
JavaScript:
const v = $gameVariables.value(1); [2,3,4,5].every(id => v >= $gameVariables.value(id))
(Explanation: "true iff the values of game variables 2, 3, 4, and 5 are all < the value of game variable 1".)
RMMZ - [Help] How to check: variable 1 is greater than multiple variables( 2, 3, 4, 5)
Hi guys! I want to put a condition where 1 variable is greater than others at once... something like $gameVariable.values >=== variable 1, 2 , 3 ,4...
forums.rpgmakerweb.com
^^This one looks really promising, but again, not sure how to apply that to an array!
Can this be done? Can you search an entire array for any numbers between a certain range?
If I don't come up with something it'll get messy, because there's quite a few ranges I'll need to check, fish was just one example. (ie, check ranges to see if Contains: 'Fruit/Vegetables/Mushrooms/Berries/Spices/Dairy' etc!