Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:53:13+00:00 2026-06-10T06:53:13+00:00

So I have a stack level too deep error, and I’m pretty sure I

  • 0

So I have a “stack level too deep” error, and I’m pretty sure I know what’s causing it. I am working on a tile based game, and I have all the tiles, and for convenience (to save looking it up every time I need to use pathfinding), each tile has a “nearby” array containing the 8 neighbours.

However, when I go to print out some objects for debugging, I am frequently running into the “stack level too deep” error. I think that it is because each tile has neighbouring tiles in the “nearby” array, which then refer back to the original tile, creating a loop when trying to print all objects.

I can live with this, but it would be much nicer if I could have my cake and eat it too. I can avoid it by referring to tiles by id or coordinates, instead of direct reference to object. Disadvantage is this means searching for the object every time.

So, is there a way to maintain my current code but prevent the “nearby” array from being printed in output so that it stops sanely?

Hope that’s clear! Current code:

class Tile
    attr_accessor :type, :x, :y, :z, :nearby, :t_id

    @type = 0

    @@count = 0

    def initialize(x, y, z, type)
        @x = x
        @y = y
        @z = z
        @t_id = @@count
        @@count += 1

        @nearby = [] 

        @type = type
    end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:53:14+00:00Added an answer on June 10, 2026 at 6:53 am

    Ruby prints the return of the inspect method of an object when you pass it to p. You can override inspect on your class to make it return a string with only the information that would be useful for you.

    For instance:

    class A
      def inspect
        "printing an instance of A"
      end
    end
    

    When you print it:

    irb> a = A.new    
    irb> p a    
    printing an instance of A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the following error: SystemStackError: stack level too deep when executing the following
I am a developer working on an internal web-based application, and I have been
I am working on an HTML5 Canvas game, and the level needs to pre-load
I have stack panel with custom controls in it. I attach standard MouseDragElementBehavior to
I have stack panel with custom controls in it. User can add or remove
I have a stack panel for which AllowDrop property is true and I have
i have a stack of messages in database table. i want to send these
I have a stack which contains some integer data. I want to find out
I have a stack of WCF services installed on a Windows 2008 R2 Standard
I have view stack in a app like so: <mx:ViewStack id=viewStack left=0 right=0 top=0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.