I need help related to functions and instances

Get help using Construct 2

Post » Sat Jul 25, 2015 6:26 pm

I was making a game that has a complex animation system and everything was going well, until I implemented a second player character.

My system works like this:
I only place the character's hitbox on the layout and at the start of the layout, the event sheet places all the body parts onto it.
Then, every tick, the position and angle of the body parts is updated. I don't use pins because the pins started lagging really badly once I daisy-chained more than one part.

Because I wanted my game to be dynamic and scalable, I used functions to implement the placing and the updating of each character's parts.
I have those 2 functions (stemming from one Function object, does that make a difference?), createCharacter and assembleCharacter, which are called with either 0 or 1 as their parameter, depending on which player they should affect.
The way that works is as follows:
The hitbox has an instance variable playerNumber that corresponds to the instance variables owner in the body parts.
For some reason, assembleCharacter places the pelvis (and thus subsequent parts) on the last called hitbox, even though I tell it to discriminate based on playerNumber and owner.

Here is the file:
https://www.dropbox.com/s/d5vf9ltlkstqrte/mortifyingProblem.capx?dl=0
I've removed almost everything that is not related to the problem. There may still be some residual behaviors and instance variables that shouldn't affect anything though.

I've also set the event sheet up so it is observable what is happening. In the first 4 seconds, the assembleCharacter function is alternately called with 0 and 1 as its parameter each second, after that both are called every tick.

I've been working on fixing this for close to 24 hours. I would be very thankful for any help.

Edit: I think I have enough reputation to post the file now.
B
4
S
1
G
1
Posts: 6
Reputation: 337

Post » Sat Jul 25, 2015 7:32 pm

Sorry for the bump, but I now have enough reputation to post the link to the file. See the post above.

Thank you in advance.
B
4
S
1
G
1
Posts: 6
Reputation: 337

Post » Sat Jul 25, 2015 8:04 pm

your functions seems well defined.
Actually, I don't understand what you want to do. How should be the character? how should it move?
B
8
S
1
Posts: 76
Reputation: 628

Post » Sat Jul 25, 2015 8:32 pm

In the file I provided, for demonstration purposes, it only places two pelvises (one for each character) rather than all of the body parts.
The problem is that the function assembleCharacter for some reason takes all the instances of pelvis and places them on one hitbox, rather than just taking the one specified through the parameter and placing it on the corresponding hitbox.
B
4
S
1
G
1
Posts: 6
Reputation: 337

Post » Sat Jul 25, 2015 8:44 pm

and what is the grey square in the middle?
I think you should add a variable to differentiate all the instances of pelvis, then you could use this variable in the function to place them at different positions.
An other way to do what you want is the "pin" behavior, which is designed exactly for these situations, I don't know why your pins was lagging.
B
8
S
1
Posts: 76
Reputation: 628

Post » Sat Jul 25, 2015 9:06 pm

In event 9, when you pick the correct pelvis and set it's position you need to refer to either the object or the family in both the condition and action. You can't mix them.

You can have pick pelvis -> set pelvis position or pick character -> set character position but you can't have pick character -> set pelvis position. In that case you're setting the position of all pelvis objects not just the ones picked by the family condition.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Sat Jul 25, 2015 9:42 pm

Thank you, ramones. I was tinkering around just minutes ago and found that it worked if I used the direct object type.
You confirmed it, though.
B
4
S
1
G
1
Posts: 6
Reputation: 337

Post » Sun Jul 26, 2015 8:13 am

You might also want to look at containers:

https://www.scirra.com/manual/150/containers

If used correctly this will make referencing the objects that should reference eachother much easier..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 49 guests