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 5973177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:45:48+00:00 2026-05-22T20:45:48+00:00

First off, I’m sorry if this is a n00b question. I’m a self-taught web

  • 0

First off, I’m sorry if this is a n00b question. I’m a self-taught web developer and this is my first real foray into apps. I’ve tried to find the answer to what I’m looking for, but I’m not sure on the proper terminology and so haven’t found any relevant results. I figure this is because either I don’t know the right way of asking for what I need; the answer is so obvious it doesn’t need writing about or what I’m asking is so stupid the concept doesn’t exist and I should be totally doing it another way.

Anyway, on to my question. I’m working on an app that has 3 classes that are giving me trouble. There is the ‘MainContainer’, which mostly handles the UI; the ‘Assigner’ which picks out tasks to do; and the ‘Worker’ which does the tasks. It’s in a very early stage, but this is kind of how it looks right now.

class MainContainer

  def setup
    @worker = Worker.new(:x => 200, :y => 200)
    @assigner = Assigner.new(:x => 400, :y => 300)
  end

  # update & draw code
end

class Assigner

  def set_target
    parent.worker.target self.x, self.y
  end

  # input, update & draw code
end

class Worker < GameObject

  def target(tx, ty)
    @target_x = tx
    @target_y = ty
    @has_task = true
  end

  # update & draw code
end

The basic flow of the app goes something like this: an instance of the MainContainer loads and shows the UI on the screen including the assigner and worker. The user then uses the assigner to move around the UI and choose a task. Everything works fine up until this point.

What I can’t figure out is how the Assigner can pass a value to the worker. The code I have in the example is the set_target method of the worker. The parent.worker.target self.x, self.y line is the most recent of my attempts. Other things I’ve tried here include things like @worker.target self.x, self.y

I was thinking of passing the @worker into the @assigner, but the plan is for there to be an arbritrary number of workers that will increase/decrease over time. I plan to handle these with a WorkerManager that will keep track of how many workers are currently available, but if I pass this into the @assigner will it not be just a copy of it that is passed? I’m still way off from implementing anything like that so I haven’t tested it, perhaps that is the way to go?

Another thing I’ve thought about is having the worker as a global, but this is a problem that will likely rise again quite frequently so I’d end up with an app full of globals, I’m guessing that’s not the right way!

I’m from web-dev so the only other solution I can think of is to database the whole lot of it. This is a last resort if I can’t get anything else going though.

Anyway, to re-state my question. In an instance of MainContainer, how do I get its Assigner and Worker to pass data between each other?

I’d really appreciate any help here, even if it goes something like “stfu n00b, read this: -relevant link”.

  • 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-05-22T20:45:48+00:00Added an answer on May 22, 2026 at 8:45 pm

    I think there’s a flaw in the design somewhere. You say that the Assigner picks the task and the Worker does it. It doesn’t look like they need to communicate. If they need to, they may be doing more than what you described, which may indicate an opportunity for refactoring into more isolated classes with fewer responsibilities.

    So, what if the MainContainer had all control?

    def main
      @worker = Worker.new
      @assigner = Assigner.new
      target = @assigner.target
      result = @worker.do_work(target)
      update_ui(result)
    end
    

    The UI should really be separate from the business logic, the pseudocode above just illustrates the idea of giving control to the MainContainer to avoid having the Worker and the Assigner to talk to each other. This will also allow you to handle multiple workers if necessary.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, this question is ripped out from this question. I did it because
First off, please accept my apologies if this question is basic, I mainly have
First off, either A) I'm not investigating into this hard enough or B) I've
First off, apologies if this is a complete noob question which could easily be
First off - apologies if this or a similar question has been asked before.
First off--thanks for having a look. MY QUESTION In a .NET web app, is
First off, I know this may be a very stupid question, so don't shoot
First off, there's a bit of background to this issue available on my blog:
First off, let me start off that I am not a .net developer. The
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS

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.