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
luness2y 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
luness2y ago
hahaha uhm can you see it in this
luness
luness2y 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
luness2y ago
perfect 😉
Doombox
Doombox2y ago
which one of the Tiles temp = Tiles[x,y]; calls is actually throwing the exception?
luness
luness2y 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
luness2y 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
luness2y 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
luness2y 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
luness2y 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
luness2y 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
luness2y 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
luness2y 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
luness2y 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
More Posts
❔ I should develop an app for windows and macos but i don't know how to do thisHello, today i started my first internship, but in my company i m the only dev and as a project i ha❔ any way to add panel to winforms net core?I am beginner and I was wondering if there was a way to add panel to net core project, cause it is n❔ Copying code from youtube and it doesn't work for meI'm new to the C# scripts and i am trying to make a board game, while trying to understand how to do❔ Error while trying to connect to MySql using MySql .Data**While trying to connect to maria db using mysql.data i get this error: ** > `Unhandled task excep❔ ✅ 'ConsoleColor' does not contain a definition for 'DrawingColor'I am experimenting a sample code to create a colourful UI on console, and am getting this error: ```❔ WinUI exe launch issueI receive this following issue every time from event viewer when I try to start the application via ✅ Logging incoming HTTP requests with WebApplicationI've got a route in my app that isn't being triggered properly. I can't currently figure out what's ❔ What unit tests should I create for my ASP.NET API Controller / project?I am new to Unit Testing. I have watched a video on XUnit and FluidAssertions, but I am unsure as to✅ Blocking ASP.NET Core Shutdown fullyWhen i shut down my ASP.NET Core API i have to make 0-n API requests and receive (and answer) that m❔ Basic NetworkingOn client side of a client-server model. Is it best to globally define a tcp Client and network stre