PDA

View Full Version : First line brackets



Noremac
07-17-2006, 04:29 PM
What's the difference between:

void main (int amount)

and

void main()
{
int amount;
}

?


Separate question: If I define something in a subprogram (feel free to correct the terminology) will it be defined in the other subprograms? If I define it in the main program will it be accessible by the subprograms?
I've tested this myself and it would seem that this is not possible but I can't rule out that I've made a mistake somewhere.

e.g.
void prog1()
{
item booze7;
}

void prog2()
{
booze7=$item[fine wine];
}

void prog3()
{
drink booze7;
}

void main()
{
prog1();
prog2();
prog3();
}

Thanks in advance.

holatuwol
07-17-2006, 07:35 PM
For your first question, the first one will prompt you for a value (using a GUI window) and the second one will simply declare the value that can be defined later in a script.

For your second question, variables are scoped.* If you put one inside of a function (that's the correct name), then it will only be visible while executing that function.* If you want global variables that get defined within functions, you can declare them in the global scope.

macman104
07-18-2006, 03:28 AM
For your first question, the first one will prompt you for a value (using a GUI window) and the second one will simply declare the value that can be defined later in a script.Wait, what?? I never knew this. Sweet!

GoldenRatio
07-18-2006, 07:12 AM
It's called a 'parameter'. When using code, it allows you to pass in (in this case) a number, and that function can then use that number for whatever. ie


void foo(int amount)
{
print("You have " + amount + " of something.");
}

void main()
{
foo(5);
foo(2543);
}

Also the guy before me was probably talking about the GUI thing, where it asks you what value you want. I didn't know that either and it's pretty sweet!