❔ Error message when trying to move direction for my tiles in a N-puzzle
Hi! I get this error message when trying to move around my tiles in my N puzzle "System.IndexOutOfRangeException has been thrown "Index was outside the bounds of the array." The error occurs in this line of code "Tile temp = Tiles[x, y];" in swaptiles method. Heres is my code: https://hatebin.com/
30 Replies
forgot to press the save button on hastebin so you just linked the home page not your code
you can also $codegif if it's short
oh my bad
the code is to long to post it in hatebin is it possibly to paste it somewhere else ?
$paste
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
it's worrying that it's too long for hatebin
hahaha
uhm
can you see it in this
Pastebin
using System;using System.Collections.Generic;using System.Drawing;...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
that'll do
perfect 😉
which one of the
Tiles temp = Tiles[x,y];
calls is actually throwing the exception?Im not really sure of what you mean
this line
Tile temp = Tiles[x, y];
appears 4 times in the SwapTiles
method, which one is the one that throws the exception
or do all 4 cause it?I think all 4 of it cause it, im not really sure ;/
no worries, just gonna get the code running on my end, quite a lot of code to just understand so it's easier to literally run it on my machine and it seems to work fine, trying to push the 0 beyond the edge never causes an exception, just causes a blank line to be pushed to the console
thank you man i appreciate it 😉
oh okaay
uhm but when you try to run the code, is it a blank tile or a 0?
btw I had this class to but idk if you needed it using System;
namespace N_Puzzle
{
public class Tile
{
public int value { get; set; }
public string Color { get; set; }
public Tile(int v) { value = v+1 ;
} } }
public Tile(int v) { value = v+1 ;
} } }
it's a
0
characterit's alright I just made my own
Tile
struct to get it to run ^^
https://paste.mod.gg/qmvnrxokcjfs/0 this is how I rewrote it (well just tidied it up so I could work on it) and it works just fine, can't seem to cause it to break no matter what I tryOh yeah its seems to be working as you say, when i remove the '1' in the value = v + 1; and just write it like value = v; its seems to be working fine
pretty neat little game by the way, good stuff
thank you man! I appreciate the help, not many people help me that good. Btw a quick question, if I dont want it to keep printing out the board everytime i move the tile, can I use console.clear();
yeah, you can also directly manipulate the console buffer if you want very high performance rendering but that's a whole other subject
hahaha thanks but im not that good, maybe sometimes in the future 🙂
yeah, but very difficult for someone who's been programming like 4 months ;/
i've been programming for 10 years and I still make garbage, it never gets better
there are always things to learn 🙂 btw do you have any tips for learning programming ? I started computer science in august last year but feel like I still can't very much
keep making things that you are interested in, computer science will teach you a lot of maths and theory but not very much practical programming skills
so just keep making things always
and go back over your old projects and try to make them again but better, less lines of code, cleaner code, new features etc.
I will definitely take your advice and try my best. I agree, we get taught too many different things in computer science. Thank you for your time and conversation my friend 🙂
no worries, good luck!
Thank you !
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.