(noobie coding) explain array in a simpler way

(noob at maths) i find this thing confusing and need help on how to use it
Ruby compiler online over here --> https://repl.it/languages/ruby
Copy-paste these codes, then hit run.

Example array #1
Code:
a = [23,45,34,45,11]
puts a[0] # <-- this print 23
puts a[2] # <-- this print 34

Example array #2
Code:
a = [23,45,34,45,11]
puts a[0] - 20 # <-- this print 3
puts a[2] - 20 # <-- this print 14

What part of this code you don't understand?
Moved to: Learning Ruby and RGSSx
What are you trying to use it for?
Moved to: Learning Ruby and RGSSx
What are you trying to use it for?
trying to make my own item drop chance system
Does my explanation help at all?
Or should I abandon this thread since you're not responding to my reply?
@NoPiessadface you need to give us more details before we can help.
more specifically, what your problem with array is and what exactly you don't understand with them.

basically arrays are tables. you have rows and columns, and row titles and column titles (which are both numbers).
you tell the array the row and column of a certain box in that table, and it will return the contents of that box.

that is the most basic description of an array, and everything else depends on what you're using the array for. it can be as simple having a postbox for a number on a hotel room, or as complex as the adressing of where a book has to be placed on a shelf in a library to be able to find it again.
but we can neither tell you to use a complex or simple system without you giving us details like what you want to do with it.

"drop chance system" can be done in dozens of different ways - dou you want to read one array per enemy from its notetags or do you want an universal system in a plugin that handles everything in a single array? and in the last case how do you want to adress which enemy has data where?
all possible with arrays, but requiring completely different solutions.
Does my explanation help at all?
Or should I abandon this thread since you're not responding to my reply?
yeah it did but i heard that item drop chance system uses arrays and i need to know more of it

@NoPiessadface you need to give us more details before we can help.
more specifically, what your problem with array is and what exactly you don't understand with them.

basically arrays are tables. you have rows and columns, and row titles and column titles (which are both numbers).
you tell the array the row and column of a certain box in that table, and it will return the contents of that box.

that is the most basic description of an array, and everything else depends on what you're using the array for. it can be as simple having a postbox for a number on a hotel room, or as complex as the adressing of where a book has to be placed on a shelf in a library to be able to find it again.
but we can neither tell you to use a complex or simple system without you giving us details like what you want to do with it.

"drop chance system" can be done in dozens of different ways - dou you want to read one array per enemy from its notetags or do you want an universal system in a plugin that handles everything in a single array? and in the last case how do you want to adress which enemy has data where?
all possible with arrays, but requiring completely different solutions.
i want to know how this randomized item drop by percentage system works and i want someone to explain it with an example code
yeah it did but i heard that item drop chance system uses arrays and i need to know more of it
i want to know how this randomized item drop by percentage system works
that has nothing to do with arrays - arrays are just a form of data storage, nothing more.
the item drop would be the programming part, the array just a way to store the data for the item drops.

and if you don't know that difference, then your skills in programming are low beginner, with no chance of using that info before you learn more about programming.

If you have a specific, existing item drop system to link then we can explain to you how that one works.
but it is impossible for you to build such a system from scratch at your current knowledge level, and you'll need to learn programming before you can even start to understand how to design an array for use in a program.
that has nothing to do with arrays - arrays are just a form of data storage, nothing more.
the item drop would be the programming part, the array just a way to store the data for the item drops.

and if you don't know that difference, then your skills in programming are low beginner, with no chance of using that info before you learn more about programming.

If you have a specific, existing item drop system to link then we can explain to you how that one works.
but it is impossible for you to build such a system from scratch at your current knowledge level, and you'll need to learn programming before you can even start to understand how to design an array for use in a program.
yeah i never touched programming languages before i only know visual programming like scratch

so heres the link of this item drop loot im studying:

and what is your problem with those?
as I said above "array" is nothing other than the computer speak for "table" (just that a table is always two-dimensional while array can have more dimensions than 2). And the tables in that tutorial are rather simple representations that can be read easily.

so what is your problem with those tables? please ask specific questions if we are to help.
yeah it did but i heard that item drop chance system uses arrays and i need to know more of it
You want to know the array or you want to know how to manipulate item drop?
If you want to learn what an is an array, drop your idea of how to manipulate item drop.

I already gave you the simplest form of "what is an array".
Do you get the idea of what my code does?
and what is your problem with those?
as I said above "array" is nothing other than the computer speak for "table" (just that a table is always two-dimensional while array can have more dimensions than 2). And the tables in that tutorial are rather simple representations that can be read easily.

so what is your problem with those tables? please ask specific questions if we are to help.

so to create that system :
*you need to create a variable called "roll" and set it to a random value of 100 = means the max percentage
*create arguments called item1(for the rare item) and item2(for the common item)
and create an array and put the arguments like:
Code:
array = [item1, item2]
then the arguments above are the rarity so example:
item1 = 10
item2 = 90
so that means
array[0] = 10% drop chance
array[1] = 90% drop chance

so if the monster is killed:

if roll >= array[0] then reward the rare item
else if roll <= array[1] then reward the common

am i doing it right?

mine's not too advanced enough

edit:
but yeah theres nothing to do with it -_- i could just replace the array with the arguments

edit2:
but one heck of a problem it won't drop the item sometimes
HELP ANDAR
Ruby:
  #--------------------------------------------------------------------------
  # * Gathering
  #--------------------------------------------------------------------------
  def gather( rare_item, chance1, common_item, chance2)
   
    roll = rand(100)
   
    if roll >= chance1
      $game_message.add("#{$data_items[rare_item].name} obtained ")
      $game_party.gain_item($data_items[common_item], 1)
     
    elsif roll <= chance2
      $game_message.add("#{$data_items[common_item].name} obtained ")
      $game_party.gain_item($data_items[common_item], 1)
     
    end
  end
here's the code

man it's hard to see it, it would have been better if it has a color support
but one heck of a problem it won't drop the item sometimes
that depends on how you use the percentages and has nothing to do with the arrays themselves. And you mixed up several things about that in your example, including when to check for what values.

I once wrote a blogpost about weight mathematics, that is the first step of what you need for item tables - trying to use percentage mathematics on those tables is a losing proposition.
The blog itself does no longer exist, but someone worked to save my old posts, and I have linked that in my signature. Please follow that link and then to "weight calculations".
That is the first part you need to understand.

after that check any code that uses weight calculation on a randomizer - for example the encounter randomizer in the RM engine - and take especially a good look on the use of <, <=, > and >= because that is where you messed up in your post above.
The rare item should be dropped on roll <= 10%, not on >= as you wrote.
and the "no drop" is because you had the common item drop only on <90% instead of <(10+90)%. because of course there is a 10% chance of "no drop" if you have the no output on rolls of 91-100...
You don't want to learn what is an array, you want to learn how to make a drop table.
And since you keep ignoring my post, then I will bail out from here.

But, I will drop something useful.
since you keep ignoring my post
It's almost like he has you on ignore and can't see your posts. That's sad.

*edit
You could probably rework that a bit better since you always want a drop and there is only two items.
Ruby:
  #--------------------------------------------------------------------------
  # * Gathering #gather(51, 15, 2)
  #--------------------------------------------------------------------------
  def gather(rare_item, chance, common_item)
    roll = rand(100)
    if roll <= chance
      $game_message.add("#{$data_items[rare_item].name} obtained ")
      $game_party.gain_item($data_items[rare_item], 1)
    else
      $game_message.add("#{$data_items[common_item].name} obtained ")
      $game_party.gain_item($data_items[common_item], 1)
    end
  end
The simplest non-coding explanation for an array would be:
"An array is just an ordered list of data."

Andar said it's a table, but given how the Array class works in Ruby, it can't really be called as a "table" per say, because a table is at least a 2 dimensional "array" (we actually have a Table class in Ruby, that is what Andar's description fits for), but an array, as in an object with the Array class itself, is a one-dimensional "table", which is basically just a simple ordered list.

Spoiler
Code:
# As you can see, it's just a simple list of elements between the [brackets].
array = [element_0, element_1, element_2, ... , element_N]

# To get an element from that list, you need to use its index number.
# The index of an element is basically just the element's place in the ordering.
# But do note that the index numbering starts from 0 and NOT from 1!

# For example, if you want to get the 1st element from that array above:
item = array[0]
# This will set the item variable to the 1st element from that array.
# After this, whenever you use item below this line, it will always get
# the 1st item from that array.
# Note that changing the 1st element in the array itself later will NOT
# automatically change the item variable!

# You can also change the elements in an array:
array[2] = new_element_2
# This will replace the 3rd element in the array (element_2) with the
# new value you set to it (new_element_2)

# To iterate all elements in an array:
array.each {|item| * do your code here * }
# Or:
array.each do |item|
  # Do your code here
end
# Or if you need the index of the elements in the iteration:
array.each_with_index {|item,index| * do your code here * }
# And the 2nd format:
array.each_with_index do |item,index|
  # Do your code here
end
#--------
# When I started coding, I was confused what exactly that item
# and index meant between the || signs, because it always had a
# different name.
# To put it simply, you can name those however you want, and
# whenever you use them in the iteration itself (NOT outside of
# them!), they will refer to the same thing:
# item - The current array element of the iteration
# index - The current index of the element in the iteration

# There are many more useful methods you can use with arrays,
# but these are the most basic ones that you absolutely must
# understand to use arrays properly.

This is how you explain the basics of an array for a newbie coder eager to learn, not just by posting some examples without any context.

Also, weighted randomization is not really necessary for making a random item drop system, and based on how you want to randomize your items and setup the chance to get them, you might be better off using a hash instead of an array.
A hash is basically the same as an array, but instead of strictly using numbers as indexes, you can name the index of the elements in the list however you want.

Spoiler
Code:
items = {
  item1 => [0,9],   # 10% chance
  item2 => [10,29], # 20% chance
  item3 => [30,79], # 50% chance
}

# Note that the above list misses 20%.
# That will be the chance of getting no item at all.

roll = rand(100) # Random roll
rand_item = items.find {|item, chance| roll.between?(*chance) }
if rand_item # There is an item dropped
  # Gain item code here
else # No item dropped
  # Do whatever here when there is no item rolled
end

# This is just the most basic example of how it can be done.
# If your list needs more than 100 for the random roll,
# you can always just increase the random roll's value
# and add more items on the list based on the available
# values of the random roll used.

Would love to go on with other possible randomization ways, but I have to go now.
It's almost like he has you on ignore and can't see your posts. That's sad.

*edit
You could probably rework that a bit better since you always want a drop and there is only two items.
Ruby:
  #--------------------------------------------------------------------------
  # * Gathering #gather(51, 15, 2)
  #--------------------------------------------------------------------------
  def gather(rare_item, chance, common_item)
    roll = rand(100)
    if roll <= chance
      $game_message.add("#{$data_items[rare_item].name} obtained ")
      $game_party.gain_item($data_items[rare_item], 1)
    else
      $game_message.add("#{$data_items[common_item].name} obtained ")
      $game_party.gain_item($data_items[common_item], 1)
    end
  end
i just want my game to be simple thats all
i just want my game to be simple thats all
then you can't use item drop tables with variable drops.

a lot of game mechanics that look simple to the player require a lot of work from the developer, especially a lot of mathematics and programming.

and I agree with the others, you have to make the choice here:
either you put in the work (weeks of work probably) needed to understand those mathematics, or you drop that idea of having a more complex drop system than the default (which is as simple as it is possible).

and please tell us that decision so that we don't waste our time to explain things to you that you don't want to learn.
I made you a real working example to examine:
Spoiler
Code:
class Game_Interpreter
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # This method accepts unlimited amount of arguments.
  # One argument looks like this:
  #
  #   [:type, ID, min, max]
  #
  # An array with 4 elements. These elements are:
  # :type = Type of the item. :i = Item, :w = Weapon, :a = Armor.
  #    ID = The database ID of the item.
  #   min = Minimum number.
  #   max = Maximum number.
  #
  # The min and max numbers are used to determine the chance of getting the
  # item. The chance is based on the numbers you use here, and on the maximum
  # roll value you use (the default max roll value is set to 100, which means
  # the random number can be anything from 0 to 99).
  #
  # In case you want some extra data in this array (like the amount of items
  # gained, for example), you can even add more elements, and edit the code
  # below to do whatever you would like to do with that extra data of yours.
  #
  # When you are done with adding the possible items to get, you can add an
  # extra, optional argument at the end. This argument must be a simple integer
  # number. This will determine the maximum roll value.
  # If you don't use this argument, the maximum roll value will be set to 100
  # automatically.
  #
  # To explain how the actual gain percentages work here, I will use 2 examples.
  #
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # - Example 1:
  #
  #   gain_rand_item([:i,1,0,19],[:i,2,20,29],[:w,15,30,34],[:a,58,35,42])
  #
  # We didn't use an integer for the last argument, so the maximum roll value
  # will be set to 100 (0 - 99, total of 100 numbers).
  #
  # As you can see, this script call got 4 possible items to get.
  #    Item 1 has 20% chance to be gotten ( 0 - 19, total of 20 numbers).
  #    Item 2 has 10% chance to be gotten (20 - 29, total of 10 numbers).
  # Weapon 15 has  5% chance to be gotten (30 - 34, total of 5 numbers).
  #  Armor 58 has  8% chance to be gotten (35 - 42, total of 8 numbers).
  #
  # The total numbers used are 43 (0 - 42), so 57 numbers left (43 - 99),
  # which means that there will be 57% chance to get nothing.
  #
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # - Example 2:
  #
  #   gain_rand_item([:i,1,0,19],[:i,2,20,29],[:w,15,30,34],[:a,58,35,42],43)
  #
  # Hey, wait just a second! It's the same as before! What a scam!!!
  # ...
  # Okay, almost the same, but there is a major differece here.
  # We used an integer for the last argument (43). This made the maximum roll
  # value 43, which means that we eliminated the possibility of getting nothing,
  # since we used up all 43 numbers (0 - 42) in the item arguments.
  #
  # This also means that the chances of gaining these items are changed.
  # Remember that math lesson with the percentage pairs?
  #
  #   43 : 20 = 100 : x  -->  20 * 100 / 43 = 46.51%
  #   
  # That will be the chance to get Item 1.
  # Following the same logic:
  #
  #    Item 1 has 46.51% chance to be gotten here.
  #    Item 2 has 23.26% chance to be gotten here.
  # Weapon 15 has 11.63% chance to be gotten here.
  #  Armor 58 has 18.60% chance to be gotten here.
  #
  # Total chance to gain any item... 100%! Ta-da!
  #
  # As you can see, it's all about the numbers you set for your items AND the
  # maximum roll value you use.
  #
  # Another handy usage of changing the max roll value would be to make chances
  # that are below 1%. For example, use 1000 or 10000 for the max roll value,
  # and use the numbers up to the max roll value in the item drop chance
  # settings to make chances such as 0.05%, 0.7%, etc (hello gacha games! :D).
  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  def gain_rand_item(*args)
    # First setting up the maximum amount of values for the roll.
    # If the last argument is an integer, it will change the maximum amount
    # to the value you used. If not, it will remain on 100 by default.
    max_num = args[-1].is_a?(Integer) ? args.pop : 100
    
    # Now roll the random number.
    roll = rand(max_num)

    # Check for valid items from the list here.
    ritem = args.find {|item| roll.between?(item[2], item[3]) }
    
    if ritem # An item has been selected from the list
      # Determine what type of item to get.
      # :i = Item, :w = Weapon, :a = Armor
      case ritem[0]
      when :i; result = $data_items[ritem[1]]
      when :w; result = $data_weapons[ritem[1]]
      when :a; result = $data_armors[ritem[1]]
      end
      # Add the item to the inventory
      $game_party.gain_item(result,1)
      # Show message about the gained item
      $game_message.add("#{result.name} obtained!")
    else # No item gained
      # Just a message to notify the player about no item gain
      $game_message.add("No items found!")
    end
    
  end
 
end
Is it simple? That's highly subjective, but it can't get any simpler than this unless you strip the high versatility from it.
This very short code can let you add random items to the inventory from any type of items (item, weapon or armor), and lets you setup the chance of getting these items in a very precise way.

I tried to explain everything about the script call and about the code itself.
I left out some more complex explanations from the code, but if you want to learn about those too, I will try to explain those too later.
Hi,

I am not a Ruby programmer but I do know a good bit of C++ and so can explain an array to you.

First you've got to understand variables. A variable is basically a storage bin. Memory is a set of storage bins. When you write a program you reserve some storage bins and name each storage bin. Then you say what kind of thing can be stored in the storage bin.

Looking at the real world, you could take a box and write on it, "Toys." You are thus naming the storage bin "toys" and saying that only toys can be stored in it.

So each of these storage bins is a variable.

Declaring a variable is similar in most languages. In C++:
C++:
// Here I create an integer called ToyBox and assign it the value of 1.
int ToyBox;
ToyBox = 1;

// Alternatively, you can create and assign a value to a variable in one line:
int ToyBox = 1;

Unfortunately, though, each variable can only hold one thing at a time. int ToyBox only holds the integer "1". But what if you want to hold multiple things at once?

You use an array.

An array is a list of variables, all stored side by side in a row. You access them through a single name. Each variable in the array must be of the same type.

When you create an array, you specify how many items it holds, and you give it a name. Keep in mind that an array starts with element 0.

Here is how you declare an array in C++ (though I am assuming you are using Ruby)
C++:
// Here an array is created, called ToyBox, that holds ten items.
// Each item must be an integer.
int ToyBox[10];

// Here I define the first item in the array.
// The first item is ID 0, not ID 1. That's important.
ToyBox[0] = 10;

Original thread: https://forums.rpgmakerweb.com/threads/noobie-coding-explain-array-in-a-simpler-way.131546/