PDA

View Full Version : Help with varibles and parameters


Sparkee77
02-28-2010, 04:34 PM
Ok need help understanding how to make good use of varibles and parameters any help would be greatly welcomed:confused:

Niteshifter
02-28-2010, 05:08 PM
I'm just going to assume that you don't know the difference just to make this "guide" easier.

Variables are information pieces that are used within a program to help it run better.

Parameters are exactly the same as variables, but they are information that is entered into a method to make the method more flexible within the world.

The main difference on which to use is actually quite simple. If the information piece in your method/function is going to be used in several different situations, then you should use parameters. If the information piece in your method/function is going to be used in one situation, or if it can generally be solved easily within the method/function, then you would use the variable.

How I go about doing this is basically make a list on paper, or in notepad or whatever of how many information bits I'll use and what types, then I decide which ones would be more suitable where.

Sparkee77
02-28-2010, 10:45 PM
Still can't understand why my varibles keep changing if I have it at a world level and can't understand what can and cant be dragged into them from the class method and functions tree.

nsprangers
03-05-2010, 04:22 PM
I don't quite understand the problem you're running up against. You have variables under the world properties and something is changing them, but you don't know what? As far as what can be dragged into them, when you create a variable you are asked what type it should be. You can then drag objects of that type into the variable.

The difference between variables and parameters is this:

A variable is something used to store a piece of information. A class variable (under the properties tree) is usually a piece of information that tells you something about that object. A variable within a method is a piece of information that will be used only within that method.

A parameter is also a variable, but it's a piece of information that a method or function needs to be given to do its job.

So for example, if you write a function to calculate the area of a circle, it will have one parameter - the radius, and one variable - the area. The parameter is given to the function by whatever object that calls it, whereas the variable is only used within the function to store the result and then return the value.