Is there anything wrong with this? I personally like to define them as global variables as it saves me the effort of defining them nearly every other function.
However, I've seen some members disapprove of this....
Is there anything wrong with this? I personally like to define them as global variables as it saves me the effort of defining them nearly every other function.
However, I've seen some members disapprove of this....
Simply a GOD beast...
My Tutorials
Just try to learn declaring them inside function because Global variables can mess up. If you use same Variable which is global over and over again. You can accidentally mess up something in your script.
(Bad Example. In some function X is declared as 10 and when next function comes it's still 10 because something went wrong in current function)
~Home
Last edited by Home; 04-09-2012 at 09:53 PM.
I'm not okay with this
It's bad practice to declare global variables. Especially x, y and i. Those are used by a lot of functions and procedures. If for some reason one procedure changes it, the script might go wrong. Also it is bad practice for the eye, these are only used within the function and can be discarded afterwards. Not globally used to safe information where it is important that it isn't lost add the end of the function.
Working on: Tithe Farmer
I really hate global variables, I usually try to stay away from them when I can.
Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
{ MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }
When posting a bug, please post debug! Help us, help you!
I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.
SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.
Ok thanks guys - I'll stop doing it then![]()
Simply a GOD beast...
My Tutorials
Hehe I think you are talking about people disapproving of this was in my appI like global variables, but that it cause in my opinion it is easier if I need the values later on in the script. Idc if its frowned upon, if it works it is good...... or least thats how i feel
however I'm sure it will catch up with me somewhere along the way in the programming life... so I should probably stop aswell
![]()
|| Droppin' Bandits || Chicken Killer || Power Iron || Ash Collector ||
Herblore script || Edgeville Yew Chopper || Basic Gnome Agility Runner
Changing the world one script at a time
Send SMS messages using Simba
Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!
I really don't get this actually (even though i do declare mine locally).
I don't see how anything can mess up really unless you code like a cheeseball.
Why would you use X & Y in a function before declaring them anyways, either globally or locally?
Like who seriously does a FindColor (and respective family) function to define X, Y or a TPA of them and doesn't include the respective actions in it's own begin/end block.
Like if you do a:
FindColorSpiral(X, Y, ...)
Mouse(X, Y, ...)
Without checking, then it would mess up globally or locally anyways.
I'm back
IMO globals should be used only for progress variables, (With some rare exceptions).
i would only declare them globally if its value is used in other procedures/functions. you can declare them globally if you want, but locally makes it so it shouldnt go wrong by starting with a bad value.
It's a really bad coding practice, there are a few good reasons why every comp sci class actively discourages using global vars. One of the reasons is, it starts with x and y and i, after that you do like x1, x2, y1 and y2 and you end up having only global vars.
Ideally you can cut and paste a function into a new script and it'll work. Won't work with stuff like this.
Also I'd like to invite everyone to also vote No at member apps if they spot this.
I made a new script, check it out!.
Simply a GOD beast...
My Tutorials
I would get as far away from global variables as possible look at the following case:
Simba Code:program new;
function DoubleThenAdd(a, b : integer) : integer;
Var
i, x, y : integer;
begin
x := a + a;
y := b + b;
Result := x + y;
end;
procedure DoSomething;
Var
i, x, y : integer;
begin
for i := 0 to 5 do
begin
x := x + 2;
y := y - 1;
WriteLn(DoubleThenAdd(x, y));
end;
end;
begin
DoSomething;
end.
Simba Code:program new;
Var
i, x, y : integer;
function DoubleThenAdd(a, b : integer) : integer;
begin
x := a + a;
y := b + b;
Result := x + y;
end;
procedure DoSomething;
begin
for i := 0 to 5 do
begin
x := x + 2;
y := y - 1;
WriteLn(DoubleThenAdd(x, y));
end;
end;
begin
DoSomething;
end.
They have different outputs just because of global/local vars, a very contrived case but could happen
Also a bad example. Though pascalscript inits variables at 0, you shouldn't rely on that.
Simba Code:program new;
function DoubleThenAdd(a, b : integer) : integer;
Var
i, x, y : integer;
begin
x := a + a;
y := b + b;
Result := x + y;
end;
procedure DoSomething;
Var
i, x, y : integer;
begin
x := 0;
y := 0;
for i := 0 to 5 do
begin
x := x + 2;
y := y - 1;
WriteLn(DoubleThenAdd(x, y));
end;
end;
begin
DoSomething;
end.
I made a new script, check it out!.
Only time u use globals in Pascal, is if u need the value initialized from another function.. Or want the value preset before it hits ur second function since Pascal doesn't have pointers and all.. Well it does. Just not Simba.
In other languages like in the real world, u don't need globals ALL the time since u can use pointers.. but sometimes u do.
I am Ggzz..
Hackintosher
There are currently 1 users browsing this thread. (0 members and 1 guests)