How do I handle a local multiplayer player loop?

Get help using Construct 2

Post » Tue Nov 04, 2014 3:19 am

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:
Image
Multiple For each loop can kill performances?

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

Thank you!
B
6
S
2
Posts: 24
Reputation: 737

Post » Tue Nov 04, 2014 3:34 am

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.
B
28
S
8
G
4
Posts: 553
Reputation: 4,914

Post » Tue Nov 04, 2014 1:21 pm

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
Scirra Founder
B
387
S
230
G
87
Posts: 24,245
Reputation: 192,210

Post » Tue Nov 04, 2014 3:37 pm

@DuckfaceNinja and @Ashley

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

Image
Is this possible without a loop?

Also for moving the character:
Image
Is this also possible without a loop?
Last edited by RootKernel on Tue Nov 04, 2014 4:16 pm, edited 1 time in total.
B
6
S
2
Posts: 24
Reputation: 737

Post » Tue Nov 04, 2014 3:50 pm

You should stick with a loop, but loop through gamepads, and leave your player logic outside of said loop.
B
67
S
27
G
24
Posts: 968
Reputation: 18,571

Post » Tue Nov 04, 2014 4:16 pm

@Magistross

I tried but without success, it seems that Image does not work out of a loop.
B
6
S
2
Posts: 24
Reputation: 737

Post » Tue Nov 04, 2014 5:36 pm

RootKernel wrote:I tried but without success, it seems that Image 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.
B
28
S
8
G
4
Posts: 553
Reputation: 4,914

Post » Tue Nov 04, 2014 5:46 pm

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 ! ;)
B
67
S
27
G
24
Posts: 968
Reputation: 18,571

Post » Tue Nov 04, 2014 5:52 pm

@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
B
6
S
2
Posts: 24
Reputation: 737

Post » Tue Nov 04, 2014 5:53 pm

System expressions don't pick anything, so that's one case where you genuinely need a for-each loop.
Scirra Founder
B
387
S
230
G
87
Posts: 24,245
Reputation: 192,210

Next

Return to How do I....?

Who is online

Users browsing this forum: Magistross, tarek2 and 2 guests