First line brackets

Noremac

New member
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

Developer
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

Member
[quote author=holatuwol link=topic=291.msg1541#msg1541 date=1153164906]
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.[/quote]Wait, what?? I never knew this. Sweet!
 

GoldenRatio

New member
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

Code:
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!
 
Top