Keeper's Forum Posts

  • 9 posts
  • Better Python scripting integration and help/tooltip.

    Just my 2c.

  • I was the first vote up (I've got about 1.4K rep in stackoverflow)

  • 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.
  • Nice idea!

    You still have to change object names inside your update() if you change them in Construct.

    I guess it's only a matter of taste where to reference the global objects.

    Following your idea I think Construct should append the project path to sys.path automatically so one can write his own modules in the same directory (or directory structure following python standard __init__.py).

    To test the (little) module we discussed in this page I was using this code:

    import sys
    sys.path.append("D:/test")
    [/code:383wvjwf]
    
    Also, a bit OT, is there a way to write Construct plugin using python?
  • Glad to be of help

    But remember to organize your code and try to understand/use classes: they can make your life a lot easier!

    boo.py

    class Boo:
        def __init__(self, Text, System):
            self.Text = Text
            self.System = System
        def sayBoo(self):
            self.Text.Text = "Screen is %d,%d" % (self.System.DisplayWidth, self.System.DisplayHeight)
    [/code:3g03cgkv]
    
    event
    [code:3g03cgkv]
    from boo import Boo
    cboo = Boo(Text, System)
    cboo.sayBoo()
    [/code:3g03cgkv]
  • You can access System using globals() this way:

    def sayBoo():
        Text = vars['Text']
        System = vars['System']
        Text.Text = "Screen is %d,%d" % (System.DisplayWidth, System.DisplayHeight)
    [/code:37kwdjs9]
  • And by taking R0J0hound's idea you can pass around all variables using globals()

    boo.py

    def sayBoo():
        vars['Text'].Text = "Boo!"
    [/code:3onb2jrp]
    event
    [code:3onb2jrp]
    import boo
    boo.vars = globals()
    
    boo.sayBoo()
    [/code:3onb2jrp]
    
    You still have to touch the code if you rename your objects but this way you can cycle on them since globals() returns a dict
  • That's because you can't have cross-module variables in Python.

    The only way (read: very bad hack) to do it is using __builtin__ which is global in all modules:

    boo.py

    import __builtin__
    
    def sayBoo():
        __builtin__.Text.Text = "Boo!"
    [/code:jgr2l8p6]editor:
    [code:jgr2l8p6]
    import __builtin__
    import boo
    
    __builtin__.Text = Text
    boo.sayBoo()
    [/code:jgr2l8p6]
    
    [url=http://stackoverflow.com/questions/142545/python-how-to-make-a-cross-module-variable]See here for reference[/url]
    
    But having to pass around objects like this is [b]very[/b] ugly.
    
    At this point I prefer using parameters:
    
    boo.py
    [code:jgr2l8p6]
    def sayBoo(o):
        o.Text = "Boo!"
    [/code:jgr2l8p6]
    
    editor:
    [code:jgr2l8p6]
    import boo
    
    boo.sayBoo(Text)
    [/code:jgr2l8p6]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Now to insert a script inside an event I have to create the script in the main scope and then drag it inside the event.

    Adding "Insert script" in the event context menu will make adding scripts less tedious and shouldn't add too much complexity to that menu.

  • 9 posts