• 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!

I need help(client-server game)

M

MarkRazdrh

Guest
Hello, so I didn't know what i should type in for title cause i cant explain it in short way..
So I have this game where you create an account and pick a character then you press the button and then client(programmed in gamemaker) sends information to server and server stores it in database.
Now everything works fine when you connect in you see the character you picked(for example you choose red cat) but the problem comes when other people join your character becomes same as his character becouse server sends information and client stores it into same global variable so now you are both for example brown cats instead one is brown and other one (which in this example is you) is red.
Now im gonna tell you an example so it will be more understandable:
You create character and choose white cat and then you join, server sends your information back to client, client creates object(white cat) and then another guy joins and server then sends information to both clients then client creates instance of him and replaaces your cat which is white in database but it replaces your cat with his so you now both have black cat. Hope i was clear man this is hard let me put some codes in maybe you'll understand it even better

Now this is the code i have in my script for packet handeling(reading server commands things like that)

case "LOGIN":
status = buffer_read(argument0,buffer_string); //Client reads if login was successful or not
if(status == "TRUE"){

target_room = buffer_read(argument0,buffer_string); //Client reads in which room is the player who logged in
target_x = buffer_read(argument0,buffer_u16); //Client reads players last location
target_y = buffer_read(argument0,buffer_u16); //Client reads players last location
name = buffer_read(argument0,buffer_string); // Client reads the name of the player(so it can draw it later)
global.CatColour = buffer_read(argument0,buffer_string); //Client reads what colour is the player
goto_room = asset_get_index(target_room);
room_goto(goto_room);
with(instance_create(target_x + 40,target_y + 70,obj_player)){
name = other.name;


This is in my player object

var cat = global.CatColour;
switch(cat){
case "white":
sprite_index = spr_cat_down;
break;
case "black":
sprite_index = spr_catBlack_down;
break;
}

this is in my networkplayer object

switch(global.CatColour){
case "white":
sprite_index = spr_cat_down;
break;
case "black":
sprite_index = spr_catBlack_down;
break;
}

I know what the problem is but i just dont know how to fix it..
It is in global.CatColour becouse everytime someone logs in this variable changes(global.CatColour) and becouse every player object(networkplayer and player) uses this variable it's changing colours becouse variable is changing

Hope any of this makes sense if you have anything please type it in the comments and if you need anything else write in comments

Thanks
 
L

Laurent57

Guest
So you create a character and choose the color, but if your color changes it's because you permanently "call" the global.CatColour variable... When you create your object you only have to call the color one time. Maybe in the Create event of your player object with color=global.CatColour. Then you definitively assign the color to your player even global.CatColour changes. Well, it's difficult to solve without all the code and without knowing your database storage system...
 
M

MarkRazdrh

Guest
So you create a character and choose the color, but if your color changes it's because you permanently "call" the global.CatColour variable... When you create your object you only have to call the color one time. Maybe in the Create event of your player object with color=global.CatColour. Then you definitively assign the color to your player even global.CatColour changes. Well, it's difficult to solve without all the code and without knowing your database storage system...
Well the code for everything server/client would be way too long to post it here, is there a way to make variable which will read input only once like for example when the first player joins the room client creates instance player which then has some variables in it and the server then sends what kind of colour that player is and then player instance reads servers input and saves it into its own variable then it cant change anymore becouse if another player will join it will create player instance again and server will send different colour to second player instance and that will make client change colours for both becouse both of them use same variables and use same input that server sends,
in other words can i make that when my instance player creates it reads what server sent(global.CatColour) and saves it into its own colour variable and then make the variable not take any input from global.CatColour variable is something like that possible?
 
L

Laurent57

Guest
In which kind of Event do you put this:

var cat = global.CatColour;
switch(cat){
case "white":
sprite_index = spr_cat_down;
break;
case "black":
sprite_index = spr_catBlack_down;
break;
}

??
 
M

MarkRazdrh

Guest
In which kind of Event do you put this:

var cat = global.CatColour;
switch(cat){
case "white":
sprite_index = spr_cat_down;
break;
case "black":
sprite_index = spr_catBlack_down;
break;
}

??
Create event
 
M

MarkRazdrh

Guest
Still need help does any1 have any idea? Im open for suggestions Thanks
 
M

MarkRazdrh

Guest
Okay i figured it out! If anyone needs help with the same problem or similar problem you can send me a message and i will help you or atleast try to help :)
 
Top