Artificial Life gadget using Python

This forum is currently in read-only mode.
From the Asset Store
High quality sound effect pack, in the following categories: computer voice
  • 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:

    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 ?
  • 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

    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.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • [quote:11964ur1]File 'string' line 1061(??)

    def swap values (self,p0,p1,p2,p3)

    syntax error invalid syntax

    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.

  • Thanks Rojo, it helped alot.

    Another problem came out :

    It seems that only one cell at a time can reproduce.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)