Performance question about simulating AND/OR with conditional branches

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,532
Reaction score
10,976
First Language
English
Primarily Uses
RMMV
Since JavaScript conditional statements don't only exist in script commands (you'll find plenty of them in the core scripts or in plugins), I considered the additional overhead associated with using script commands to be outside the scope of my statement.
Okay, cool - so I either misunderstood you, the OP, or both :guffaw:

When they first asked
i am trying to figure out if is better to simulate AND/OR with conditional branches or better to just script it
I read that as putting code including AND/OR operators into the conditional branch's Script field, as opposed to actually nesting conditional branches or using their Else branch.

If the conversation actually veered outside of using an event entirely and just putting the code directly into a plugin, I think both myself and Aqua missed it.
 

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,224
Reaction score
1,884
First Language
English
Primarily Uses
RMMZ
Okay, cool - so I either misunderstood you, the OP, or both :guffaw:

When they first asked

I read that as putting code including AND/OR operators into the conditional branch's Script field, as opposed to actually nesting conditional branches or using their Else branch.

If the conversation actually veered outside of using an event entirely and just putting the code directly into a plugin, I think both myself and Aqua missed it.
Yeah, your understanding of the OP's question makes more sense. I think I probably didn't pay good enough attention. I was too focused on my desire to share my array shuffling idea, and just jumped in and started saying stuff. Sorry, folks.
 
Last edited:

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
425
Reaction score
259
First Language
EN/JP/NL
Primarily Uses
RMMZ
You can also start with

JavaScript:
let nums = Array.from({length: 101}, (value, key) => key + 1);
Okay this is very off-topic, but why is it that passing (value, key) instead of just (key) allows you to successfully populate the array? I don't understand why

Array.from([0,1,2,3,4, all the way to 100], (x) => x + 1)

works, but

Array.from(Array(101), (x) => x + 1)

does not...

EDIT: it was the other way round lol
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,532
Reaction score
10,976
First Language
English
Primarily Uses
RMMV
Okay this is very off-topic, but why is it that passing (value, key) instead of just (key) allows you to successfully populate the array?
I'm not sure whether your edit means you figured it out, or that you're still confused but your examples are backwards :wink:

Per the documentation of some(), the second argument is a map function called on each element:

Similarly, per the documentation of map(), the first argument is simply the current value of the given element:

If you simply call Array(101), each of those 101 elements are undefined. So only passing one argument into the map function will reference their current value, produce undefined + 1 and all math in JavaScript with undefined produces NaN.

1696226466570.png

The second argument of map(), however, is the current index of the given element, and that must be a value. So you can perform math on the index (what Trihan labeled key) to produce a value for the elements of the array.

1696226589941.png

In your example where you actually initialized the values of the array elements manually ( [0, 1, 2, 3, etc.] ) only passing the first argument into map() has a defined value to work with. But in that case the whole thing is kind of pointless because what Trihan provided was a shorthand to initialize the values of a large array without typing it out.
 

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
425
Reaction score
259
First Language
EN/JP/NL
Primarily Uses
RMMZ
Thanks as always! The realization that the mapping portion was a function was missing from my brain. This is so cool, thanks!
 

gstv87

Regular
Regular
Joined
Oct 20, 2015
Messages
3,361
Reaction score
2,555
First Language
Spanish
Primarily Uses
RMVXA
@ATT_Turan like I said, all things being equal, conversion done and all, comparing two variables requires the processor to make one additional loop to load both operands to it's own registry, in contrast to "write [this] to [this address]".
I don't remember my CPU-Fu all that well, but I believe those writings happen in parallel (all bits at the same time) while *looking for a number* is sequential (going up or down the table one position at a time)
still... even if it was [bus size] X [number of operands] X [bit actions], we're talking hundreds or thousands of operations, in a structure that handles millions to hundreds of millions per second.
it's not gonna make a difference.
 

Latest Threads

Latest Posts

Latest Profile Posts

image.png

Baldur's Gate 3 got a little bit too real there
Albert.png
You're welcome! Fly in, take Albert in my style
The flight sim I've bought has some amazing priorities.
If I land with one wheel slightly off the runway, but it's an otherwise fine landing, it doesn't count. But if I touch down on the runway so hard it makes me bounce back into the air and crash in the next 10 seconds, as long as it's on the runway, it's a successful landing.
Mike Final Breaker.png
that time I drew Mike doing Hugo from Street Fighter 3's Shootdown Backbreaker...

Forum statistics

Threads
136,638
Messages
1,268,285
Members
180,324
Latest member
Flamedro
Top