Multiplayer/asset management questions.

I'm trying to implement local multiplayer. However, I'm having a difficult time. I'm not sure how to move forward.

I have a player object that I would like to use for 1-4 players.

Can I use the same object when creating additional players? Or do I need to create additional player objects for each player? I was trying to use an initialization script to create obj_player 1 to 4 times, and pass variables to a controls script in the obj_player step event. I've also created an obj_player_parent, which contains player variables.

I'd post some code, but it's not working and quite messy! I'm not sure I'm in the right ballpark and kindly request some guidance/examples.

Is it best to run everything from the parent object? For example, the directional taps for combos, etc? I've tried to logically write the process on paper to pass them to a controller script, but I'm lost! I hope I explained things clearly. Thanks!
 

Phil Strahl

Member
Hm, when you set up your game that it never assumes that there is only one obj_player instance, then that's a good start. Another thing I would do is to read a player's input through an input controller, so that an instance would only check, for example, if controller.left_down = true or if controller.fire_down = false, etc. That way you can have one input controller object that reads gamepad/keyboard input to set its internal flags accordingly and another that parses the network input. To the player object(s) it wouldn't matter from where its controller gets the command, because all it would look for are flags in the associated controller object.

For example here's some pseudo-code what the ctrl_input object could look like
Code:
// create event
is_left = false
is_right = false
is_up = false
is_down = false;
// etc.
Code:
// step event
switch on the desired input mode
{
  case input_mode_keyboard:
  {
    is_left = keyboard_check(ord("A"))
    is_right = keyboard_check(ord("D"))
   // etc.
  } break;
  case input_mode_controller:
  {
    if (gamepad_axis_value(0, gp_axislh) >= 0)
    {
      is_right = true
      is_left = false
    } else {
      is_right = false
      is_left = true
    }
    // etc.
  } break;
case input_mode_network:
{
  // fill the booleans in an async network event from the received data instead
} break;
}
// etc.
Code:
In the player event you just specify the corresponding input_control 
[code]
// player create event
input_controller = instance_create_depth(0,0,0,ctrl_input_gamepad)
//step event
Code:
if (input_controller.is_right)
{
 x += 2;
}
// etc.
Of course that's just ugly code and you can have individual objects for the different input modes, etc. but I hope you get the idea behind it :) I hope this helps!
 
Top