Artificial Life gadget using Python

For questions about using Classic.

Post » Thu Sep 09, 2010 11:09 am

Hey all, im now experimenting with Alife game. Im trying to make my "Cell's" reproduce and mutate wich is represented by colour filter changed by random number.
This is roughtly what i want to achieve:
[code:2g5y6fog]If Cell has enough eneregy
get Cell colour
Spawn new cell
set new cell colour to parent cell colour +random[/code:2g5y6fog]

The script i made so far goes like that:
[code:2g5y6fog]import random
d=Cell.Value('color')
r=System.GetRed(d)
b=System.GetBlue(d)
g=System.GetGreen(d)
Cell.SpawnObject('Cell',1)
a=SOL.Cell
a.Filter=System.rgb(r+random.randint(-10,10),g+random.randint(-10,10),b+random.randint(-10,-10))
a.SetXY(random.randint(0,10),random.randint(0,10))
[/code:2g5y6fog]
but when it is executed it generates error :
[code:2g5y6fog]File 'string' line 1061(??)
def swap values (self,p0,p1,p2,p3)
syntax error invalid syntax
[/code:2g5y6fog]
I dont understand why it showing me that because I didnt typed that nowhere.
What i'm doing wrong ?
B
5
S
1
G
2
Posts: 70
Reputation: 1,140

Post » Thu Sep 09, 2010 1:06 pm

I can't reproduce your error so if you post your cap me and others can try to solve it.

The only thing I noticed is that you use
[code:bn3vdkc7]a.Filter = ...[/code:bn3vdkc7]
by trials and error (and I read about it on the forum) you should use .SetXXXXX to set any value
[code:bn3vdkc7]a.SetFilter(...)[/code:bn3vdkc7]

Trying to of any help I created a simple cap that creates a 20x20 grid of TiledBackground and then modify the Filter of each one by a random value.
That's my code:

-> Start of layout -> script:
[code:bn3vdkc7]
for x in range(20):
for y in range(20):
System.Create("Cell", 1, x*25, y*25)
[/code:bn3vdkc7]

-> Always -> script:
[code:bn3vdkc7]
from random import randint

def cb(x):
if x < 0:
return 0;
if x > 255:
x = 255
return x

for i in range(Cell.Count):
cell = Cell[i]
color = cell.Filter
r = cb(System.getred(color) + randint(-5,5))
g = cb(System.getgreen(color) + randint(-5,5))
b = cb(System.getblue(color) + randint(-5,5))
cell.SetFilter(System.rgb(r,g,b))
[/code:bn3vdkc7]

May be this will help you.
B
1
G
2
Posts: 9
Reputation: 643

Post » Thu Sep 09, 2010 3:42 pm

B
5
S
1
G
2
Posts: 70
Reputation: 1,140

Post » Thu Sep 09, 2010 6:47 pm

[quote:11964ur1]File 'string' line 1061(??)
def swap values (self,p0,p1,p2,p3)
syntax error invalid syntax[/quote:11964ur1]
If you remove the S plug-in from your project it will eliminate that error.

Some other fixes:
r=System.getred(d)
b=System.getblue(d)
g=System.getgreen(d)
Cell.SpawnObject('Cell',1,0)

Add this event to initialize python at the start of layout:
+ System: Start of layout
-> System: Run Script ("")
Construct will crash if python isn't initialized and ~700 objects are created.

Hope that helps.
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

Post » Thu Sep 09, 2010 7:25 pm

Thanks Rojo, it helped alot.

Another problem came out :
It seems that only one cell at a time can reproduce.
B
5
S
1
G
2
Posts: 70
Reputation: 1,140


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests