Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   GS2: Local variables (https://forums.graalonline.com/forums/showthread.php?t=59006)

Fry 05-18-2005 05:54 PM

GS2: Local variables
 
I was wondering, Torque Script has them, so why have them be removed from GS2? Having those would really easen things.
I'd guess there were some problems including them, but I'd really appreciate it if we could get something similar.

(I am talking about variables that won't exist over the current scope, like explained in http://tork.beffy.de/uploads/liquid.net/tutorial1.htm)

Admins 05-18-2005 06:14 PM

Quote:

Originally Posted by Fry
I was wondering, Torque Script has them, so why have them be removed from GS2? Having those would really easen things.
I'd guess there were some problems including them, but I'd really appreciate it if we could get something similar.

(I am talking about variables that won't exist over the current scope, like explained in http://tork.beffy.de/uploads/liquid.net/tutorial1.htm)

You mean temp. variables ?
In new Graal script variables are by default global (like in old scripting engine on clientside), and you can limit the scope by putting this., player., server., temp. etc. in front.

Rick 05-18-2005 06:14 PM

The only way to do local variables right now is define them in the function arguments. I agree with you, the removal of local/global variable scope sucks. :(

Quote:

Originally Posted by Stefan
You mean temp. variables ?

temp.?

In TorqueScript you have %local, and $global variables.

Admins 05-18-2005 06:29 PM

Quote:

Originally Posted by Rick
temp.?

Function parameters are temp. variables, you can call a variable temp.something to make it only work in the current function body or if you want to do a recursive function.

Quote:

Originally Posted by Rick
In TorqueScript you have %local, and $global variables.

In Graal script % is an operator (modulus), and like I said it is needed for compatibility so that the old Graal scripts work the same.

Fry 05-18-2005 06:32 PM

Quote:

Originally Posted by Stefan
You mean temp. variables ?
In new Graal script variables are by default global (like in old scripting engine on clientside), and you can limit the scope by putting this., player., server., temp. etc. in front.

Well, I don't know how temp. vars act, but I was talking about variables that won't exist in (as example) a function called by the function, like

function foo() {
foovar = "hello";
bar();
}

Now function bar shouldn't have access to foovar, yet it does and it is one big source for errors.
Like when you use some function someone else made, and it changes a variable you use in your function that calls this 3rd party function.

EDIT: A-hah, so temp. vars replace them :) Well, that answers my question, thanks very much.

Admins 05-18-2005 06:48 PM

Quote:

Originally Posted by Fry
Now function bar shouldn't have access to foovar, yet it does and it is one big source for errors.

Yes it can be confusing sometimes, but it was the only way in the old scripting engine to pass parameters to the called function so it cannot be just removed. It could be possible to add the possibility to modify the scope of variables by serveroptions may be, although it can be even more confusing if the same script works differently from server to server.


All times are GMT +2. The time now is 08:30 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.