Object Manipulation with Python

New releases and general discussions.

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

Post » Tue May 31, 2011 6:27 am

Try this:
[code:1a1ac7tf]value=40
name="N"+str(value)
System.Create(name,1, 0, 0)
newobj=eval('SOL.' + name)
newobj.x=300[/code:1a1ac7tf]

eval() evaluates any python string. Now you will only have an error if there is no object named "N40".
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue May 31, 2011 3:57 pm

[quote="R0J0hound":1m2irun2]Try this:
[code:1m2irun2]value=40
name="N"+str(value)
System.Create(name,1, 0, 0)
newobj=eval('SOL.' + name)
newobj.x=300[/code:1m2irun2]

eval() evaluates any python string. Now you will only have an error if there is no object named "N40".[/quote:1m2irun2]
It worked!!!!!!! thank you!!
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Previous

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 0 guests