Triggered conditions

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Sat Feb 13, 2010 8:01 pm

Ok so when a state changes from true to false or from false to true I want to generate a triggered event. I know that I use the flag CND_TRIGGERED and the generateEvent() call. but what would the ADDCND function look like because the event is generated in the switch action.

[code:13g8hh22]if( strcmp(tempState.name, tempString) =0)
{
if(tempState.state)
{
tempState.currentState = false;

// call the true to false trigger here

}
else
{
tempState.currentState = true;
// call the false to true trigger here
}


}[/code:13g8hh22]
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Sat Feb 13, 2010 9:48 pm

[code:1gkjhzbu]if( strcmp(tempState.name, tempString) =0)[/code:1gkjhzbu]
This line is wrong, you need == to compare to zero. Otherwise you're assigning 0 to the result of strcmp, but it should actually give you a compile error.

I'm not sure I understand your question. You call GenerateEvent() to trigger an event, and the event you trigger must have the CND_TRIGGERED flag. Which part of this are you having trouble with?

Edit: Don't forget you can look at what other plugins do on SVN. Here's a triggered condition in Sprite:
[code:1gkjhzbu]ADDCND("On any animation finished", "Animations", "%o %n: Any animation finished", &ExtObject::cTrigger, "AnyAnimFinished", CND_TRIGGERED);[/code:1gkjhzbu]

cTrigger just returns true:

[code:1gkjhzbu]long ExtObject::cTrigger(LPVAL params)
{
return true;
}[/code:1gkjhzbu]

...because it should always run the event when GenerateEvent is called.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508

Post » Sat Feb 13, 2010 10:41 pm

How do i distuguish between the two triggered events in the generate event call?


[code:3bbpr97n]void ExtObject::aSwitchState(LPVAL params)
{

for( int i = 0; i< (int) stateVector.size(); i++)
{
state tempState = stateVector[i]
CString tempString = params[0].GetString();

if( strcmp(tempState.name, tempString) == 0)
{
if(tempState.state)
{
tempState.currentState = false;
GenerateEvent(); // how do the GenerateEvent() calls distiguish between the two?
// call the true to false trigger here

}
else
{
tempState.currentState = true;
GenerateEvent();
// call the false to true trigger here
}


}


}
}[/code:3bbpr97n]
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Sun Feb 14, 2010 1:26 am

...you haven't added any parameters to GenerateEvent! What made you think you call it like that? It takes three parameters, again using Sprite as an example:
[code:11c7mqmh]pRuntime->GenerateEvent(info.oid, 7, this);[/code:11c7mqmh]
The first and last parameters are always 'info.oid' and 'this'. The second parameter is the zero based index of the condition to trigger (0 is the first condition added by ADDCND, 1 is the second etc).

I'd really recommend downloading the other plugin/behavior sources and seeing how they do things. You'll learn a lot about how the SDK works that way.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508

Post » Sun Feb 14, 2010 3:05 am

Dont worry Im not calling them that way :lol: lol I know they take params I looked at the definitions. It took me a bit to download the SVN i was just asking about how the generateEvent function knew which triggered event to trigger. So I would call the GenerateEvent(info.id, 3, this) if it is the 3rd condition defined in the ACETable.cpp right?
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Sun Feb 14, 2010 2:34 pm

the id of the triggered condition is it's order in the ACE Table,
first condition is 0, and you count all conditions, triggered or not.
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Feb 14, 2010 2:37 pm

It's zero based so 3 would refer to the fourth condition added by ADDCND.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests