How to get all items in a INI group using python script?

For questions about using Classic.

Post » Sat Apr 16, 2011 12:32 am

My goal is to get all items in a group in INI object.

Sub-event of 'For each item' can do that.
+ INI: For each item in group "key"
-> Output: Set text to INI.CurrentItem

How to use python script to do the same thing?
I try this and crash.
[code:2spjgapt]for key in INI.ForEachItem('key'):
Output.SetText(key)[/code:2spjgapt]
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Tue Apr 19, 2011 1:23 am

What is the error you are getting? You could always parse the INI file with Python with a "for each line" type method.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Wed Apr 20, 2011 1:21 am

Use python to parse text file is a good solution.
There is a built-in INI object, so I try it first. Methods in INI object almost can be used in python, except for ForEachItem().
Finally, I mix python script and built-in event to solve it, but it is not perfect.
(run python script first)
[code:3rqwfxc2]keys = [][/code:3rqwfxc2]
(then built-in event)
[code:3rqwfxc2]+ INI: For each item in group "group"
-> System: Run Script ("keys.append(INI.CurrentItem)")[/code:3rqwfxc2]

--
Another question, how to call sprite's 'destroy' method in python script?
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Wed Apr 20, 2011 3:08 am

You can call it just like it was a Python method: Sprite.Destroy()
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Mon Jun 06, 2011 7:13 am

I find a pure python module "ConfigObj" for access unicode INI file.
http://www.voidspace.org.uk/python/conf ... ownloading

There is a little different between built-in INI object and "ConfigObj". The comment in "ConfigObj" is using "#", not ";".
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests