Main Menu
  • Welcome to The RPG Maker Resource Kit.

Braces vs. Brackets

Started by cozziekuns, May 09, 2010, 10:56:45 PM

0 Members and 1 Guest are viewing this topic.

cozziekuns

Probably a dumb question but...

What's the difference between Braces {} and Brackets [] when scripting with RGSS2?

modern algebra

Well, braces create hashes and blocks. Square brackets create arrays. Since square brackets aren't really involved in blocks, I'm guessing what you are asking is what is the difference between a hash and array. There are quite a lot, but I'm guessing what you're interested in is that arrays can associate an object with an ID integer, whereas a hash can associate objects with any arbitrary objects, and there isn't any necessary order to it.

So, for instance, an array could be:

array = [5, "abc", 84]


and then array[0] would return 5, array[1] would return "abc", and array[2] would return 84.

Whereas a hash could be:


hash = { 1 => 5, "alpha" => "abc", :sym => 84 }


and then hash[1] would return 5, hash["alpha"] would return "abc", and hash[:sym] would return 84.

There are a number of reasons to use one or the other, if you want to know more.

cozziekuns

Oh, that makes a bit more sense.

Thanks Modern.

Grafikal


cozziekuns