Object Manipulation with Python

New releases and general discussions.

Post » Wed Aug 25, 2010 10:55 am

Luomu, that will work no problem. Also you can eliminate the "objref" variable and do it directly:
[code:32mlmfm3]System.Create('Sprite', 1, 0, 0)
SOL.Sprite.x =300[/code:32mlmfm3]
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon Aug 30, 2010 4:11 pm

[quote="R0J0hound":2btwhewz]Luomu, that will work no problem. Also you can eliminate the "objref" variable and do it directly:
[code:2btwhewz]System.Create('Sprite', 1, 0, 0)
SOL.Sprite.x =300[/code:2btwhewz][/quote:2btwhewz]

So, can this be used in the fashion of the py fix plugin?

Is there a len() operator of any fashion?

Is this correct?

[code:2btwhewz]
import random

for x in range(10):
System.CreateByName("spr", 1, random.randint(10,400), random.randint(10,400))

for i in range(10):
spr[i].X = random.randint(10,400)
spr[i].Y = random.randint(10,400)
[/code:2btwhewz]

Just wondering. I couldn't figure out how to use the SOL class for iterating, but the above works (not sure if it's intentional or not, or if that was always functional).
B
3
G
2
Posts: 31
Reputation: 737

Post » Mon Aug 30, 2010 7:11 pm

SOL stands for "selected object list" and it allows you to access the objects picked via events. When an object is created it becomes the only picked object of that type. Also the created object will not be accessible via "Sprite[index]" until the next frame.

Say there are no instances of the "Sprite" object.
[code:25n0pb6b]System.Create('Sprite', 1, 45, 45)
Sprite.x=22 #this will cause an index error[/code:25n0pb6b]
[code:25n0pb6b]System.Create('Sprite', 1, 45, 45)
SOL.Sprite.x=22 #this will work[/code:25n0pb6b]

Your example will create 10 sprites and move the first 10 sprites not the created ones.

Ideally new objects are modified right after each are created. You can however create multiple objects save their references and modify them later.
[code:25n0pb6b]import random
newObjs=[]

for x in range(10):
System.CreateByName("spr", 1, random.randint(10,400), random.randint(10,400))
newObjs.append(SOL.spr[0])

for obj in newObjs:
obj.X = random.randint(10,400)
obj.Y = random.randint(10,400)[/code:25n0pb6b]

[quote:25n0pb6b]Is there a len() operator of any fashion?[/quote:25n0pb6b]
len(Sprite) returns the number of Sprite objects excluding objects created that frame.
len(SOL.Sprite) returns the number of picked Sprite objects. It will return 1 after a sprite object is created.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon Aug 30, 2010 7:42 pm

I suppose I don't see how that is a list, though. You're saying I have to make my own list and store the references returned by SOL... so is it a misnomer? Should it be called LastObjectRef instead?

A list would be.. a list. Not a single reference after 10 calls of Create*()

It would probably be prudent to do a write up on all the functionality of SOL... lest we all sit around trying to figure out it's actual functionality. As it stands, the Lucid's plugin is more useful for picking objects. I must be confused, I thought this was proper built in support for that bandaid fix.

As it stands it seems like a wrapper to get the last object created, and not a list at all.

Surely I am mistaken?
B
3
G
2
Posts: 31
Reputation: 737

Post » Mon Aug 30, 2010 9:28 pm

In a nutshell
"Sprite" is a list of all the sprite instances.
"SOL.Sprite" is a list of all the picked sprite instances.

The reason "System.Create()" picks only the new object is because that's what happens in events.

Here's an example:
[url:10qiqr11]http://dl.dropbox.com/u/5426011/examples/pythonSOL.cap[/url:10qiqr11]
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon Sep 06, 2010 1:04 pm

I ran into a problem while trying to play with that new Python functions.
[code:3r40wsxi]System.Create('Sprite',1,random.randint(200,400),random.randint(200,400))
SOL.Sprite.Filter=System.RGB(255,255,255)[/code:3r40wsxi]
I simply wanted to set the colour filter of newly created sprite, but unlike setting the position it thrown an error "NoneType object is not callable"
B
5
S
1
G
2
Posts: 70
Reputation: 1,140

Post » Mon Sep 06, 2010 8:47 pm

[quote:eq5613lp]it thrown an error "NoneType object is not callable"[/quote:eq5613lp]
System.RGB(255,255,255)
is incorrect, it's:
System.rgb(255,255,255)

Notice the lowercase.

-cheers
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue Sep 07, 2010 10:39 am

GAH!
I must explain myself: built in Pyhton editor suggested usage of "RGB"(caps) i thought that it was correct.
B
5
S
1
G
2
Posts: 70
Reputation: 1,140

Post » Tue Sep 14, 2010 9:42 am

It really useful for me, thanks for the info that you guys have been discussing.
B
1
G
2
Posts: 1
Reputation: 627

Post » Tue May 31, 2011 5:20 am

[quote="R0J0hound":2fstjl4k]Luomu, that will work no problem. Also you can eliminate the "objref" variable and do it directly:
[code:2fstjl4k]System.Create('Sprite', 1, 0, 0)
SOL.Sprite.x =300[/code:2fstjl4k][/quote:2fstjl4k]

And how do I get the new created object in the condition below?
[code:2fstjl4k]
value=40
name="N"+str(value)
System.Create(name,1, 0, 0)[/code:2fstjl4k]

if I try and use:
[code:2fstjl4k]
SOL.name.x=300[/code:2fstjl4k]

It ill show an error(AttributeError:class SOL has no attribute 'name')
and I really need to get the object with a script like that..
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

PreviousNext

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 3 guests