[SOLVED] 2D Arrays Not Working Quite Right for setTileAt Map Gen

tristonhopkins

  • Posts: 69
So a long while back I made a little map generation demo, which you can see here. http://www.stencyl.com/game/play/12566

Just the other day I opened it up again and I'm trying to add a second method of map generation using cellular automata.  That's not where I'm running into trouble, though..

Here's the new and very broken build. http://www.stencyl.com/game/play/17740

I can't for the life of me seem to figure out why my code is misbehaving so much.  For one, the map is supposed to be filled, of course, and it's certainly not supposed to be flashing.  Two, regardless of specifying very specifically what tiles to use with setTileAt, it's using a tile it shouldn't be, and it's driving me crazy.  I'm sure it's something stupid, so please point out how stupid I am being.

Hopefully someone can help me out!  Code is attached below!  Thanks.

« Last Edit: March 11, 2013, 02:54:32 pm by tristonhopkins »

Tuo

  • *
  • Posts: 2469
I have never seen the "_attribute][_attribute" style before... where are the end brackets? Should you put that inside a code deliminator?

Also, you shouldn't need the extra parentheses around mapX and mapY when doing the coding for the tiles.

If your tiles are not being set correctly, it's also possible that your tiles have become corrupted. You may want to delete them and try re-importing them.

I hope you can get it to work. I've wanted to see a working 2D array for a while now (I use a pseudo-2D array for my tiles, using one extra-long list that wraps around instead; if you want to see it, it's in my "Demo- Miner" in the StencylForge).
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

rob1221

  • *
  • Posts: 9456
One case I'm aware of that can cause odd tiles to be drawn is if the tile sizes of the scene and tileset editor do not match.  If that's not the problem then I have no idea.

Hectate

  • *
  • Posts: 4643
I have never seen the "_attribute][_attribute" style before... where are the end brackets? Should you put that inside a code deliminator?
Code: [Select]
When you reference an array within another array,
the syntax is [A][B] where A is the index number of
an item in the first array and B is the index number
of the item in the second array (which is located at
A). The block he's using just takes whatever text or
attribute inserted and puts it within [...] brackets,
so by inserting additional brackets he's referencing
the second array instead of just the first. For
example; "get item number A from MyList" would be
just getting "[A]" in code. But "get item number A][B
from MyList" would instead be getting "[A][B]" instead.
Note, BBCode wanted to make my B a bold statement so I put it in a code quote field. :)

Back on topic, my initial guess was that it was going to be an issue with the "current loop count" block because behavior had changed on that (my tile generation code broke as a result) but you're not using that so that can't be it.

« Last Edit: March 11, 2013, 05:57:41 am by Hectate »
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

tristonhopkins

  • Posts: 69
One case I'm aware of that can cause odd tiles to be drawn is if the tile sizes of the scene and tileset editor do not match.  If that's not the problem then I have no idea.

You know, I just noticed that none of my scenes are allowing me to specify their tile size.  The tile size entry space is blank and I can't enter anything into it.

And apparently it's affecting all of my projects.  Um..

tristonhopkins

  • Posts: 69
Okay, it was a stupid mistake on my part and this is fixed now.  While I can't seem to change the tile size of a scene once it's created (not sure if this is a Stencyl bug or not) I was specifying the wrong tile size anyways, so I made a new scene with the correct tile size.

This is what happens when I go back to a project and forget that I'm using a smaller tile size than I normally do.  #$%& me.

Tuo

  • *
  • Posts: 2469
Have you changed your tiles since importing them? Are the tile sizes the same sizes as the tiles for your scenes?

EDIT: Looks like you just checked that yourself :P
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)