2019-03-19 00:13:30 (edited by Zarvox 2019-03-19 00:16:21)

I have written a small peer to peer internet game in bgt that is a spin off of time fcrest. It is a nice little game and it can be a blast. However the way I have coded it is an absolute pain in the ass. It supports 4 players, and for each player I have to write the same exact thing. So I have 4 sets of everything. Menus, music selection, and 4 wheels. But that's not the part that is a pain in the ass. The part that is: having to write 12 blocks of the same code to make sure each player receives each player's online action. For example, player 1 receives 2, 3, and 4. Player 2 receives 1, 3, and 4. You get the idea. That's 12 blocks of the same code!

I would like to make a player class containing all of the variables so I only have to write everything once and not 4 or 12 times. However I am not very good with working with classes, and adding online to it makes it even more frightening. What is the best way to go about rewriting this? I may have lots of trouble at the start. The thing I have the most trouble with is assigning the player to that specific player when they connect to the server, but that's a step ahead of what I need to do. If anyone can help me start rewriting this, that would be fantastic!

2019-03-19 13:14:09

I don't know much about this topic, but you could have the online player become player1, and if player1 exists, it's player2... etc.
And then if(player1) then call something or other that just has the code that tells it to show the stats for the others players except the one that is recieving... I D K.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-19 18:16:19

classes are easy enough for me.
Create a player class.
Create a global array of handles.
Put all 4 player classes into the array.
Then, you can run functions defined in the player that you choose.
Here is what I consider to be the difference between classes and functions.
Classes don't really return data, they contain it. I'd like to say a class is sort of a new dimension where you can store data and functions, keep in mind that functions and methods are really, really similar, it's just that a method is a function that is stored inside a class.
When defining a class, you can do:
class player
{
}
Fill up the area between the braces with variable declarations like this:
class player
{
string name;
int turn=0;
}
You probably want a constructor. Let's say you go to a restaurant where you can set up a pizza with you're own ingredients.
To make that pizza, the data is required.
In the same way, a constructor will prepare the pizza, erm, class by using data you give it.
class player
{
string name;
int turn=0;
player(string name, int turn=0) // To create a constructor, you put the name of the class, then a set of () like you do when defining a normal function. Between these, you can tell BGT what variables you expect, just like a normal function too. All you can't do with a constructor is return a value.
{ // Here's the code that goes in a constructor, it'll set up the class.
//this is a way to refer to the current class
this.name=name; // Set the name property of this class to the name property that you passed.
this.turn=turn; // Same as above
}
}
//Now we can test this.
First, to use the class, make it like this.
player me("monkey")
//To declare a class, put the name of the class first, a space, the name you want it to be and then, if you made a constructor for that class player has one then pass it parameters, in this case name.
//Now test the name
void main()
{
alert("The name of me is ", me.name);
}

2019-03-21 20:56:03

@3 I sent you a pm

2019-03-22 08:03:23

Hey, if you want help, you can add me on Skype: isoto680

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

2019-03-22 22:06:05

I added you on skype

2019-03-22 22:18:02

@4
Responded