XAudio2 Issues

For questions about using Classic.

Post » Tue Jul 27, 2010 7:13 am

I'm wondering if there is a bug with construct 0.99.91. Basicly, the following code doesn't work:

C: On Left Clicked on mutesprite
Inverted C: Master is Muted (an XAudio2 function)
A: Set Master Muted (an XAudio2 function)
A: mutesprite: Set animation to "Animation 1"

C: On Left Clicked on mutesprite
C: Master is Muted (an XAudio2 function)
A: Set Master Unmuted (an XAudio2 function)
A: mutesprite: Set animation to "Default"

C = Condition
A = Action

It works as long as you use any keyboard condition except for the left mouse click. Any ideas as to why? If it is a bug, will someone report it onto the bug tracker for me since I don't have a sourceforge account. Thanks.

BTW-Why isn't there a condition for seeing if the Master is muted? Also, would it be "a XAudio2" or " an XAudio2"?

Edit: The problem seems to occur whenever the keyboard condition for both events is the same. For example, replace both left mouse clicks with m and you have the same problem.
B
2
G
2
Posts: 48
Reputation: 746

Post » Tue Jul 27, 2010 11:10 pm

On left clicked is a trigger, so you don't really want to have both in there. You're only going to have success with one trigger of the exact same type in a given frame. Just make the secondary conditions into sub-events (looks like you can get away with the second one being an "else" here, too).
B
2
S
1
G
2
Posts: 48
Reputation: 896

Post » Wed Jul 28, 2010 12:34 am

This is often asked. I've started a thread, that may help understanding the work flow within Construct and why branching is the way to solve problems like this.
viewtopic.php?f=8&t=6880
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Jul 28, 2010 1:55 am

Hi. While tulamide provided a nice write-up of the general problem here, I thought I'd reiterate it about your specific problem as well. The thread that tulamide made is definitely worth a read, though, so check that out as well.

[code:3trxyti0]C: On Left Clicked on mutesprite
Inverted C: Master is Muted (an XAudio2 function)
A: Set Master Muted (an XAudio2 function)
A: mutesprite: Set animation to "Animation 1"

C: On Left Clicked on mutesprite
C: Master is Muted (an XAudio2 function)
A: Set Master Unmuted (an XAudio2 function)
A: mutesprite: Set animation to "Default"[/code:3trxyti0]

Using tulamide's 'snapshot' analogy, the thing to note here is that ALL 'On Left Clicked' conditions will be true for the one tick in which they are polled after the left click takes place. This is by design, so that you can have more than one condition testing for it, though it's usually not necessary.

However, changes that you make are generally instantaneous. So, your first event actually sets up the second to be true as well, effectively canceling each other.

The best way to do that is to check for the left click, then in a sub-event of that, check the 'muted' state, carrying out the appropriate actions if so. It's important that both conditions can't be true in the same tick, so the system->else condition comes in handy for that. Put the second set of actions under an else condition, and there is no way that both sets of actions can be run in the same tick. That's also why it worked if you used different keys for each, as that kept both from being true in the same tick.

[code:3trxyti0]C: On Left Clicked on mutesprite
---C: Master is Muted (an XAudio2 function)
---A: Set Master Unmuted (an XAudio2 function)
---A: mutesprite: Set animation to "Default"
---C: Else
---A: Set Master Muted (an XAudio2 function)
---A: mutesprite: Set animation to "Animation 1"

C = Condition
A = Action
--- = Sub-event (one level of indentation)[/code:3trxyti0]

That would look just as tulamide's good and easy 'hello world' example in the other thread, if it's hard to tell the structure from the text example.

[quote:3trxyti0]
BTW-Why isn't there a condition for seeing if the Master is muted? Also, would it be "a XAudio2" or " an XAudio2"?[/quote:3trxyti0]

I didn't see an expression for checking the muted state either. Maybe it was overlooked.

And I've always gone with 'an' with words that start with a vowel sound, and I think of that name as 'ex audio two'. ;)
B
3
S
2
G
2
Posts: 187
Reputation: 1,449


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests