Need help with calculation in variable

Sorry it's me again. In short:
I want a calculation that checks in a conditional branch if stealing an item will work. it should be based on the luk of a party member (here leader).
Thats the calculation I found on the internet, and I liked it, but somehow the maker always can't calculate it and gives 0 as an answer.

JavaScript:
rand(100) <= $gameVariables.value(30) + $gameParty.members()[0].luk * ( ( 100 - $gameVariables.value(30) ) / 100 )

V(30) - supposed to be how hard it is to steal (lets say its 60, so it should be little more than 50/50 chance, without your luk)
My max Luk should be 100

If I try it with V(30) and 100 Luk, it always brings up 0 and I don't know if its just an writing error or something like this.

Or maby someone has another suggestion how I could calculate if the player could steal an item depending on ther luk-STAT and how hard it is in general.
what is the outcome in the console log if you use that math?
than we can see how to fix it and where or how to adjust it.

my guess is to change the variable 30 this way.
Use Math.randomInt(100) (random integer 0~99) instead of rand(100).
what is the outcome in the console log if you use that math?
than we can see how to fix it and where or how to adjust it.

my guess is to change the variable 30 this way.

Its says
"$gameParty.leader().luk * ( ( 100 - $gameVariables.value(30) ) / 100 )
ReferenceError: rand is not defined"

@caethyril
if I use that instead, it also shows 0 and the dev console says nothing about that
1) can you give a screenshot of how exactly you entered the condition into the event and how you used it?

2) just as a test - use a series of control variable to calculate the result instead of using script, and then check against the randomizer of control variable instead of the script.
That is to make sure the values are what you think they are and not some other problems.
than you know that "rand" is not defined as a function, so the outcome cannot be declared.
so you could also make a variable 0...99 at random if you want to use it there.

so you could control this in the stealth as well 🙂
1) can you give a screenshot of how exactly you entered the condition into the event and how you used it?

2) just as a test - use a series of control variable to calculate the result instead of using script, and then check against the randomizer of control variable instead of the script.
That is to make sure the values are what you think they are and not some other problems.
1) Sure here is the screenshot
1697318656416.png


2) I tried that, and it also was the same problem and I didn't understand how..
Maybe I should just try another calculation... something simplier that I can understand myself.

than you know that "rand" is not defined as a function, so the outcome cannot be declared.
so you could also make a variable 0...99 at random if you want to use it there.

so you could control this in the stealth as well 🙂
I tried that, but didn't helped... but I will try again, I guesse. Maybe I changed something important. My brain isn't working to well.
Also will try finding another more easy calculation
and it also was the same problem
no, it cannot be because you would not use any script, just a series of control variable mathematical operations.
if you used any script line then you did the test wrong - because it was supposed to be a test of the mathematics, not of the script functions.

please try again, using only addition, multiplication and division of the control variable (and one game data to get the luck)
Maybe I should just try another calculation... something simplier
Yes, always start with something easy!

However, it seems OK for me. Here's what I used to test it, checking the value at each stage of the arithmetic:
Spoiler: click to see event text
◆Control Variables:#0031 Check = 100 ◆Control Variables:#0031 Check -= #0030 Difficulty ◆Text:None, Window, Bottom : :100 - var 30 is \v[31] ◆Control Variables:#0031 Check *= $gameParty.leader().luk ◆Text:None, Window, Bottom : :Multiplied by party leader's luck is \v[31] ◆Control Variables:#0031 Check /= 100 ◆Text:None, Window, Bottom : :Divided by 100 is \v[31] ◆Control Variables:#0031 Check += #0030 Difficulty ◆Text:None, Window, Bottom : :Plus var 30 is \v[31] ◆Control Variables:#0031 Check -= Random 0..99 ◆Text:None, Window, Bottom : :Minus random number 0~99 is \v[31] ◆If:#0031 Check ≥ 0 ◆Text:None, Window, Bottom : :Success! ◆ :Else ◆Text:None, Window, Bottom : :Fail. ◆ :End
($gameParty.leader() is just a shorthand for $gameParty.members()[0], unless you're using some plugin that changes how the party leader is assigned.)
@caethyril
if I use that instead, it also shows 0 and the dev console says nothing about that

What do you mean exactly when you say "it shows 0"? the line of code in question returns a boolean value (true or false), it can't possibly return 0.

Also I noticed you're using another condition above that with what I assume is a self variable plugin? make sure you're using that correctly as well, otherwise variable 19 will be equal to 0 and maybe that's the 0 you're seeing.
I found a problem I guesse, as I tried again making calculating everything step by step only with variables.
It seems as soon as the variable should hold something like 0,4 it just make it to = 0
so everything turns 0...

has somebody an idea of how I do that? Maybe that it calculates with 0,4 or how to come around that?
Unbenannt-1.jpg

screenshot of my try what went wrong. At this All of it above is working, but the last part V[29] / 100 =0,4
and everythings goes 0

I also tried, if a script would calculate with it, but it seems it don't
JavaScript:
$gameVariables.value(30) + $gameParty.members()[0].luk * ( ( 100 - $gameVariables.value(30) ) / 100 )
Unbenannt-1.jpg
RMMV's game variables use integer arithmetic: when a number is stored in a variable, it floors that number to an integer. This is a deliberate choice, for precision. JavaScript (like many general-purpose programming languages) uses the IEEE 754 standard for representing floating-point numbers, which has interesting quirks like 0.1 + 0.2 = 0.30000000000000004.

Typically you would just scale everything up to the precision you need, e.g. multiply everything, including the random roll, by 1000 (3 decimal places). 👋
RMMV's game variables use integer arithmetic: when a number is stored in a variable, it floors that number to an integer. This is a deliberate choice, for precision. JavaScript (like many general-purpose programming languages) uses the IEEE 754 standard for representing floating-point numbers, which has interesting quirks like 0.1 + 0.2 = 0.30000000000000004.

Typically you would just scale everything up to the precision you need, e.g. multiply everything, including the random roll, by 1000 (3 decimal places). 👋

I didn't really understood what you said about the programming, but I DO understood that the solution can be that simple.
I will try just multiplying everything ^^
I didn't really understood what you said about the programming,
it has less to do with programming and more with how the computer stores numbers.

You might have heard or read somewhere "1 kilobyte are 1024 bytes" despite the human conventions like "1 kilogram are 1000 gram".
That is because the computer has to use 1024 where the human would use 1000 - the 1000 is actually a very complex number for the computer where the easy number for it to use is the 1024.

And that difference creates rounding errors - where we round to multiples of 1000, the computer will round to multiples of 1024, and forcing integers (full numbers) is one way to prevent rounding errors.
But that only works if you know that forced rounding exists...

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-calculation-in-variable.162013/