Posted By: Rasch
[ANET] Panel creation - 10/10/09 21:33
Hi,
how does it work if a client creates a runtime panel (paint something) and all other clients should see what he has created or painted?
Greets
Posted By: darkinferno
Re: [ANET] Panel creation - 10/11/09 00:52
send the location of the cursor and run the painting function on all clients ii guess.. am wayy to tired to acutually think of other methods or if this would work, i'll reply tomorrow if you dont get a better reply though
Posted By: Dark_samurai
Re: [ANET] Panel creation - 10/11/09 08:24
If you change the color of a pixel, send the new color to the other participants.
You could create a string that contains: [x position] [y position] [color blue] [color red] [color green]
And send it as event (the string as msg paramter).
Posted By: Rasch
Re: [ANET] Panel creation - 10/11/09 09:06
BMAP* malpunkt = "#5x5x16";
function paint(var mouse_pos)
{
bmap_fill(malpunkt,vector(0,0,0),100);
PANEL* paint_panel = pan_create("bmap = malpunkt;",1);
vec_set(paint_panel.pos_x, mouse_pos.x);
set(paint_panel,SHOW);
}
function main()
{
enet_init(); // enet initialisieren
enet_svset_event(21,_str("paint")); // Malfunktion
while(enet_get_connection() > 0) // solange ich ne Verbindung habe!
{
//...
if(mouse_left)
{
enet_clsend_event(21,_str("mouse_pos"),-1);
}
wait(1);
}
}
The problem is if i set: enet_svset_event(21,_str("paint"));
It runs one the client/server but not on normal clients. And clients cant use the function.
If iset it to: enet_clset_event(21,_str("paint"));
It works for nothing.
What do i do wrong?
Posted By: Dark_samurai
Re: [ANET] Panel creation - 10/11/09 10:03
You have to register the event also on the clients. And your event function is wrong. An event function always needs to have the same two parameters: var sender, STRING* msg. You can't send a variable directly with an event, you have to save it into the msg STRING instead:
BMAP* malpunkt = "#5x5x16";
function paint(var sender, STRING* msg)
{
if(sender == enet_get_clientid()) return;
bmap_fill(malpunkt,vector(0,0,0),100);
PANEL* paint_panel = pan_create("bmap = malpunkt;",1);
vec_set(paint_panel.pos_x, mouse_pos.x);
set(paint_panel,SHOW);
}
function main()
{
enet_init(); // enet initialisieren
enet_svset_event(21,_str("paint")); // Malfunktion
enet_clset_event(21,_str("paint"));
while(enet_get_connection() > 0) // solange ich ne Verbindung habe!
{
//...
if(mouse_left)
{
STRING* data_str;
//copy the mouse_pos into data_str here (use str_for_var)
enet_clsend_event(21,data_str,-1);
}
wait(1);
}
}
Code not tested!
Posted By: Rasch
Re: [ANET] Panel creation - 10/12/09 08:44
Alrigh. Didnt know that i can set the same events with same number. But the function str_for_var doesnt exist i at the moment dont know how to convert my mouse_pos into the STRING.
I get a error msg.
Just one more hole in my head
Posted By: Dark_samurai
Re: [ANET] Panel creation - 10/12/09 15:06
Yes they changed the name to str_for_num. I forgot that.
Here is the manual page:
http://www.conitec.net/beta/astr_for_num.htm
Posted By: Rasch
Re: [ANET] Panel creation - 10/14/09 15:47
Ok i tried everything now but everytime i click mouse_left it says error in main() Something still must be wrong but cant find the problem.

Thanks
Posted By: Dark_samurai
Re: [ANET] Panel creation - 10/14/09 16:40
Please post your current code.
Posted By: Rasch
Re: [ANET] Panel creation - 10/14/09 19:55
function paint(var sender, STRING* msg)
{
if(sender == enet_get_clientid()) return;
bmap_fill(malpunkt,vector(0,0,0),100);
PANEL* paint_panel = pan_create("bmap = malpunkt;",1);
vec_set(paint_panel.pos_x, mouse_pos.x);
set(paint_panel,SHOW);
}
function main()
{
fps_max = 60;
video_mode = 7;
video_depth = 32;
vec_set(screen_color,vector(255,255,255));
mouse_func();
on_enter = chat_input_start;
//on_mouse_left = paint;
enet_init(); // enet initialisieren
enet_svset_event(16,_str("client_connected")); // Infoverteiler Event - User Event
enet_svset_event(17,_str("client_leave")); // Client hat Spiel verlassen
enet_svset_event(18,_str("server_shutdown")); // Server Shutdown kick von allen Clients
enet_svset_event(19,_str("connect_msg")); // Info wer sich mit dem Server vebunden hat
enet_svset_event(20,_str("chat_msg")); // Chateingabe Funktion
enet_svset_event(21,_str("paint")); // Malfunktion
enet_clset_event(21,_str("paint"));
enet_svset_event(EVENT_DISCONNECTED,_str("client_disconnected")); // Server Event wenn jemand disconnected.
enet_clset_event(EVENT_CONNECTED,_str("connected_with_server")); // Client-Event beim Verbinden von Client
while(1)
{
if(key_1)
{
enet_init_server(port,max_players,_str("")); // server start
wait(4);
enet_init_client(_str("localhost"),port,_str("")); // client start
break;
}
if(key_2)
{
enet_init_client(_str("localhost"),port,_str("")); // client start
break;
}
wait(1);
}
while(enet_get_connection() > 0) // solange ich ne Verbindung habe!
{
enet_connection = enet_get_connection();
clientid = enet_get_clientid();
ping = enet_get_ping();
if(mouse_left)
{
var temp;
STRING* data_str;
vec_set(temp, mouse_pos);
str_for_num(data_str, temp);
enet_clsend_event(21,_str("data_str"),-1);
}
if(key_esc)
{
enet_clsend_event(17,_str(clientid),-2);
//client_leave(clientid);
break;
}
wait(1);
}
on_esc = NULL;
if(clientid > 0)
{
str_cpy(zeile4, "#80");
str_cpy(zeile3, "#80");
str_cpy(zeile2, "#80");
str_cpy(zeile1, "Disconnected. Press ESC to close application");
while(key_esc != 1)
{
wait(1);
}
wait(-0.1);
sys_exit(0);
}
}
Posted By: Dark_samurai
Re: [ANET] Panel creation - 10/15/09 11:23
The Problem is the following line:
var temp;
STRING* data_str;
vec_set(temp, mouse_pos);
vec_set() excepts a VECTOR and not a var.
Posted By: Rasch
Re: [ANET] Panel creation - 10/15/09 11:28
Ok but
temp.x = mouse_pos.x
temp.y = mouse_pos.y
donīt work. Itīs not a member of ".x" whatever this means what is the solution at the moment iīm really lost with that small problem.
Posted By: Dark_samurai
Re: [ANET] Panel creation - 10/15/09 14:03
Yes because you are using a var. A var is not a VECTOR. A VECTOR has .x, .y, .z but a var can only have a floating point value.
STRING* data_str = str_create("#100");
STRING* temp_str = str_create("#100");
str_for_num(data_str,mouse_pos.x);
str_for_num(temp_str,mouse_pos.y);
str_cat(data_str," ");
str_cat(data_str,temp_str);
//Use str_remove() when you don't need the strings anymore
This generates the following string: [value of mouse_pos.x][space][value of mouse_pos.y]
You should be able to read out the values after you sent them
Posted By: Rasch
Re: [ANET] Panel creation - 10/15/09 14:33
Alright seems a bit complicated for that simple function but thanks