3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Access variable from other program?
[Re: WretchedSid]
#434836
12/28/13 09:23
12/28/13 09:23
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
Include pulls the other script into the current translation unit. In other words: Your problem doesn't exist to begin with. So by using #include , it is basically making the two scripts a part of the same script?
|
|
|
Re: Access variable from other program?
[Re: Ruben]
#434840
12/28/13 10:57
12/28/13 10:57
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
As far as the current translation unit is concerned: Yes. The include is replaced with the contents of the other script by the pre-processor.
By the way at whoever suggested global variables: Shame on you! Polluting the global namespace with variables is evil!
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Access variable from other program?
[Re: WretchedSid]
#434841
12/28/13 11:33
12/28/13 11:33
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
By the way at whoever suggested global variables: Shame on you! Polluting the global namespace with variables is evil! Using global variables isn't normal, but on Meth it is. I don't understand the hate on global variables, they are awesome and I use literally thousands of them in my project. <3
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Access variable from other program?
[Re: Superku]
#434842
12/28/13 11:37
12/28/13 11:37
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
The problem is that every function has access to them and the large a project grows, the harder it gets to keep track of what is doing what with what and who is depending on which variable and who is writing into which... To give you a hands on example, let me quote yourself: ground_contact, wie ich aber gerade feststellen musste, ist keine variable, die nur 0 oder 1 annimmt, sondern die zähle ich bis 16 hoch.... weil ich irgendwo irgendwann vor jahren mal die dauer des bodenkontaktes brauchte English (translation by me): ground_contact is, as I just discovered, not a variable in the range of 0 to 1 but is incremented up to 16 because years ago I needed a the time of the ground contact That basically sums up why global variables are considered bad practice. Class dismissed
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Access variable from other program?
[Re: Superku]
#434844
12/28/13 11:41
12/28/13 11:41
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Where it is stored doesn't matter, the point was to provide meaningful encapsulation. Put it all into one big struct and you haven't changed the problem one bit, just moved it around to another namespace. The point is to minimize the scope of access.
I mean, there is a reason why it's universally accepted as bad practice and anti-pattern, I don't make this stuff up just to annoy people.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Access variable from other program?
[Re: Superku]
#434846
12/28/13 12:00
12/28/13 12:00
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
@Superku: Maybe the best example: target, result, hWnd, player, my, me, you, your, nullvector, mtl, camera... Imagine how often you need a local variable with this name but not with the same type.
ENTITY *camera = ent_create("camera.mdl", vector(16, 324, 123), follow_player);
camera->x = 5; // What variable do i modify? global VIEW* camera or local ENTITY* camera?
TraceResult *result = x_trace(from, to, USE_POLYGON); // Using custom tracing
if(result->isHit) { // Doesn't even compile, because result is a var and it is global
error("I hit something!");
}
@Sid: Thanks for teaching a good code discipline EDIT: In short version: Every single global variable takes your possibility of thousands of local variables.
Last edited by MasterQ32; 12/28/13 12:01.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|