[solved] Python and ImageManipulator

For questions about using Classic.

Post » Sat May 08, 2010 5:45 pm

How can i use the ImageManipulator Object in a Python script?

I want to use "ImageManipulator copy image to sprite"

I have tried: ImageManipulator.CopyToSprite(spritename) but my game crashes at start. how do I have to use this?
B
7
S
2
G
2
Posts: 45
Reputation: 1,465

Post » Sat May 08, 2010 8:20 pm

I'm using .99.84 and it doesn't do anything for me at all so this definitely sounds like a bug.

When using your syntax (putting the Sprite name in) it doesn't do anything, when putting a 1 or 2 for sprite name it crashes.

I tried to find the source to the ImageManipulator but it isn't available so I can't do much more to help. I've posted it to the tracker.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sat May 08, 2010 9:34 pm

Yeah, I can't get it to work either.

I also noticed that there seems to be no method defined for 'Copy from sprite', which makes Python usage of the manipulator even more difficult.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Sat May 08, 2010 10:34 pm

It appears that 'CopyToSprite' actually copies from the sprite. What's probably happening is the two functions 'CopyToSprite' and 'CopyFromSprite' both have the name 'CopyToSprite' in python. So the last one defined is the only one accessible. Easily fixable if the source were available.

Edit:
Also ImageManipulator.CopyToSprite(spritename) is incorrect.
With functions (or methods) in construct, only two types work in python: numbers or strings. So the correct way would be: ImageManipulator.CopyToSprite('spritename'). If you use a number instead of a string, the objecttype with an OID (object id) equal to that number would be referenced. If the referenced objecttype has no image data it will cause a crash.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Sun May 09, 2010 5:24 am

This sounds not good to me.

My problem is that "ImageManipulator copy image to sprite" in construct has only a dropdown list of all my sprites. But I dont want to use the name of a sprite from this list. What I want is to use a variable for the name because i have 100 sprites, and all of them should get the same imagemanipulator actions. If i can not use a variable there, I have to do the same events for every single sprite i want to change.

I really dont know what to do now.
B
7
S
2
G
2
Posts: 45
Reputation: 1,465

Post » Sun May 09, 2010 1:16 pm

Well, you can use variables instead of string or number literals. The variable just has to contain the name in string form, or the Object ID in number form, as R0J0hound pointed out.

The bigger issue is the fact that the python methods are messed up, but it should be possible to work around that with the function object. I made a simple example with a couple of different ways to use the function object to do image processing, including from python.

v.99.84 Cap here: [url:e7ji612u]http://dl.dropbox.com/u/5868916/FunctionWorkaround.cap[/url:e7ji612u]
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Sun May 09, 2010 1:40 pm

Thank you very much. That helped me a lot. But one little Problem is still there. How can i load an Image from an ini file with such a function ?

INI.ItemString("item1", "image1") does not work in Function.ProcessSprite("Sprite", "Sprite2").

If i can load the image from an ini string, my problem will be solved.
B
7
S
2
G
2
Posts: 45
Reputation: 1,465

Post » Sun May 09, 2010 2:11 pm

[quote="UnixRoot":2h0ho73a]Thank you very much. That helped me a lot. But one little Problem is still there. How can i load an Image from an ini file with such a function ?

INI.ItemString("item1", "image1") does not work in Function.ProcessSprite("Sprite", "Sprite2").

If i can load the image from an ini string, my problem will be solved.[/quote:2h0ho73a]

You're welcome. I'm not terribly familiar with the INI object, but I added one and replaced the function call in start of layout with this:

[code:2h0ho73a]+ System: Start of layout
-> INI: Set INI file to "MyINI"
-> INI: Write string "Sprite2" to item "Item1" in group "Group1"
-> Function: Call function Function.ProcessSprite("Sprite", INI.ItemString("Group1", "Item1")) (and Forget picked objects)
[/code:2h0ho73a]

... and it worked the same as before. Assuming that you're storing object names in the INI file.

Also, the same as above can be done from python as:

[code:2h0ho73a]INI.SetFile("MyINI")
INI.WriteString("Group1","Item1","Sprite2")
Function.AddParam("Sprite")
Function.AddParam(INI.ItemString("Group1","Item1"))
Function.Call("ProcessSprite", 0)[/code:2h0ho73a]
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Sun May 09, 2010 4:26 pm

This solved my Problem completely. Thank you for your quick help.
B
7
S
2
G
2
Posts: 45
Reputation: 1,465

Post » Sun May 09, 2010 9:23 pm

You can right click just above the drop down list and switch the expression box to "use expression mode" wich allows you to pass things like string from an ini file into it.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest