Locoweeds MPTut

Posted By: Lawrence

Locoweeds MPTut - 03/29/07 19:46

I have been working on this tutorial. Typing in all the commands(I find I learn and understand more if I type them in myself) to the point of the first test of a connection. I have built the small world and then tried it. It is the part where it places on the screen "people connected". My problem is the server shows '2' people connected and the client machine shows '0'. Does this matter or is it correct. I would have thought at worst case the client would say '1'.

I thought maybe I had typed something in wrong, so cut pasted it to make sure and still have the same problem.

Is this going to cause me a problem further on in the tutorial?

Lawrence
Posted By: PeterM

Re: Locoweeds MPTut - 03/29/07 20:30

Did you go throu whole tutorial? just go ahead with the tutorial... if you did and it still doesnt work then i dont know:)
I think i was wondering the same when i went throu tutorial but I think its solved later on...
Posted By: Zelek

Re: Locoweeds MPTut - 05/09/07 04:12

If there was only one response to this in over a month, I guess I'm probably out of luck, but I am having this exact same issue.

I spent the last couple of days re-reading the tutorial and reviewing my code to make sure I hadn't missed something, but it looks like this is an actual bug with the code. I just ran the included source code (after fixing a typo in it) and it has the same problem: the client doesn't receive information, but the host does. No variables sent via 'send_var' are ever received by the client.

The thing is, when I run the Biosphere .exe included with the tutorial, it works perfectly! Does anyone know what's going on? I'll keep looking through the tutorial to see if anything's mentioned, but if the source code itself contains this problem, I'm not terribly hopeful. If anyone can point me to another simple/current/working example of multiplayer code, that would be awesome too. Thanks.
Posted By: Scorpion

Re: Locoweeds MPTut - 05/09/07 16:15

just add to this varaible +1 at your main function then it should work
Posted By: Zelek

Re: Locoweeds MPTut - 05/10/07 02:34

I found the answer in an old post:
add "sleep(.5);" after the level load. It looks like you'll also want to sleep(.5) after you create an entity before you send it.

Maybe the engine changed since he wrote the tutorial, because it's been really thorough and great about not skipping steps up to this point.

I never thought I could be so happy to see the same variable on two different clients. It's like magic.
Posted By: fastlane69

Re: Locoweeds MPTut - 05/10/07 17:21

Don't use sleep(.5); use wait(-.5).

Sleep is likely to get dropped from the syntax and then your back to square one

Also, here is the quote from the manual:
Quote:

One frame cycle after this instruction the level is loaded, two frame cycles after the instruction the local entities in the new map are created and their actions are started.





So 1/2 second is probably overkill (unless you are running at 2 FPS), but a good precaution.

PS: also note that if you ever intend to use Session_Connect(), it used to be we had to put a pause after that instruction as well but JCL hardcoded that instruction into the function. Why this isn't the same with level_load, I don't know.
Posted By: oriongu

Re: Locoweeds MPTut - 06/02/07 11:45

I have the same problem, the wait(0.5); doesnt seem to change anything...

The vars just doesnt seem to get to the client.

This code should just show the number of people connected... but only the server shows anything.

//////////////// my code /////////////

path "Wads";
path "Sounds";
path "Models";
path "Entities";
path "Bitmaps";
path "Scripts";

font standard_font = "ackfont.pcx", 6, 9; // small text font

// --------------------------------------- Engine STRINGS

string world_str = <meetrikk.wmb>; // level string
string str_cbabe = <cube.mdl>; // CBabe Model

string str_people_connected; // number of people connected to server

string str_temp; // temp string

// --------------------------------------- Engine DEFINES

define MAX_CONNECTIONS, 64; // maximum number of people who can be connected to server

define FALSE, 0;
define TRUE, 1;

define player_number, skill1; // player number this entity owned by
define health, skill5; // health
define max_health, skill6; // max health of entity

// --------------------------------------- Engine VARIABLES

var fps_max = 60; // lock fps at 60 for all players
var fps_lock = ON;
var video_mode = 6; // screen size 800x600
var video_screen = 2; // start settings for Fullscreen
var mouse_mode = 2; // does not effect forces

// --------------------------------------- GAMES VARIABLES

var people_connected = 0; // number of people connected to server
var number_of_players = 0; // # of players in game
var server_says_start = FALSE; // client holds creating entity until server says go

var temp_loc[3]; // temp vector
var vecFrom[3]; // temp vectors
var vecTo[3];

//------------------------------------------PANELS------------------

text txt_people_connected
{
pos_x = 15;
pos_y = 15;
layer = 1;
font standard_font;
string str_people_connected;
}

// --------------------------------------- Engine MAIN

function main()

{
// if not a single player game, wait for connection

ifdef server;
while(connection== 0) {wait(1);} // wait until level loaded and connection set
endif;

ifdef client;
while(connection== 0) {wait(1);} // wait until level loaded and connection set
endif;

level_load(world_str); // load level

wait(1); // make sure level is loaded

if(connection == 2) // client?
{
while (server_says_start == FALSE) // wait for server to signal ok to continue
{
wait(1);
}

}

if(connection == 3){people_connected = 1;} // Compte le serveur comme un joueur

if(connection != 1) // if dedicated server skip these
{
display_info(); // continually display any information we want to show

// if not single player mode, display multiplayer information
if(connection)
{
txt_people_connected.visible = ON;
}
}
}

function server_called()
{
// if new player connected, increment people connected
// and tell him it's ok to continue

if ((event_type == event_join) && (people_connected < MAX_CONNECTIONS))
{
ifdef server;
people_connected += 1; // another person connected
send_var(people_connected); // send number of people connected
server_says_start = TRUE; // send it's ok to go to newest client
send_var(server_says_start); // send start message
endif; // ifdef server
}

// some one disconnected
if (event_type == event_leave)
{
ifdef server;
people_connected -= 1; // one less person connected to server
send_var(people_connected); // send number of people connected
endif;
}
}


function display_info()
{
while(1)
{
str_cpy(str_people_connected, "People Connected: ");
str_for_num(str_temp, people_connected);
str_cat(str_people_connected, str_temp);
wait(1);
}
}

on_server = server_called; // on server event, call server_called()
Posted By: fastlane69

Re: Locoweeds MPTut - 06/02/07 23:00

a) event_join and event_leave are server only... no need to IFDEF then.
b) Have you tried 1's and 0's for TRUE and FALSE. These are vars after all, not strings.
c) Once you get everything done, you do realize that that message is being sent to all clients currently logged in. This may be fine since if you are already in for a long time it's ok to start but if you get two poeple coming into your game at the same time, as soon as one is ready, the other will also get the go-ahead whether it's ready or not. Something for you to think about in your network object flow design.
Posted By: oriongu

Re: Locoweeds MPTut - 06/04/07 18:17

First , i thought i did modify my post , seems like i forgot.

i solved my problem by putting a wait(1);

Quote:

if ((event_type == event_join) && (people_connected < MAX_CONNECTIONS))
{
wait(1);
ifdef server;
people_connected += 1; // another person connected
send_var(people_connected); // send number of people connected
server_says_start = TRUE; // send it's ok to go to newest client
send_var(server_says_start); // send start message
endif; // ifdef server
}




Thanks for your reply fastlane....

For the true and false , its just me who prefer true's and false's than 1's and 0's.

I never done multiplayer coding , so im finding it quite hard but i love it.

Im not intending to have dozens of people on this game lol , so i dosnt really matter , but you are right im gonna have to change my code to allow people to come in one by one.

Just a la last question : Where'nt you doing a mmorpg? some sort of mmorpg kit?



Posted By: fastlane69

Re: Locoweeds MPTut - 06/04/07 19:07

Dropped the kit idea. Too risky and unprofitable.
Now fleshing out my Educational MMOG and then I'll maybe license the engine source but not as a "kit" persay. Though in truth, since my MMOG platform is built with 3DGS, WED, SED, MED, and the ongoing script development are pretty much a "kit" if you have my source.

That wait() troubles me. It is VERY bad to have a wait within an event. An event should be processed as quickly and independently as possible, often serving as no more than process to store the event for further use later on.

Do me a favor. Take out the wait AND the IFDEF's. See if it still works. Like I said before, those IFDEF SERVERS are redundent inside that event and there is no logical reason why putting a wait() where you did should make it work.
Posted By: oriongu

Re: Locoweeds MPTut - 06/04/07 20:40

I've removed the IFDEF and the waits , and it works as you said

Now to the movement's code

Thanks for all your help in this forum
Posted By: Black_Sheep

Re: Locoweeds MPTut - 07/11/07 22:52

Hi guys, ive the same problem and cant follow your steps in this thread!
Btw iam german, so if anyone of the posters above is a german one, would be great

So, back to topic. As i said ive the same problem. The Thing is: I have isolated the problem. This Bug comes only across with the last Client, that joined. I let four Clients join the Server and every Client and the Serer shows the correct amount of players connect, only the last client shows a great Zero.
And i swear... after hours of testing: this Zero seems to laugh about me
Posted By: Black_Sheep

Re: Locoweeds MPTut - 07/12/07 11:07

okay... i solved it too. Thx to oriongu for the right way to go. But i had to increas the wait(1) to wait(150) to get it correct. And than i realized, that wait(150) means 150 Frames! I had a fast computer , so i changed it in wait(-5), to let him wait exactly 5 seconds. Now my machine could connect twice in this time, but maybe someone with a slower one will connect.
© 2024 lite-C Forums