Instruct room creation with a large number.

Get help using Construct 2

Post » Fri Nov 06, 2015 11:13 pm

Hello! I want to insert objects into a room by having a local variable store a number that instructs what objects to place, and using that in conjunction with a loop to place objects in the level. The issue I am having is that apparently the number is too large to store in a local variable. The loop to place objects works fine, it's the local variable that is giving me the problem.

Example:
This is a room, where each "0" is an empty space, and each "1" is a wall.
Code: Select all
000000000000
011100001110
010000000010
010110011010
000100001000
000100001000
010110011010
010000000010
011100001110
000000000000


When the line breaks are removed, it becomes:
Code: Select all
000000000000011100001110010000000010010110011010000100001000000100001000010110011010010000000010011100001110000000000000


That's a pretty long number, and Construct2 jumbles it when it is placed into a local variable:
Code: Select all
11100001110010002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


Where and how can I store a lot of these large numbers? Is there a way to compress these numbers without having to program in a way to de-compress them? Thank you in advance.
B
9
S
3
Posts: 52
Reputation: 1,260

Post » Fri Nov 06, 2015 11:22 pm

Wouldn't putting it into array be the best option?
Using a dictionary object would work too, but these kind of things scream array..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Nov 06, 2015 11:54 pm

LittleStain wrote:Wouldn't putting it into array be the best option?
Using a dictionary object would work too, but these kind of things scream array..


How would you do this?
I tried placing the value into an array but the array also jumbles the number.
B
9
S
3
Posts: 52
Reputation: 1,260

Post » Sat Nov 07, 2015 12:02 am

I would put every number 0 and 1 in it's own x,y place in the array so the array would look like your first code..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Nov 07, 2015 12:05 am

LittleStain wrote:I would put every number 0 and 1 in it's own x,y place in the array so the array would look like your first code..


Wouldn't I then need to input each 0 and 1 manually whenever I want to load a new level layout... ?
B
9
S
3
Posts: 52
Reputation: 1,260

Post » Sat Nov 07, 2015 12:14 am

Offcourse not..
put the 0's and 1's in a string and create a function to parse the string to the array..
I guess you should put the numbers in a string anyway..
Maybe you could use the string directly..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Nov 07, 2015 12:20 am

Might be easier if you converted from binary.
Image ImageImage
B
169
S
50
G
170
Posts: 8,292
Reputation: 108,728

Post » Sat Nov 07, 2015 3:17 am

HacksawUnit wrote:
LittleStain wrote:Wouldn't putting it into array be the best option?
Using a dictionary object would work too, but these kind of things scream array..


How would you do this?
I tried placing the value into an array but the array also jumbles the number.


Sounds like the array size is not set. There is a set size action. Try using it on-start.

If you dont set the size properly, it can get really messy. Remember it is 0 based.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Tue Nov 10, 2015 12:17 am

I figured out a solution that worked well for me. I created a text file that contains every room layout, back to back. It is referenced using AJAX. Each room layout consists of 120 characters, so I'm using "mid" to reference a random level layout like so:

mid ( ajax.LastData, ( whichLevel*120 ), 120 ), where "whichLevel" is a random number from 0 to [total number of layouts I make minus one.]

I am using a spreadsheet to make sure I don't lose levels in the giant text file. :-)
B
9
S
3
Posts: 52
Reputation: 1,260


Return to How do I....?

Who is online

Users browsing this forum: Leef and 26 guests