Python as an array(?)

This forum is currently in read-only mode.
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I was thinking it might be useful to use the python script editor with its copy and paste ability as a way to import an array into Construct with having to import an external file.

    The problem is how to get things hashed out correctly...

    Apparently ampersand doesn't concatenate the same way in python.

    + System: Start of layout

    -> Array: Set size to 4 x 1 x 1

    x1=5
    x2=3
    x3=3
    x4=1[/code:xua455tx]
    + Array: For Each element
    -> Array: Set index Array.CurrentX to python("x&Array.CurrentX")
    
    + System: Always (every tick)
    -> Text: Set text to Array (1)
    
    Any ideas on how to get them to play nice with each other?
    
    Edit:
    oops
    This seems to work.
    python("x"&Array.CurrentX)
    
    Any way I guess this is no longer a question but a statement instead... Move if you like
  • Oooh, Python integration...

    There are numerous other ways to do such a thing, as well. For example, you can use a python list as an array. Here is a variation of the above, which will automatically set the Construct Array size, if you add or remove elements in x:

    + System: Start of layout

    x = [5, 3, 3, 1, "No", "Yes"]
    Array.SetSize(len(x), 1, 1)
    for index, value in enumerate(x):
       Array.SetAtX(index + 1, value)[/code:26ee4b3r]
    
    + System: Always (every tick)
    -> Text: Set text to Array (1)
    
    No real error checking, though...
  • I just taught my self python last week but as of yet not tried it with Construct. Objects rock in python.

    Can you do an example with the Python array in construct as a Cap file so I can see you you added them together?

  • I've been using relatively unused "at" or array access operator. It is fairly simple and requires no python.

    + System: Start of layout
    -> Array: Set size to 3 x 1 x 1
    	+ Array: For Each element
    	-> Array: Set index Array.CurrentX to {"one","two","three"}@Array.CurrentX
    [/code:1uak4www]
  • Opps sorry R0J0hound. I didn't need a construct array I was just looking at how to implement my new python skills into Construct. Reading wiki now.

  • Interesting info, R0J0hound. Thanks.

    I just taught my self python last week but as of yet not tried it with Construct. Objects rock in python.

    Can you do an example with the Python array in construct as a Cap file so I can see you you added them together?

    Well, I'm still learning, myself, so sorry if I got a bit scattered with my example... Here's an example of some ways to integrate Python into something like the original example:

    http://dl.dropbox.com/u/5868916/PyStuff.cap

    It just shows different ways to access objects using a combination of Construct events and Python scripting. The example also lets you modify the values on the fly by editing the EditBox widgets in the upper left. It can get a bit complicated in some cases, especially when picking is involved. Best to stick with Construct actions when you need to pick.

    It should be noted that all objects in the layout have corresponding objects accessible through Python as well. I made a recent thread with a little utility that lets you mess around with objects interactively through Python, here:

    You can drop an object in the layout, and run it, then interact with it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    Thanks, I've wondered how that would actually be implemented.

    Question tho, how would you go about using that in a 2 dimensional array?

    Silent Cacophony

    Thanks, checking out that cap now.

  • [quote:1gnjibfz]how would you go about using that in a 2 dimensional array?

    Like this:

    + System: Start of layout
    -> Array: Set size to 3 x 2 x 1
    	+ Array: For Each element
    	-> Array: Set index (Array.CurrentX, Array.CurrentY) to {"one","two","three","four","five","six"}@((Array.CurrentX-1)*2+Array.CurrentY)
    [/code:1gnjibfz]
  • Ok, but I'll have to take your word for it. Now that brings up another question. Does "@((Array.CurrentX-1)*2+Array.CurrentY)" work for any array size?

    Well except for z that is.

  • In general if you have an array with sizes: sizeX, sizeY and sizeZ,

    and X,Y and Z are the current positions,

    then here is the general formula:

    X+sizeX*(Y-1)+sizeX*sizeY*(Z-1)

    or if written in construct:

    @(Array.CurrentX + Array.SizeX*(Array.CurrentY - 1) + Array.SizeX*Array.SizeY*(Array.CurrentZ - 1))[/code:exdklix3]
    and if it's just a 2d array:
    [code:exdklix3]@(Array.CurrentX + Array.SizeX*(Array.CurrentY - 1))[/code:exdklix3]
    
    The other formula I gave you fills the Y column before increasing X.  It was in this form:
    [i]Y+sizeY*(X-1)[/i]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)