2018-12-24 21:44:13

I have read the network chapter in bgt and I understand it. I have 2 questions though.
I have built a dreidle game, and it gives you messages when you spin the wheel. How would I put those messages into a packet? The messages are in the function when you spin the wheel, so how would you transfer it over to the function that sends packets?
And the second question. I built a menu and a wheel function for both player 1 and player 2. Is it possible for player one to be in the player 1 menu while player 2 is in the player  2 menu? And if so, how do I use the peer_id to set them as player 2?

2018-12-24 23:51:09

sorry for posting twice. I have gotten the connection successfully established, and the answer to my second question about player 2 has been answered.
I didn't explain question 1 clearly. If player one spins the wheel an the outcome is they gain 15 gold, ow do I send that message to player 2's computer and add the 15 gold to player 1 on their computer? Thanks

2018-12-25 00:13:05

I woulnd't go and doing it that way. I would make a player class on the server and have it contain things like points and an uint containing the player's peer_id. If you have an questions and want live help, you can add me on skype. Isoto680
let me know who you are because I won't add random people

Ivan M. Soto.
Feel free to check out my work and services.
http://ims-productions.com

2018-12-25 21:49:37

the game wants to connect to my local IP, not my general IP or whatever it is called. I have looked at the code for hosting on a server and their is no mention of local verses general IP. So why is it only accepting local?
void create()
{
show_game_window("Game Server");
tts_voice voice;
if(host.setup_server(6500, 1, 100)==false)
{
speak("Error. The server could not be set up.");
exit();
}
speak("You are now hosting.");
network_event event;
while(true)
{
event=host.request();
if(event.type==event_connect)
{
alert("peer joined.", "Peer number " + event.peer_id + " connected from " + host.get_peer_address(event.peer_id) + ".");
alert("total peers", "Peers now connected: " + host.connected_peers + ".");
play=1;
p_first=true;
f_menu();

2018-12-25 21:55:06

The game will connect to your local IP, and you can then configure your router to route incoming data to that local IP.  You'd give your global IP to other people who want to connect to you, and it is your router that then gets those messages and knows which computer on your local IP to redirect them to.  Hopefully that helps.

- Aprone
Please try out my games and programs:
Aprone's software

2018-12-26 00:12:43

I know nothing about network connections, lol. Would Can you list the steps I would need to take to get the router to recognize my computer for the local connection I had no idea the game connected to local to begin with, but at least I can get a successful connection with my own computer, lol

2018-12-26 05:34:18

Every router is a bit different so I can't really give specifics.  You'll have some specific web address you visit, which gives you access to your router for changing it's internal settings.  For example, some routers use the address 192.168.0.1, or 192.168.1.1
When you finally get in (likely explained in the manual that came with the router) there should be some section that lets you forward ports.  You'll come up with a port number you want to use, type it, and then type the local IP for the computer you're running your game server on.  The router now knows that any time someone sends data to that port, it will redirect the message to your specific computer.  The game you're making (or playing) will request the IP to connect to, but also the port to use.  Make sure you're using the same port number as the one you set up in the router, since that's how the router knows those are the messages you want sent to your computer.

- Aprone
Please try out my games and programs:
Aprone's software

2018-12-26 05:48:36

@7 Thank you for the reply. Someone was able to help me configure the new port and it was successful! Thank you for listing the steps, and that it doesn't automatically connect to the computer.

2018-12-26 07:14:31

BTW don't use functions like alert(string,string) because it blocks all the other loops, therefore it could disconnect players or if is client, could just disconnect from the server

Ivan M. Soto.
Feel free to check out my work and services.
http://ims-productions.com

2018-12-26 11:37:13

I have a question. I am trying to send a packet from one computer to the other, but I don't know what to write when it gets received. I can send them correctly, but what do I type after, if event=event_receive

2018-12-27 03:04:44

Update I have figured out how to do it

2018-12-28 07:23:37

hey, I have a question. could someone make a practice game, that just has a client and server and you can tell the client that when the key is pressed, send message to the server, so I know if reliables are getting through properly, I'm also figuring out multiplayers game in bgt.

2018-12-29 01:29:02 (edited by Zarvox 2018-12-29 01:37:53)

@post 12 I can walk you through it. It's not hard.
The example in the network chapter has 2 while loops in each void, so I split it into 2 different voids between the while loops.
//hosting with IP
void create()
{
show_game_window("Game Server");
tts_voice voice;
if(host.setup_server(6500, 1, 100)==false)
{
speak("Error. The server could not be set up.");
exit();
}
speak("You are now hosting.");
network_event event;
while(true)
{
if(key_pressed(KEY_ESCAPE))
mainmenu();
event=host.request();
if(event.type==event_connect)
{
p.play_stationary("sounds/message.wav",false);
alert("peer joined.", "Peer number " + event.peer_id + " connected from " + host.get_peer_address(event.peer_id) + ".");
//determine that this is player 1
player=1;
//determines who's turn it is
first__turn=true;
second_turn=false;
//the menu for player 1 after connect success
show_game_window("player1");
player1_menu();
}
}
}
Here is the void for the person who will enter your IP
void join()
{
show_game_window("Game Client");
tts_voice voice;
uint server_id=0;  // This is used to store the ID of the remote peer that will be our server.
if(host.setup_client(1, 1)==false)
{
speak("Error. The client could not be set up.");
exit();
}
//speak("Client started.");
speak("Please enter the IP address or host name that you wish to connect to.");
string address=input_box("Address", "Please enter the host name or address to connect to.");
if(address=="")
{
speak("Exiting.");
exit();
}
speak("Connecting, please wait.");
host.connect(address, 6500);
network_event event;

// In this loop, we just wait for either a connect or disconnect event as this is always the first thing that we'll get.

while(true)
{
if(key_pressed(KEY_ESCAPE))
mainmenu();
event=host.request();
if(event.type==event_connect)
{
p.play_stationary("sounds/message.wav",false);
alert("connected", "The connection to " + host.get_peer_address(event.peer_id) + " succeeded!");
server_id=event.peer_id;
//determine player
player=2;
//determine who's turn it is
first_turn=true;
second_turn=false;
show_game_window("player2");
//the menu for player2 after connection successful
player2_menu();
}
if(event.type==event_disconnect)
{
voice.speak_interrupt_wait("The connection to " + host.get_peer_address(event.peer_id) + " failed. Exiting.");
exit();
}
if(key_down(KEY_LMENU) and key_pressed(KEY_F4))
{
host.destroy();
voice.speak_interrupt_wait("Exiting.");
exit();
}
wait(5);
}
}
So, that's how you set up the connection. Now we can start sending and receiving messages. Make sure you write "network host;" at the top of your script. I will post a few examples here.
//send
void send_player1()
{
while(true)
{
//checks for received messages
receive_player1();
if(key_pressed(KEY_SPACE))
{
alert("sending", "You are sending a message.");
host.send_reliable(0, "send1_player1", 0);
//switch turns
first_turn=false;
second_turn=true;
}
if(key_pressed(KEY_RETURN))
{
p.play_stationary("sounds/send.ogg",false);
alert("sending", "You are sending another message.");
host.send_reliable(0, "send2_player1", 0);
//switch turns
first_turn=false;
second_turn=true;
}
}
}
void send_player2()
{
while(true)
{
//check for received messages
receive_player2();
if(key_pressed(KEY_SPACE))
{
alert("sending", "You are sending a message.");
host.send_reliable(0, "send1_player2", 0);
//switch turn
first_turn=true;
second_turn=false;
}
if(key_pressed(KEY_RETURN))
{
p.play_stationary("sounds/send.ogg",false);
alert("sending", "You are sending another message.");
host.send_reliable(0, "send2_player2", 0);
//switch turn
first_turn=true;
second_turn=false;
}
}
}
//receive
void receive_player1()
{
tts_voice voice;
network_event event;
event=host.request();
if(event.type==event_disconnect)
{
host.destroy();
alert("disconnected", "The server died. Exiting.");
exit();
}
if(event.type==event_receive)
{
wait(50);
if(event.message=="send1_player2")
{
alert("receive", "You received a message.");
//switch turn
first_turn=true;
second_turn=false;
}
if(event.message=="send2_player2")
{
p.play_stationary("sounds/receive.ogg",false);
alert("receive", "You received another message.");
//switch turn
first_turn=true;
second_turn=false;
}
void receive_player2()
{
tts_voice voice;
network_event event;
event=host.request();
if(event.type==event_disconnect)
{
host.destroy();
alert("disconnected", "The server died. Exiting.");
exit();
}
if(event.type==event_receive)
{
wait(50);
if(event.message=="send1_player1")
{
alert("receive", "You received a message.");
//switch turn
first_turn=false;
second_turn=true;
}
if(event.message=="send2_player1")
{
p.play_stationary("sounds/receive.ogg",false);
alert("receive", "You received another message.");
//switch turn
first_turn=false;
second_turn=true;
}
I hope that helps you with your projects.