0 Favourites

Python picking help!

This forum is currently in read-only mode.
  • I am working on making the 2 player net pong game be four player but don't want to have to do it the tedious way of duplicating code for each player (in this case it is not really tedious, but wouldn't be practical for a 20+ person game which is the point of the exercise):

    Here is Python function that updates the player position only if the player number is not yourself.

    def Network_move(self, data):
          if ((data['player'] == 1) and (System.globalvar("myPlayer") != 1)):
          elif ((data['player'] == 2) and (System.globalvar("myPlayer") != 2)):
    For example, to make the above support 4 players I would have to double the code. Instead I would like to do something like (with all players in a Family) :
    if data['player'] != System.globalvar("myPlayer") :
       Pick players by players PV == data['player']
       players.SetPosition(data['playerx'],data['playery']) [/code:34szvw2l]  
    So something like the above where you pick a player based on their Private Variable (or something else) being the correct match.  Now the above three or so lines are sufficient to handle 2, 4, 50 players.
    Any ideas?
  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Instead of using different objects per remote player, use just one :"players".

    if data['player'] != System.globalvar("myPlayer") :
       for w in players:
          if(w.Value("player") == data['player']):
    But until "pick.Value("player")" works use the function object to get the private variable:
    + Function: On function "PVplayer"
    + players: Unique ID is Function.Param(1)
    -> Function: Set return value to Sprite.Value('player')
    and the code would become:
    [code:303ifi0x]if data['player'] != System.globalvar("myPlayer") :
       for w in players:
          if(Function.Return == data['player']):
  • Thanks Rojo! That worked. Now I'm trying to do it just by the index to improve performance.

    Looks like I might just be able to do a:

    players[data['player'] - 1].SetPosition(data['playerx'],data['playery'])

    Thanks for the help! It's great having more Python guys around here.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)