[HELP] Call last created object in Python

For questions about using Classic.

Post » Mon May 30, 2011 6:26 am

Hey everyone..

I searched for this around here and found something about the SOL object, but to be honest not sure if this is really what I'm looking for..
I'm with a little question about accessing a newly created object using python and change their values... example..
I have a script that creates a new sprite object..
then I want this new sprite have the variable ('test') the value 10.

So how do I call this object after created?
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Mon May 30, 2011 11:45 am

Yes, SOL is what you want. The post from ROjohound in this thread is what you are looking for:

viewtopic.php?f=2&t=7086&p=56119&hilit=python+sol#p56119
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Mon May 30, 2011 8:31 pm

As always, thanks scidave!

This SOL object is py.csx plugin from lucid right?

The Construct is crashing when I try to execute this script, what might be the problem?
[code:2garosdq]
id=System.globalvar('GAME ID')
query="""SELECT * FROM PLAYER_ITEMS WHERE PLAYER_ID = %s"""
cursor.execute(query,(id))

results=cursor.fetchall()
for row in results:
value=row[1]
value1=row[2]
value2=row[3]
value3=row[4]
value4=row[5]
value5=row[6]
itemname="n"+str(value)
System.Create(itemname,2,value1,value2)
objref=py.GetSOL(itemname)
objref[py.SOLi].SetValue('R',value3)[/code:2garosdq]
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue May 31, 2011 5:33 am

Here is a more basic example of what I'm trying to do..

[code:3vd45ghj]
value=40
name="N"+str(value)
System.Create(name,1, 0, 0)[/code:3vd45ghj]

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

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.. cuz the value changes and so the objects created.


EDIT: It's NOW WORKING Thanks to R0J0hound!
Had to use eval()
here's how:
viewtopic.php?f=2&t=7086&p=74276#p74254
B
30
S
6
G
5
Posts: 433
Reputation: 6,061


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest