123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|675|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Web Development -> javascript array problem [solved]

Fri, 17 Jul 2020, 06:30
spinal

javascript array problem [solved]


Having looked around, I could not find a version of maprecon (you know it, its a tile map creator) with some extra features I want, so I made a start at my own version in javascript.

However, I seem to be having trouble comparing two arrays. The code first creates an array from an 8x8 block of the loaded image, then compares it with the current collection of tiles. But when I output the current comparison to the console, it seems that no matter what I do, the tile array is always exactly the same as whatever array I check, which as we know is completely impossible.

Is anyone able to see if I have a typo somewhere, or other stupid mistake? I'm pulling my hair out here. The conversion is triggered when you load a ong with the 'choose file' button and it will only check the first 8 tiles, no need to check more when it doesn't even work...



-=-=-
Check out my excellent homepage!
Fri, 17 Jul 2020, 06:43
spinal
In fact, changing the checking routine to only the following



Shows that tileArray[0] for some reason is ALWAYS whatever is being passed to the function... I don't get it.

-=-=-
Check out my excellent homepage!
Fri, 17 Jul 2020, 06:51
spinal
dammit, it's a pointer.



It was turning the tile array into a pointer to the new array and it stayed that way. so reading it always just showed the other.

-=-=-
Check out my excellent homepage!
Fri, 17 Jul 2020, 07:14
Jayenkai
Javascript can be a right pain sometimes. I often fall for the "is x a value? .. 'Yes!' .. What is x's value? ... 'Undefined!'.. " pitfall
Double and triple check everything, and be sure to make good use of the dev-console, too.
I used to find Microsoft Edge to be great for debugging, but since they redid it using Chromium, it seems like they lost a lot of the quirks that showed up some of my bugs!

-=-=-
''Load, Next List!''
Fri, 17 Jul 2020, 07:31
spinal
Something else is odd now after expanding the checking to the full width of the image and just a few rows, it seems to no find matches from the previous row! so each new row starts adding new tiles, even though some of them should match

|edit| caught that one too

now to test the full size image, I'm expecting a little over 1200 tiles from the example image I'm using...

Result = 1210 tiles in image, mapRecon gave 1216 tiles for the same image!

Difference could be because I reduce the palette to 565 from 888 before checking, which would result in similar colours being removed.
Also, mapRecon did it a LOT faster

-=-=-
Check out my excellent homepage!
Fri, 17 Jul 2020, 07:50
Jayenkai
Just a minor tweak...
When you're comparing the tile, you're doing a y loop, an x loop, and a bit of maths for every element. (X+width*y)

Instead, you can do a single n=0;n<length of array;n++ loop, which reduces the number of loops, and also means you needn't do that little bit of maths several hundred-thousand times.

-=-=-
''Load, Next List!''
Fri, 17 Jul 2020, 08:07
spinal
good point!

Now I just need an async progress bar so I can tell something is happening in the couple of minutes the screen is frozen

-=-=-
Check out my excellent homepage!
Fri, 17 Jul 2020, 08:33
spinal
Although, that might get in the way of the extra feature I want... checking for flipped tiles...

-=-=-
Check out my excellent homepage!
Fri, 17 Jul 2020, 09:09
Jayenkai
Aaah, yeah.. Bugger!
Wed, 22 Jul 2020, 04:03
spinal
hmmm, I seem to be generating valid tiles and map, including flipped tiles (probably, not fully tested with my renderer) but I seem to be messing up on my flip array



There is defiantly less tiles being generated, which suggests that its finding flipped versions of the tiles. However I think I'm recording the flip-ness wrong...


|edit| I think I fixed it...



-=-=-
Check out my excellent homepage!
Wed, 22 Jul 2020, 04:22
Jayenkai
I'll have to take your word for it!!

What's this for, anyway?

-=-=-
''Load, Next List!''
Wed, 22 Jul 2020, 05:04
spinal
I basically want a version of maprecon that has the ability to find flipped tiles as well as normal ones I have been playing with tile maps from old games and some of them use flipped tiles.

-=-=-
Check out my excellent homepage!
Wed, 22 Jul 2020, 05:08
Jayenkai
Aww, thought you had a game in mind.
Wed, 22 Jul 2020, 06:49
spinal
Nah, just curiosity
Wed, 22 Jul 2020, 08:05
spinal
Here is the experiment...
https://twitter.com/Spinal_Cord/status/1285899828648644610?s=09
Converted from a level map found online.

-=-=-
Check out my excellent homepage!
Wed, 22 Jul 2020, 08:31
Jayenkai
Coooooool!!!