Started by Blizzard, August 06, 2008, 08:07:00 pm
Quote[01:39] mumerus: Clarify this for me[01:39] mumerus: Weapon Name Syntax: $data_weapons[weapon_id].name Example: $data_weapons[1].name[01:40] mumerus: It can be like[01:40] mumerus: $data_weapons[1].Idiot's_Sword?[01:40] Blizzard: not really[01:41] Blizzard: ok, this is how it works[01:41] Blizzard: imagine we have a "variable" named icon[01:41] Blizzard: now let's see what we have[01:41] mumerus: k[01:41] Blizzard: we have an object[01:41] Blizzard: we wonder what's the icons's size[01:41] Blizzard: so we say[01:41] Blizzard: icon.size[01:41] Blizzard: see[01:42] Blizzard: objects can be considered as real-life objects[01:42] Blizzard: and they have properties[01:42] Blizzard: llike size[01:42] Blizzard: color[01:42] Blizzard: smell[01:42] Blizzard: taset[01:42] Blizzard: imagine food[01:42] Blizzard: now, food is not an object[01:42] Blizzard: it's a class[01:42] Blizzard: it's a type, a shape[01:42] Blizzard: like[01:42] Blizzard: Pizza is food[01:42] Blizzard: Hamburger is food[01:42] Blizzard: class Food[01:43] Blizzard: class Pizza < Food[01:43] Blizzard: class Hamburger < Food[01:43] Blizzard: that's how it works[01:43] mumerus: I see[01:43] Blizzard: now, a Pizza can have some properties[01:43] Blizzard: let's take the radius[01:43] Blizzard: se we say[01:43] Blizzard: class Pizza < Food attr_reader :radius end[01:44] Blizzard: let's make something like a default pizza[01:44] Blizzard: like[01:44] Blizzard: a Pizza that always has a radius of 30 cm[01:44] Blizzard: class Pizza < Food attr_reader :radius def initialize @radius = 30 end end[01:45] Blizzard: now we can create a pizza and store it into a variable[01:45] Blizzard: xyz = Pizza.new[01:45] Blizzard: when we use this now[01:45] Blizzard: p xyz.radius[01:45] Blizzard: a window will appear telling us the radius of the pizza (which is 30)[01:46] Blizzard: let's now create a pizza where we can say what radius we want at the very beginning[01:46] Blizzard: class Pizza < Food attr_reader :radius def initialize(rad) @radius = rad end end[01:46] Blizzard: using PIzza.new now will give us an error (argument error, 0 for 1)[01:46] Blizzard: which means[01:46] Blizzard: PIzza requires some data and information to be created[01:47] Blizzard: so we need to use[01:47] Blizzard: ttt = Pizza.new(25)[01:47] Blizzard: if we use now[01:47] Blizzard: p ttt.radius[01:47] Blizzard: we will get 25 as result[01:47] Blizzard: and there is a third alternative[01:47] Blizzard: let's say we want pizzas with variable sizes, but a default of 35[01:48] Blizzard: class Pizza < Food attr_reader :radius def initialize(rad = 35) @radius = rad end end[01:48] Blizzard: now we can try something like[01:48] Blizzard: a = Pizza.new(40) b = Pizza.new[01:48] Blizzard: we will get no error[01:48] Blizzard: p a.radius p b.radius[01:48] Blizzard: this will give us 40 and 25 respectively[01:49] Blizzard: since we said that we wanted Pizza a to be created with a radius of 40[01:49] Blizzard: and Pizza b didn't get any information so we have a pizza of 35[01:49] Blizzard: well[01:50] Blizzard: I just explained you the concept of creating classes, objects and what properties are[01:50] Blizzard: I'll put something else on top[01:50] Blizzard: behavior[01:51] Blizzard: class Pizza < Food attr_reader :baked def initialize(rad = 35) @radius = rad @baked = false end def bake @baked = true end end[01:51] Blizzard: here's the code and what we will get[01:51] Blizzard: pizza = Pizza.new p pizza.baked pizza.bake p pizza.baked[01:51] Blizzard: we created a PIzza[01:52] Blizzard: it was initialized with @baked as false[01:52] Blizzard: that means the first time "false" will be printed on the window[01:52] Blizzard: then we called the "method" named "bake"[01:52] Blizzard: (that's what "def" is for: define method with name "bake")[01:53] Blizzard: when we called the second printing[01:53] Blizzard: we got "true"[01:53] Blizzard: because the method "bake" was executed first[01:53] Blizzard: and it changed the variable[01:53] Blizzard: that's basically it[01:53] Blizzard: that's some knowledge to start with[01:54] Blizzard: you define instance variables (the ones with the prefix @)[01:54] Blizzard: and you define methods[01:55] Blizzard: which pretty much simulates the behavior of the object[01:55] Blizzard: it's like real life[01:55] mumerus: Hm[01:55] Blizzard: the difference is that you can but don't have to go into details[01:55] Blizzard: we have a very simple pizza here[01:55] Blizzard: we could have complicated it endlessly[01:55] Blizzard: creating other classes[01:55] mumerus: After a big talk with Ulta.. thats gonna hurt me[01:55] Blizzard: for stuff you put on the pizza[01:55] Blizzard: lol[01:56] Blizzard: I think I'll post this as a messy tute[01:56] mumerus: Yeah[01:56] mumerus: Im starting to get it little by little
Quote from: winkioI do not speak to bricks, either as individuals or in wall form.
Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.
Quote from: Berans on August 08, 2008, 01:20:00 pmScripting is an evil thing though...it sucks you in and makes you spend more time than you have fixing up the tiniest little bugs