Jump to content

troubles with NetworkEvent


photo

Recommended Posts

1. When I do network.connectTo server in SYSTEM.CPP

2. Connect is successefull

3. I see packets transmisition in tcpdump log

4. And I registered RegisterHandlers in system.cpp, but I event handlers weren't called.

 

But I added event handler code in WORLD.CPP (not register, only write event handler code), then event handler were called and called in WORLD.CPP.

 

It's big problem, because I cann't use variables from SYSTEM.CPP in WORLD.CPP and v.v. too. =(

Link to comment

1. When I do network.connectTo server in SYSTEM.CPP

2. Connect is successefull

3. I see packets transmisition in tcpdump log

4. And I registered RegisterHandlers in system.cpp, but I event handlers weren't called.

 

But I added event handler code in WORLD.CPP (not register, only write event handler code), then event handler were called and called in WORLD.CPP.

 

It's big problem, because I cann't use variables from SYSTEM.CPP in WORLD.CPP and v.v. too. =(

Network event handlers can only be world functions, because plugin uses Engine::runWorld() to call event handlers.

 

Why do you think you can't use variables from system script in world script? We do this in our projects.

See oilrush code for reference.

To set system script variable we create separate function. It looks like this:

   void setServerPort(int server_port_) {
        server_port = server_port_;
   }

And call it from world script:

   engine.system.call("setServerPort",12345);

To get variable you can use the following code:

   int server_port = engine.system.get("server_port");

 

And why do you want to call connect from system script?

We call connect/disconnect functions from world script. Connection does not drop if you load another world (if you do not call disconnect during shutdown).

We use system script to save some data that should be passed from main menu into game.

Link to comment

I'm use variable of UserClass type, and if use this code, then create copy of variable.

int server_port = engine.system.get(...);

And when I had changed a copy, original didn't change.

 

And how do I get variable from system script in world script?

 

I want to call connect in system script, because data for loading world transmit by network.

Link to comment

I'm use variable of UserClass type, and if use this code, then create copy of variable.

int server_port = engine.system.get(...);

And when I had changed a copy, original didn't change.

 

And how do I get variable from system script in world script?

 

I want to call connect in system script, because data for loading world transmit by network.

 

To call world functions and get world script variables you can use the same way.

There are engine.world.call() and engine.world.get() methods in Unigine script library.

See documentation for reference.

This is a reference for engine.system functionality.

 

But it is not appropriate to pass UserClass variables through this methods.

It's better to convert it into several simple variables (if the UserClass is not very complicated).

 

What data for world loading do you transmit?

 

And is it possible to load some default world at first, call connect there and after that load the new world?

We use this approach in oilrush.

Link to comment

Anet

Oilrush sources opened or not?

I cann't find it, scripts in data is packed in *.UNG format.

 

What data for world loading do you transmit?

Coordinates of objects, object types, objects options and many over data

Link to comment

Anet

Oilrush sources opened or not?

I cann't find it, scripts in data is packed in *.UNG format.

You can unpack it. Use ung tool (Tools pack).

 

Coordinates of objects, object types, objects options and many over data

Why don't you create all this objects dynamically in a loaded world?

Link to comment
×
×
  • Create New...