Python and behaviors

For questions about using Classic.

Post » Sun Mar 28, 2010 1:24 am

Can Python access and/or modify behaviors? From what I've tried so far it does not seem to be possible.

For example, if I want to change sprite[CustomMovement].XSpeed, how would I set that or get the value of in script?

Thanks!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sun Mar 28, 2010 7:03 am

that's correct.

you can still use python though, with the python() expression
Sprite - Custom Movement - Set X Speed to:
[code:2c7nxwqa]python("myspecialequation(1,5,x,y)+math.cos(12)/Sprite.Width")[/code:2c7nxwqa]

if it gets messy, or you want to tweak it alot:
an alternative is to set a python variable:
[code:2c7nxwqa]XSpeed=myspecialequation(1,5,x,y);[/code:2c7nxwqa]

Then in the event sheet:
Sprite - Custom Movement - Set X Speed to:
[code:2c7nxwqa]python("XSpeed")[/code:2c7nxwqa]

for retrieving the value of Sprite[CustomMovement].XSpeed, the only thing I can think of is to set a private or global variable to Sprite[CustomMovement].XSpeed just before the script in the eventsheet, then using the variable in your script in place of the expression
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Mar 30, 2010 12:39 am

Thanks for the example! I figured there would be syntax issues since the way Construct specifies Behaviors would clash with Python syntax, so this is a pretty good work around.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests