Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 236 237 [238] 239 240 ... 796

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

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3555 on: November 23, 2012, 07:21:58 am »

Well, I did find an installer which gives me errors because network sources are unavailable.

edit: I'm off to doing uni stuff now. I'll see if IDLE has the same problem or not when I get home.
« Last Edit: November 23, 2012, 07:27:32 am by Dutchling »
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3556 on: November 23, 2012, 07:31:27 am »

Just get somebody to punch you in the face or something so you can go home and program in a dark room, alone, talking only to text on the internet LIKE US NORMAL PEOPLE.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3557 on: November 23, 2012, 10:48:45 am »

Just get somebody to punch you in the face or something so you can go home and program in a dark room, alone, talking only to text on the internet LIKE US NORMAL PEOPLE.

The way programming should be done.

I'm getting good work done on my latest non-uni project, but making Java and C++ communicate via sockets is a pain. Just using sockets in C/C++ is bad enough.

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3558 on: November 23, 2012, 02:30:52 pm »

Sooo, another module related problem.
I basically have this:
Code: [Select]
# families.py

from simple import *

def main():
    global WORLD
    WORLD = <yadda yadda>
    loop()

main()
   


Code: [Select]
# simple.py

def loop():
    <yadda yadda>
    map_mod()

def map_mod():
    for X in WORLD:  #  //NameError: global name 'WORLD' is not defined//
        <yadda yadda>

How do I prevent the error? using one of the following:
Code: [Select]
import families # at the beginning of simply.py
from families import WORLD # at the beginning of map_mod
results in restarting the whole thing, as it runs main() in families.py again.

Is there no way to have global variables? I'm thinking of just coding everything in one large file, as this is really annoying.
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3559 on: November 23, 2012, 02:38:04 pm »

I'm not familiar enough with python to know how to do it properly, but one way I have to avoid using globals is to create an object (I call it Game) that contains everything important that you want everyone to have access too.  Then whenever creating an object, I pass in the game object and assign it to self.game.  Eventually every object has access to the game object, which has access to pretty much every thing else. 

So I've got something like:

Code: [Select]
class Game:
  def __init__(self):
    self.dungeon = dungeon.Dungeon(self)
    self.item_manager = item_manager.ItemManager(self)
    self.monster_list = []
    self.whatever = {}

class Monster:
  def __init__(self, game)
    self.game = game
    //blah blah blah

So basically I make one instance of game, and just pass it around to everything.
« Last Edit: November 23, 2012, 02:42:47 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3560 on: November 23, 2012, 03:49:37 pm »

Thanks! Will be very useful.

edit: still one question, is there a way to import a module without running it? I don't need to do that now any more, so I'm not interested in workarounds, just wondering if it is possible.
« Last Edit: November 23, 2012, 04:01:40 pm by Dutchling »
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3561 on: November 23, 2012, 04:07:02 pm »

edit: still one question, is there a way to import a module without running it? I don't need to do that now any more, so I'm not interested in workarounds, just wondering if it is possible.

I only deal in workarounds.   :P  I have no idea other than wrapping the code into a function, and then not calling the function.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3562 on: November 23, 2012, 04:08:50 pm »

Wrong thread.
Logged

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3563 on: November 23, 2012, 09:54:57 pm »

Sooo, another module related problem.
I basically have this:
Code: [Select]
# families.py

from simple import *

def main():
    global WORLD
    WORLD = <yadda yadda>
    loop()

main()
   
Replace
Code: [Select]
main()
with
Code: [Select]
if __name__ == '__main__':
    main()
and import families.py
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3564 on: November 24, 2012, 09:37:48 am »

So, I want to make a simple, inefficient n-body simulation :D (By inefficient, I mean O(n2) inefficient). The problem is I have no idea how to display it. What could be a way to display what's going on in the simulation? o_O Possible ways I've thought up, in order of increasing time probably needed and complexity. Most likely readability, too.

1. Export as lots of text with X, Y coordinates every once in a while. Only 2D. Can use Excel to show all the particles.
2. Use a low resolution, easy-to-use display library (like libtcod). It has 144 times less resolution than you would expect, since each tile is 12 x 12 pixels.
3. Export images with white pixels as bodies and black as nothing, again every once in a while. Doesn't work with 3D simulations.
4. Learn a graphics library and implement it.

...Dx Are there any suggestions as to which is best? And maybe even tutorials. c: Number four seems pretty darn imposing.
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

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3565 on: November 24, 2012, 01:46:25 pm »

Supposedly libtcod can work with any size of tileset; a 1x1 or 2x2 tile size should work for your needs. It would probably be slow as all hell, but you could use that to render. It would work for 3D as well; you just use an orthographic view. Which basically just means 'toss out the z axis and render it on the x-y axes.' You could do a full perspective view, but that would require transformation and projection matrices, which would make it both take longer to render and longer to code.

As for learning a graphics library, it's best to do that when you are just focusing on learning a graphics library. Particularly for a project like n-body simulation, where the things being rendered are dots, it would be difficult to figure out where things went wrong; as they most assuredly will when one does graphics programming for the first time.
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3566 on: November 24, 2012, 02:08:15 pm »

Is anyone here familiar with Slick2D?
Logged
This conversation is getting disturbing fast, disturbingly erotic.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3567 on: November 24, 2012, 02:34:42 pm »

Alway: SDL is simple enough to learn and ported to nearly every language.
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3568 on: November 24, 2012, 02:59:17 pm »

Ah, true, I forgot about SDL. I was thinking more along the lines of shader-based OpenGL or DirectX.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3569 on: November 24, 2012, 08:52:01 pm »

So the verdict is 'use libtcod with a 1x1 tileset' for now? :D
Hrm. If there's lots of dots, it might be slow enough that it interferes with the simulation...
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
Pages: 1 ... 236 237 [238] 239 240 ... 796