The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: cozziekuns on May 09, 2010, 10:56:45 PM

Title: Braces vs. Brackets
Post by: cozziekuns on May 09, 2010, 10:56:45 PM
Probably a dumb question but...

What's the difference between Braces {} and Brackets [] when scripting with RGSS2?
Title: Re: Braces vs. Brackets
Post by: modern algebra on May 09, 2010, 11:51:10 PM
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.
Title: Re: Braces vs. Brackets
Post by: cozziekuns on May 09, 2010, 11:55:32 PM
Oh, that makes a bit more sense.

Thanks Modern.
Title: Re: Braces vs. Brackets
Post by: Grafikal on May 09, 2010, 11:57:56 PM
Yeah, he's awesome.
Title: Re: Braces vs. Brackets
Post by: cozziekuns on May 09, 2010, 11:59:48 PM
Agreed.