• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Question about global variables

X

XirmiX

Guest
Since I'm creating a top-down shooter MMO, a question about global variables came up to me... I don't exactly have much knowledge of how to implement dedicated server-based gameplay, but still it kept nudging me; if I set a global variable, would it be global to only one player's character or the whole game? So, if I set a global variable for moving around for my playable object, would I in result be able to move the playable object of a friend who joined the game's server? If so, how can I resolve this if the code for all playable characters is the same and there are global variables I want to share only within a few objects? That is without linking them as child or parent (although even that didn't work for me before and so I had to set all variables in another object to global so that the controllable object(s) would respond to them and I wouldn't get an error).
 
A global variable is shared with the entire game. You may want to set a local variable for objects the player(s) will control exclusively. Perhaps depending on what is shared on an environmental level, you may want to use the global variables for. Like gravity for example will be the same for all players and objects and would therefore require a global variable.
 
X

XirmiX

Guest
A global variable is shared with the entire game. You may want to set a local variable for objects the player(s) will control exclusively. Perhaps depending on what is shared on an environmental level, you may want to use the global variables for. Like gravity for example will be the same for all players and objects and would therefore require a global variable.
Wait, aren't local variables something that acts within a particular event? I don't remember them being something that will act upon multiple specified objects or anything... In which case, how would I do THAT?
 

Genetix

Member
object.var possibly? For example: obj_player.health - Another object could always check out the players health variable by doing such. You can also check the variables of specific instances (say if you have multiple obj_player objects), the "with" command is another good tool to learn if you haven't.
 
X

XirmiX

Guest
object.var possibly? For example: obj_player.health - Another object could always check out the players health variable by doing such. You can also check the variables of specific instances (say if you have multiple obj_player objects), the "with" command is another good tool to learn if you haven't.
I would guess it would have to be instance specific as you're controlling an instance and not the entire object in an MMO, right? So would object.var really do the trick? It doesn't seem like it. I can only guess I would need to mess around with code for instances and not objects specifically to get the result I want, right? Though, I would need to set up a connection first. And moreover, not just a dedicated server connection, but also involvement of master server, which will hold onto all of the room layouts and account details and such.
 
B

bojack29

Guest
Your attempting an MMO and your confused about global variables? You should probably start smaller. Waaay smaller. People who have been programming for YEARS have immense trouble building a functional MMO, ans they typically do it within a team.

But to answer your question, No.

Global variables affect your game and no one elses. If you need a variable set amongst different clients then a server will have to destribute that variable to all respective parties.
 
X

XirmiX

Guest
Your attempting an MMO and your confused about global variables? You should probably start smaller. Waaay smaller. People who have been programming for YEARS have immense trouble building a functional MMO, ans they typically do it within a team.

But to answer your question, No.

Global variables affect your game and no one elses. If you need a variable set amongst different clients then a server will have to destribute that variable to all respective parties.
Oh, but I'm taking on the challenge :p It's just a 2D game with a bit of content in it, nothing too huge, like say a game of Halo or something. It's not like extremely huge or anything, though a lot of code is necessary and I've already got a bunch of code done just so that the two weapons, the one hull and the two paints I have added work as intended (plus collision). And I still have trouble with things like recoil (because I can't stand nor understand SohCahToa) and impact force working as intended, though I'm getting things working for what I am working on, step by step.

So, from a tutorial I previously took a glimpse on, client and server would have to be completely different game files that would interact with each other, correct? In which case, even if I use a global variable within the game on the client side, so long as the server doesn't direct it to other clients, I can still use global variables, correct? If that is the case, then that's good, because I wouldn't want to go through every single variable I've set as global at this point and set to something else.
 
B

bojack29

Guest
Correct, global variables are for YOUR PC only.

However the server can be a client at the same time. Ever heard of host advantage in different video games? The host hosts the games and sends packets to all the PCs connected to the host. Dedicated servers do not have a host and are most ideal
 
X

XirmiX

Guest
Correct, global variables are for YOUR PC only.

However the server can be a client at the same time. Ever heard of host advantage in different video games? The host hosts the games and sends packets to all the PCs connected to the host. Dedicated servers do not have a host and are most ideal
Wait, so then global variable... agh, this is so confusing >_< and yeah, I know about hosts. The dedicated servers within which players will be playing in for my game will need people to host their own dedicated servers too.
 
B

bojack29

Guest
Dedicated servers are... well dedicated. There are no hosts involved. Thats what makes it so ideal. The problem with hosts is that their computer has zero lag. This is because everyone connects to him and he does all the legwork. This in turn gives whomever is the host client a huge advantage over everyone else playing because his computer always registers hits, movement and updates before anyone else.

Gears of War suffered from this problem because the host was damn near impossible to kill because of his perfect latency.

It also means that if the host is downloading content or streaming heavy bandwidth operations, it meant that everyone connected to him playing some video game suffered latency issues as a result.
 
X

XirmiX

Guest
Dedicated servers are... well dedicated. There are no hosts involved. Thats what makes it so ideal. The problem with hosts is that their computer has zero lag. This is because everyone connects to him and he does all the legwork. This in turn gives whomever is the host client a huge advantage over everyone else playing because his computer always registers hits, movement and updates before anyone else.

Gears of War suffered from this problem because the host was damn near impossible to kill because of his perfect latency.

It also means that if the host is downloading content or streaming heavy bandwidth operations, it meant that everyone connected to him playing some video game suffered latency issues as a result.
Oh, but my idea was that you could host your own server, be it on the same machine or another and you logging on on off would not determine whether the server is active or not; you would need to do it manually yourself. You can check out a game called Don't Starve Together to get what I mean. And I understood a bit more about the global variables now, I think. Also, whilst the host might still have some minor advantage, since my game isn't particularly huge and is in 2D, with pixelized graphics (tiles that are like 128x128 size in pixels), so I don't see this being too huge of an issue. Besides, it's not like I could hold on a few hundred or a few thousand players on my own for all the battles (servers) hosted PLUS the master server, which holds all the map and account data.
 
B

bojack29

Guest
What you could do is have a master server that runs all day long. Hosts can host games on and off and other players can connect to hosts as they appear. All information about maps and stats of all players can be stored and retrieved off the master server. But you need to make sure this server is active at all times.

You need to realize too that host advantage really only comes into play in games that are high action and require real time skill.

RTS, FPS etc.

Turn based games are not affected by this.
 
X

XirmiX

Guest
What you could do is have a master server that runs all day long. Hosts can host games on and off and other players can connect to hosts as they appear. All information about maps and stats of all players can be stored and retrieved off the master server. But you need to make sure this server is active at all times.

You need to realize too that host advantage really only comes into play in games that are high action and require real time skill.

RTS, FPS etc.

Turn based games are not affected by this.
Yeah, I am aware of the master server needing to be run on a machine that runs all the time (So, I think it would be better if I set times when the servers are open and when they are closed). But apparently this... I could perhaps make it so that clients hold onto their own data and could only play together if their client-side-games have the same data, but I'm aware there can be made workarounds if two people cooperate in order to cheat...
 
B

bojack29

Guest
Right. That is an important factor of a server. By utilizing a middle man to check packets, you can analyze different variables to determine active cheaters. Say the mouse coordinates in an FPS follow a straight line, the result is that the player is likely a cheater. Humans cannot draw perfectly still lines across the screen. Or it can compare movement coordinates against old coordinates to see how fast a player moves. When a player exists the distance between two coordinates, he is moving too fast and likely cheating.
 
Top