Actually this might not be a math operator problem but the system simply does not recognize at the new variable is numeric/integer (not string)
Item Select Command
RPG Maker MV SupportHi Guys
I have simple questions but still cannot solve it.
I wanted to add value to item (so need to numeric (aka number) not string) and use simple math for item
For example, I wanted to add value 1 to item A and value 2 to item B
and then use meta.value to operate
I put this in item A notetag <value:1> but when I use item A + (math) item B
it should be 3 (as math function) but I got 12
The problem I got was that JS doe not recognize <value:1> as numeric but string
As my programming exp, I realize this is just numeric/string problem but I am not JS expert
Is there a way to convert or call function to convert <value:1> to numeric ?
Probably someone has the way to assign numeric directly to item
Any suggestions are welcome, just wanted to brainstrom
I have simple questions but still cannot solve it.
I wanted to add value to item (so need to numeric (aka number) not string) and use simple math for item
For example, I wanted to add value 1 to item A and value 2 to item B
and then use meta.value to operate
I put this in item A notetag <value:1> but when I use item A + (math) item B
it should be 3 (as math function) but I got 12
The problem I got was that JS doe not recognize <value:1> as numeric but string
As my programming exp, I realize this is just numeric/string problem but I am not JS expert
Is there a way to convert or call function to convert <value:1> to numeric ?
Probably someone has the way to assign numeric directly to item
Any suggestions are welcome, just wanted to brainstrom
The problem is RPG Maker doesn't know that in <value:1> the "1" is supposed to be a number instead of a string.
Fortunately, you can easily convert numeric values from string to number by passing it to the Number() constructor, like this:
Be careful with booleans! If for some reason you need something like <value:false>, then Boolean("false") will give you true instead of false. The solution to that is to compare the value to "true" or "false", like this:
or this:
Fortunately, you can easily convert numeric values from string to number by passing it to the Number() constructor, like this:
Code:
Number(value)
Be careful with booleans! If for some reason you need something like <value:false>, then Boolean("false") will give you true instead of false. The solution to that is to compare the value to "true" or "false", like this:
Code:
value === "true"
Code:
value !== "false"
I tried it in notetag but did not work how can use in Number(")
Can I do like this ?
Number"($gameVariables.value(15)")
Can you show an example how to use this Number(")
Assuming you want to add the meta.value of item 65 and item 66 and save it into variable 15 (one-liner):
Or if you want something more easy to read and understand:
Code:
$gameVariables.setValue(15, Number($dataItems[65].meta.value) + Number($dataItems[66].meta.value));
Or if you want something more easy to read and understand:
Code:
const A = Number($dataItems[65].meta.value);
const B = Number($dataItems[66].meta.value);
$gameVariables.setValue(15, A + B);
@Charles2020 I merged your new post with this one, as it is still the same topic. Also, please do not double post. You can quote multiple posts in one reply by selecting the +Quote button for each post. In addition, you can tag someone as I've done in this post. Thanks.
Original thread: https://forums.rpgmakerweb.com/threads/item-select-command.125751/