How do I go about doing this?

For questions about using Classic.

Post » Mon Nov 22, 2010 7:10 am

I want to use txt file to make my game level with python
but I don't now the best way of doing it. can anybody help me out.
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » Mon Nov 22, 2010 5:02 pm

[quote="toralord":20lfc9gk]I want to use txt file to make my game level with python
but I don't now the best way of doing it. can anybody help me out.[/quote:20lfc9gk]

I can't quite figure out what it is that you're wanting from that. Can you be more specific?

Python has really nice text processing abilities, so it sounds quite feasible.

Do you want to design levels using a text file, then read it into variables using Python? If so, what format would you use? Graphical representation (like arranging characters in a grid pattern to represent the layout), or descriptive (like an .ini file?)

What type of level? Top-down (like a dungeon level), or side-view (like a platformer?)

Or, do you want to use Python to procedurally generate the level, then store it in a text file? The generation would be the hard part there. Storing string variables into text files is pretty easy, though. I have an example of procedural generation using python, here. It would be easy to store the results as a text file in that example.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Mon Nov 22, 2010 10:21 pm

Sorry for my lack of information I was sleepy and, I wanted to write it down before I forget it.
anyway, I would like to have characters arrange in a grid pattern to represent the layout.
Tt is a Top-down game.

it would look like this
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4 0 0 0 0 0 0 0 0 0 4 4 4 4
4 4 4 0 0 0 0 0 0 0 0 0 0 0 4 4 4
4 4 0 0 6 8 8 8 6 8 8 8 6 0 0 4 4
4 4 0 0 8 4 4 4 4 4 4 4 8 0 0 4 4
4 4 0 0 8 4 4 4 4 4 4 4 8 0 0 4 4
4 4 0 0 6 4 4 4 4 4 4 4 6 0 0 4 4
4 4 0 0 8 4 4 4 4 4 4 4 8 0 0 4 4
4 4 0 0 8 4 4 4 4 4 4 4 8 0 0 4 4
4 4 0 0 6 8 9 7 4 7 9 8 6 0 0 4 4
4 4 0 0 0 0 0 0 4 0 0 0 0 0 0 4 4
4 4 4 0 0 0 0 0 4 0 0 0 0 0 4 4 4
4 4 4 4 0 0 0 0 4 0 0 0 0 4 4 4 4
4 4 4 4 4 4 0 0 4 0 0 4 4 4 4 4 4
4 4 4 4 4 4 0 0 4 0 0 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » Mon Nov 22, 2010 10:39 pm

You don't necessarily need python to do that. In fact the array object works quite well for this.
You do know the object can save, and load an external file don't you?
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon Nov 22, 2010 11:02 pm

[quote="newt":2ltf8xci]You don't necessarily need python to do that. In fact the array object works quite well for this.
You do know the object can save, and load an external file don't you?[/quote:2ltf8xci]

Yes I know that and I us mostly use it for that.
but I am trying to learn more about python in construct.
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » Tue Nov 23, 2010 2:57 am

Ahh, well in that case, I'd say you don't have to load an external file. :lol:
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Tue Nov 23, 2010 5:49 pm

So, Silent Cacophony can you post a cap showing how to do it.
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » Tue Nov 23, 2010 6:44 pm

I'm not sure what you want to do with the file, still, but I did a bit of experimenting in my PyShell:

[code:1l52u2pk]>>> with open("grid.txt") as f:
s = f.read()


>>> s
'4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n4 4 4 4 0 0 0 0 0 0 0 0 0 4 4 4 4\n4 4 4 0 0 0 0 0 0 0 0 0 0 0 4 4 4\n4 4 0 0 6 8 8 8 6 8 8 8 6 0 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 8 6 0 0 4 4\n', '4 4 0 0 0 0 0 0 4 0 0 0 0 0 0 4 4\n', '4 4 4 0 0 0 0 0 4 0 0 0 0 0 4 4 4\n', '4 4 4 4 0 0 0 0 4 0 0 0 0 4 4 4 4\n', '4 4 4 4 4 4 0 0 4 0 0 4 4 4 4 4 4\n', '4 4 4 4 4 4 0 0 4 0 0 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4']

>>> l1 = []

>>> for j in s:
l1.append([i for i in j if not i.isspace()])


>>> l1
[['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4', '4'], ['4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4'], ['4', '4', '0', '0', '6', '8', '8', '8', '6', '8', '8', '8', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '6', '4', '4', '4', '4', '4', '4', '4', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '6', '8', '9', '7', '4', '7', '9', '8', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '0', '0', '0', '0', '4', '0', '0', '0', '0', '0', '0', '4', '4'], ['4', '4', '4', '0', '0', '0', '0', '0', '4', '0', '0', '0', '0', '0', '4', '4', '4'], ['4', '4', '4', '4', '0', '0', '0', '0', '4', '0', '0', '0', '0', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '0', '0', '4', '0', '0', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '0', '0', '4', '0', '0', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4']]

>>> l2 = []

>>> for j in s:
l2.append(j.split())


>>> l2
[['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4', '4'], ['4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4'], ['4', '4', '0', '0', '6', '8', '8', '8', '6', '8', '8', '8', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '6', '4', '4', '4', '4', '4', '4', '4', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '6', '8', '9', '7', '4', '7', '9', '8', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '0', '0', '0', '0', '4', '0', '0', '0', '0', '0', '0', '4', '4'], ['4', '4', '4', '0', '0', '0', '0', '0', '4', '0', '0', '0', '0', '0', '4', '4', '4'], ['4', '4', '4', '4', '0', '0', '0', '0', '4', '0', '0', '0', '0', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '0', '0', '4', '0', '0', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '0', '0', '4', '0', '0', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4']]

>>> l3 = []

>>> for j in s:
l3.append([int(i) for i in j if not i.isspace()])


>>> l3
[[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4], [4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4], [4, 4, 0, 0, 6, 8, 8, 8, 6, 8, 8, 8, 6, 0, 0, 4, 4], [4, 4, 0, 0, 8, 4, 4, 4, 4, 4, 4, 4, 8, 0, 0, 4, 4], [4, 4, 0, 0, 8, 4, 4, 4, 4, 4, 4, 4, 8, 0, 0, 4, 4], [4, 4, 0, 0, 6, 4, 4, 4, 4, 4, 4, 4, 6, 0, 0, 4, 4], [4, 4, 0, 0, 8, 4, 4, 4, 4, 4, 4, 4, 8, 0, 0, 4, 4], [4, 4, 0, 0, 8, 4, 4, 4, 4, 4, 4, 4, 8, 0, 0, 4, 4], [4, 4, 0, 0, 6, 8, 9, 7, 4, 7, 9, 8, 6, 0, 0, 4, 4], [4, 4, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 4, 4], [4, 4, 4, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 4, 4, 4], [4, 4, 4, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 0, 0, 4, 0, 0, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 0, 0, 4, 0, 0, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]][/code:1l52u2pk]

Assuming that you don't want the spaces in the final data structure, and you want numerical values instead of characters, and that you may want to use Construct's array object, I made a simple .cap that demonstrates how you can load the data file into both a 2D python list and a 2D Construct array.

http://dl.dropbox.com/u/5868916/grid.zip

The text file should be in the same folder as the .cap in it's current form, is all.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Fri Nov 26, 2010 3:29 pm

Thanks for the example, I was looking for something like it.
Can you show me how to change the script to use double digit numbers?
Something like this
[code:1r0lhh1w]
15 15 15 15 15 15 15 15 15 15
15 15 15 15 15 15 15 15 15 15
15 15 15 15 02 02 02 02 02 02
15 15 15 02 02 02 02 02 02 02
15 15 02 02 03 03 03 03 03 03
15 15 02 02 03 15 15 15 15 15
15 15 02 02 03 15 15 15 15 15
15 15 02 02 03 15 15 15 15 15
15 15 02 02 03 15 15 15 15 15
15 15 02 02 03 15 15 15 15 15
[/code:1r0lhh1w]
I have 17 tiles for background(maybe more later) and I don't wanna use letters.
Do you know how to make it with events? I've tried it with TextManipulator and from start it looked promising, but after 2 hours trying I got massive brain pain and I had to quit :D
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Fri Nov 26, 2010 3:38 pm

17 tiles? Well, you could use the alphabet as well.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests