Pick Created in Python

For questions about using Classic.

Post » Thu Jun 16, 2011 5:40 am

So if I create an object with events, say, Sprite, I can immediately do Sprite.Value('Var')=stuff, without doing any additional picking since the created object is picked.

Is this the same with System.Create("Sprite") in python? If not, is there some way to pick the object?
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu Jun 16, 2011 11:09 am

You can select the newly created sprite in python with:
[code:17ps0prp]SOL.Sprite[/code:17ps0prp]
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Thu Jun 16, 2011 3:20 pm

Thanks!
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Fri Jun 17, 2011 4:50 am

So I tried this code:

SOL.Sprite.Value('Home')=System.globalvar("tempHome")

and I get the message:

SyntaxError: can't assign to function call
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Fri Jun 17, 2011 6:22 pm

You need to use SetValue:
SOL.Sprite.SetValue('Home', System.globalvar("tempHome"))
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Sat Jun 18, 2011 1:06 am

Oh I see. Is that construct-specific? If so, is there a good Construct Python documentation available? I checked the wiki and there's not a whole lot there.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Sat Jun 18, 2011 1:46 am

As always, the best recommendation is Silent Cacophony's Python Shell:

[url:sbleb9p1]http://www.scirra.com/forum/viewtopic.php?f=8&t=6158&p=50287[/url:sbleb9p1]

:)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Jun 20, 2011 6:13 am

That's kinda neat. I tried messing with it but I'm not sure it still does what I want, but maybe I don't get it.

For example, let's say I want to set a color filter.

I can do something like dir(System) to find that, then dir(System.SetFilter), but I stil don't get how to use SetFilter in python. E.g. what arguments does it take, and what syntax would you put them in, stuff like that (I do need to know how to do something like Sprite.SetFilter(Args) in python btw :) ) Seems like the default editor for scripting also fills in the commands on the bar on the right so I'm not sure exactly what that program is meant for.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Mon Jun 20, 2011 5:03 pm

The python functions take the same number of arguments as their event counterparts. So events are the reference.

If the argument in events is a color then in python it is in this form:
System.rgb(255,128,0)
so to set the filter of Sprite to red:
Sprite.SetFilter( System.rgb(255,0,0) )

If the argument in events is a object then in python it is the OID of that object.

If the argument in events is a combo box then in python it is the index of the list, starting from zero.
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Mon Jun 20, 2011 6:05 pm

Just a (non-related) thought/suggestion, but maybe it would be beneficial to have all python related questions and answers under their own sub-forum, for easier accessibility. It would certainly make finding what we need much simpler, rather than trawling though generic help.

As I said, just a thought/suggestion/wishful thinking.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,846
Reputation: 48,293

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests