Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 254 255 [256] 257 258 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 907618 times)

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3825 on: February 05, 2013, 05:40:48 pm »

because the game has no attribute named id1? it has an attribute with a value of id1, but that still needs to be referenced by game.c
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3826 on: February 05, 2013, 05:42:54 pm »

Then why does game.c work? ???

edit: To clarify: How would you write
Code: [Select]
c = 'id1'
game.c
in one statement? c does not seem to equal 'id1' at all...

Never mind, I get it >.<

edit:

So I have the following code:
Code: [Select]
def init(game):
    for i in range(game.personStart):
        c = 'id' + str(i)
        globals()[c] = person.Person(game)
        game.c = globals()[c]
'Obviously' (:P), that last line just makes something refer to what it was referring to in the first place. Is there a way to get the following:
Code: [Select]
one first iteration: game.id0 = x
second iteration: game.id1 = y
etc etc
« Last Edit: February 05, 2013, 06:07:44 pm by Dutchling »
Logged

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3827 on: February 05, 2013, 06:11:36 pm »

you mean you want to write it to the console?

google tells me you should use print('iteration' + str(i) + ': ' + globals()[c])

i look at that globals()[c] and feel a bit queasy.
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3828 on: February 05, 2013, 06:18:27 pm »

I'll try that.

globals()[c] works fine so far. I don't know of any way to assign variables without manually typing them all or using some sort of dictionary trick.

edit: I think you misunderstood me, I want to assign variables in an instance of a class, which is game. But I do not know those variables at the start. globals()[] works for normal global variables, but I can't get it to work inside of a class.
« Last Edit: February 05, 2013, 06:21:15 pm by Dutchling »
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3829 on: February 05, 2013, 06:26:32 pm »

I don't know what exactly you want to do that for, but you could always use setattr(). I share Twiggie's uneasiness, though.

Example:
Code: [Select]
class TestClass:
  def __init__(self):
    pass

tc = TestClass()
for i in range(50):
  setattr(tc, "id"+str(i), i)

Creates an empty object and then adds fifty variables to it. Again, I don't know why you want that rather than just keeping a dict in your class, but here you go.
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3830 on: February 05, 2013, 06:29:31 pm »

What I want to do is create a lot of person objects. The game object should know all of those.
Logged

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3831 on: February 05, 2013, 06:43:01 pm »

have an array(-analogue) of type person in game?
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3832 on: February 05, 2013, 06:46:34 pm »

That.... should work actually. I was a bit too intend on doing what worked earlier, even though this might a be more useful.

That is assuming you mean list with array :P
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3833 on: February 05, 2013, 06:48:27 pm »

That is assuming you mean list with array :P
Linked list, Array list, Array, Dictionary, fuck it, just use a collection of some sort.
The way you are doing it currently is approaching parody.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3834 on: February 05, 2013, 08:42:36 pm »

I figured it was something about the braces, it's hard to get used to a new language. :-[

Levi, according to my reference it doesn't make a difference if you use = 0 or (0).

Interesting.  I've never seen it done with the (0) before.
I guess it's implicit assignment or whatever, like you use in initializer lists.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3835 on: February 05, 2013, 09:37:29 pm »

About a year ago, I was taking C and had a huge problem with functions: their declarations, their headers, the pointers...you name it, I probably bitched in this thread about it. My mental block caused me to lose all enthusiasm for the class which led to my failing.

Now I'm taking the class again, and my block is gone so far! I honestly don't know how I could screw it up so thoroughly before, because this time it's all clicking. I even managed to complete a two-day assignment in a little under two hours :D

So yeah, just wanted to share the happies. Please continue your discussion :P
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

kaenneth

  • Bay Watcher
  • Catching fish
    • View Profile
    • Terrible Web Site
Re: if self.isCoder(): post() #Programming Thread
« Reply #3836 on: February 07, 2013, 04:47:56 pm »

Logged
Quote from: Karnewarrior
Jeeze. Any time I want to be sigged I may as well just post in this thread.
Quote from: Darvi
That is an application of trigonometry that never occurred to me.
Quote from: PTTG??
I'm getting cake.
Don't tell anyone that you can see their shadows. If they hear you telling anyone, if you let them know that you know of them, they will get you.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3837 on: February 09, 2013, 04:22:14 pm »

I've got a non-coding question relating to software projects.

Potential employers like seeing practical experience listed on resumes. I have no work experience in the field, so that's problematic. I do have a game I'm working on, though.

Do you guys put your personal projects on your resumes? I guess it couldn't hurt, but I'm not sure how professional it would be.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3838 on: February 09, 2013, 04:32:33 pm »

The current big fad is to put a link to your github on your application or resume. LinkedIn even has a special plugin for it.

Interviewers often ask to see a sample of your work, at least if they're not pure HR people. And by necessity that has to be personal projects, you can't exactly give them stuff you've done at a former or current job. It doesn't have to be fancy though, something done for a class assignment/project/paper at college/university works fine as long as it's not just from a tutorial.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3839 on: February 09, 2013, 09:56:20 pm »

Though working on personal projects that AREN'T games is generally a lot more attractive to employers.
Logged
Pages: 1 ... 254 255 [256] 257 258 ... 796