0 Favourites

How do I handle a local multiplayer player loop?

  • Hi

    I'd like to know what is the best way to handle a local multiplayer player loop?

    I want to order my code in groups for readability.

    Something like this:

    Multiple For each loop can kill performances?

    Or Something like this:

    I think this is the best because it only runs the loop once, but what about the nested groups? Is this better?

    Thank you!

  • I don't think there's any difference at all between the two, but theoretically the second one is using less loop. Personally I'd go for the 2nd one, because it is easier to read.

  • Either way is probably not a good idea. The engine has built-in for-each loops and using an explicit loop is only necessary in certain circumstances. See common mis-used events and gotchas

  • DuckfaceNinja and Ashley

    Thanks for your answer, I already tried without a loop but get stuck while managing multiple input for players:

    Is this possible without a loop?

    Also for moving the character:

    Is this also possible without a loop?

  • You should stick with a loop, but loop through gamepads, and leave your player logic outside of said loop.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Magistross

    I tried but without success, it seems that

    does not work out of a loop.

  • I tried but without success, it seems that

    does not work out of a loop.

    I don't get the total situation here, but have you tried using binary instead of boolean? It is known that boolean is true=1, false=0, but I'm not sure whether it still stay as 1 and 0 in the MP sync, it might return 0 all the way. Don't take my word for it, I just want to suggest using binary instead, as normally used in the official example.

    If the gamepad use sensitive input, it'll probably better sync variable instead.

  • Indeed it won't. System's condition "compare two values" won't do any implicit looping, and it'll simply pick the first Player object in the SOL to evaluate itself. For the getbit() function, you should use "Pick by evaluate", implicit looping through all Player in the SOL will then occur.

    @DuckfaceNinja It's local multiplayer, so there's no syncing issue. And his TRUE expression is probably a global constant with 1 for its value. There is nothing more binary than using the getbit() function !

  • DuckfaceNinja thanks for your answer

    I'm not using the MP plugin, but I'm using the same binary system for inputs for handling multiple input methods (Keyboard, Gamepad and Touchscreen)

    (INPUT_LEFT = 0, INPUT_RIGHT = 1, ...) and TRUE = 1, FALSE = 0

  • System expressions don't pick anything, so that's one case where you genuinely need a for-each loop.

  • Magistross

    Wow, thanks "Pick by evaluate" actually works! But is it "fastest" than the "god" for each loop?

  • I was about to ask Ashley the same question. I guess we'll have to wait and see !

  • Lol no wonder I didn't get the situation, I misread the situation haha my bad.

    TRUE expression is probably a global constant with 1 for its value.

    Hah! This is why I like to engage in a discussion, I'd get to learn things! I always assumed TRUE/FALSE is a value, never thought that it is actually a CONSTANT for value 1/0. That opened my eyes!

  • DuckfaceNinja Well let me open them a bit more if I may. true/false are actually values of the "boolean" type. However, Construct2 support for that particular type is quite limited. For example, the getbit() expression return type is number, 0 or 1, when in theory, a bit can only be true or false. But that's alright, since an implicit conversion of a number to a boolean is quite simple : 0 is false, everything else is true. It's also common practice to consider "true" to have a numeric value of 1, hence the creation of global constants of FALSE = 0 and TRUE = 1.

  • DuckfaceNinja Well let me open them a bit more if I may. true/false are actually values of the "boolean" type. However, Construct2 support for that particular type is quite limited. For example, the getbit() expression return type is number, 0 or 1, when in theory, a bit can only be true or false. But that's alright, since an implicit conversion of a number to a boolean is quite simple : 0 is false, everything else is true. It's also common practice to consider "true" to have a numeric value of 1, hence the creation of global constants of FALSE = 0 and TRUE = 1.

    Thanks! It's good to have knowledge sharing like this every now and then.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
224 49,523
ThePhotons's avatar
ThePhotons
Unread hot topic
190 41,427
juantar's avatar
juantar
Unread hot topic
163 20,242
iBarin's avatar
iBarin