Performance question about simulating AND/OR with conditional branches

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,675
Reaction score
11,194
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,243
Reaction score
1,929
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
436
Reaction score
262
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,675
Reaction score
11,194
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
436
Reaction score
262
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,367
Reaction score
2,567
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 Profile Posts

Me working on a deadline, "don't make the baseline and chords too funky, don't over compose it... remember, you have to finish it." Touches MIDI controller...instant funk.
TGA are coming up, and I'm still mad Lies of P didn't get nominated.
Like, they chose a remake of a 20 year old game and a vanilla 2D Mario game over it?

Bah, humbug!
I'll be there for the trailers and whatever weird mistakes are made.
I've bundled all my free plugin releases on itch.io I'll add more later, feel free to check it out! https://starlit.itch.io/rm-free-plugins
If I could draw, my Game Jam title screen would be a Krampus sitting in Santa's chair, his long, blonde hair flowing in the wind, sipping on an Espresso, while snacking on cheddar popcorn, chewing on an orange pencil pensively, while completing a crossword puzzle. I guess it's a good thing I can't draw.
Time for the next chance for y'all to affect my advent calendar! Where should Day 7's sprite come from: land, sea, or demon realm? :rwink:

Forum statistics

Threads
136,782
Messages
1,269,921
Members
180,532
Latest member
jorddy
Top