C
C#2y ago
luness

❔ 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
Doombox
Doombox2y ago
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
luness
lunessOP2y ago
oh my bad the code is to long to post it in hatebin is it possibly to paste it somewhere else ?
Doombox
Doombox2y ago
$paste
MODiX
MODiX2y ago
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!
Doombox
Doombox2y ago
it's worrying that it's too long for hatebin pepetense
luness
lunessOP2y ago
hahaha uhm can you see it in this
luness
lunessOP2y ago
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.
Doombox
Doombox2y ago
that'll do
luness
lunessOP2y ago
perfect 😉
Doombox
Doombox2y ago
which one of the Tiles temp = Tiles[x,y]; calls is actually throwing the exception?
luness
lunessOP2y ago
Im not really sure of what you mean nervousowo
Doombox
Doombox2y ago
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?
luness
lunessOP2y ago
I think all 4 of it cause it, im not really sure ;/
Doombox
Doombox2y ago
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 pepelaff 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
luness
lunessOP2y ago
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 ;

} } }
Doombox
Doombox2y ago
it's a 0 character
Doombox
Doombox2y ago
it'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 try
luness
lunessOP2y ago
Oh 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
Doombox
Doombox2y ago
pretty neat little game by the way, good stuff
luness
lunessOP2y ago
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();
Doombox
Doombox2y ago
yeah, you can also directly manipulate the console buffer if you want very high performance rendering but that's a whole other subject
luness
lunessOP2y ago
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 ;/
Doombox
Doombox2y ago
i've been programming for 10 years and I still make garbage, it never gets better sunglas
luness
lunessOP2y ago
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
Doombox
Doombox2y ago
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.
luness
lunessOP2y ago
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 🙂
Doombox
Doombox2y ago
no worries, good luck!
luness
lunessOP2y ago
Thank you !
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server