Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,119 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 8 1 2 3 4 5 6 7 8
Re: Access variable from other program? [Re: Ruben] #434835
12/28/13 09:20
12/28/13 09:20
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
inventory.c is an open source script that allows anyone to make their own customized inventory bag for the player in their game. It is saved in its own script called inventory.c . Are you saying that I have to combine inventory.c and OrcStronghold.c in the same script, in order to allow me to use a variable only stored in inventory.c , but who's value is needed by OrcStronghold.c to compare to another value, in order to initiate an action?

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 Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Originally Posted By: JustSid
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 Offline
Expert
WretchedSid  Offline
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 Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Quote:
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 Offline
Expert
WretchedSid  Offline
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:
Quote:
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):
Quote:
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 tongue


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] #434843
12/28/13 11:38
12/28/13 11:38
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Sadly this does not prove anything, it could have been a member of a struct or anything different but no global variable and it would have resulted in the same problem.


"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] #434844
12/28/13 11:41
12/28/13 11:41
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
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: WretchedSid] #434845
12/28/13 11:46
12/28/13 11:46
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I still don't see a reason. I can understand that there may be some problems when you work on a project in a big team or want to provide libraries for other users but even this could be solved with a proper naming convention.

#globalvariables4life


"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] #434846
12/28/13 12:00
12/28/13 12:00
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
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.

Code:
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 wink

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.

Visit my site: www.masterq32.de
Re: Access variable from other program? [Re: MasterQ32] #434847
12/28/13 12:16
12/28/13 12:16
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Yes, I see, but given that you have an (almost) unlimited pool of possible variable names and you should know that those GStudio variables overwrite local variables (which I find a little stupid, though) you only have to take a very little amount of care and creativity to overcome this problem.
Global variables are useful for a number of things, they are not 100% evil.


"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
Page 2 of 8 1 2 3 4 5 6 7 8

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1