Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 225 226 [227] 228 229 ... 796

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

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3390 on: November 06, 2012, 11:00:59 am »

Or, alternately, have the "update" method except (for example) a hash of named arguments as an optional second parameter, or an argument array, in the parent class. Then you can override using as many additional components as you wish.

*args and *kwargs, dude.
« Last Edit: November 06, 2012, 11:02:46 am by GlyphGryph »
Logged

Berserker

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3391 on: November 06, 2012, 11:06:28 am »

This works also, just make the "param" optional parameter.

Code: [Select]
class Animate:
    def update(self):
        print 'Animate update'

class Player(Animate):
    def update(self, param=None):
        if param:
            print 'Player update with parameter',param
        else:
            Animate.update(self)


player = Player()
player.update()     # Prints Animate update
player.update(1234) # Prints Player update with parameter 1234

The "param=None" means that you don't have to give that argument. If you don't give it, it will be None and the Player.update calls Animation.update.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3392 on: November 06, 2012, 11:09:22 am »

Have you tested that it works, or do you just think that it should?
If Python doesn't do method overloading via separately defined functions, then even optional parameters change the signature, causing an error, I would think.
Python isn't my native tongue.  :P It's strange way of handling things never appealed to me much.

Berserker

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3393 on: November 06, 2012, 11:31:08 am »

Yes, I tested it. The update in Player replaces the update that it inherits from Animation regardless of the parameters.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3394 on: November 06, 2012, 12:57:32 pm »

Here's an update.

Added a whole new universal file format and lots of uses for it, added animated sprites, added menu states with widget-based GUIs, parallax backgrounds, camera zoom, tiles, tilesets and tilemaps, fixed the collision code, added elasticity (press Space to become bouncy!), and even added loadable levels! Have a look at the data folder. especially the *.z* files.
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3395 on: November 06, 2012, 03:01:39 pm »

So, um, I may have just used a python interpreter to open 100 more python interpreters. It takes about a second to actually type a character now. :3
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3396 on: November 06, 2012, 03:03:16 pm »

So, um, I may have just used a python interpreter to open 100 more python interpreters. It takes about a second to actually type a character now. :3

I'm so proud!

*manly tears*

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3397 on: November 06, 2012, 03:08:22 pm »

I was going to have all of them open another 100 interpreters each all at once, but that would probably cause some sort of high-level implosion that would result in everyone wrapping around back to using punch-cards. 
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3398 on: November 06, 2012, 03:16:57 pm »

Here's an update.

Added a whole new universal file format and lots of uses for it, added animated sprites, added menu states with widget-based GUIs, parallax backgrounds, camera zoom, tiles, tilesets and tilemaps, fixed the collision code, added elasticity (press Space to become bouncy!), and even added loadable levels! Have a look at the data folder. especially the *.z* files.

Stop working so much faster than me! >_<

Haha, definitely gonna check it out when I get home, sounds pretty cool.

Meanwhile, I've come across the problem of their being no easy way to save a json file with javascript - so I'll probably have a button to display the raw JSON (which you can then manually save to a file) and a button to send it as a post request to some php on the server to create the file there (assuming you aren't running it locally, which I would like to preserve if possible).
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3399 on: November 07, 2012, 09:07:19 am »

Updated again.

New options menu with configurable (and saveable) key bindings! Also, fixed the collision code. Again.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3400 on: November 07, 2012, 01:01:44 pm »

Stop working so much faster than me! >_<
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3401 on: November 07, 2012, 01:27:56 pm »

I also think I broke Skyrunner and made her hate linux. :(

Perhaps trying to link libraries and compile in linux via the code blocks IDE wasn't the best first task for an introduction...
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3402 on: November 07, 2012, 02:34:41 pm »

Here's an update.

Added a whole new universal file format and lots of uses for it, added animated sprites, added menu states with widget-based GUIs, parallax backgrounds, camera zoom, tiles, tilesets and tilemaps, fixed the collision code, added elasticity (press Space to become bouncy!), and even added loadable levels! Have a look at the data folder. especially the *.z* files.

Stop working so much faster than me! >_<

Haha, definitely gonna check it out when I get home, sounds pretty cool.

Meanwhile, I've come across the problem of their being no easy way to save a json file with javascript - so I'll probably have a button to display the raw JSON (which you can then manually save to a file) and a button to send it as a post request to some php on the server to create the file there (assuming you aren't running it locally, which I would like to preserve if possible).

Depending on how old a browser you want to target, consider web storage for saving state.

http://www.w3schools.com/html/html5_webstorage.asp

Or cookies: for smaller amounts of data.

http://www.w3schools.com/js/js_cookies.asp
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3403 on: November 07, 2012, 02:38:39 pm »

The problem is that both sorts of saving are temporary and difficult to transfer - the exact opposite of what I want for map and tile definitions (though perfect for things like, say, save states).
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3404 on: November 07, 2012, 11:51:39 pm »

So... save files. I need to touch on them some day.

I think C++'s fstream/ostream/istream are horridly inadequate for this usage. Any libraries out there that might be useful? Maybe Boost::Filesystem, or Boost IOStream-state?

Also, if not the stream-state library, how should I save stuff? Should I output plaintext along with variables, like

Code: (plaintext) [Select]
HP = 100;
MaxHp = 100;
Inventory = (5,3,2),(5,6,43);

or just variables in binary... or use XML? @_@

I think the map files will have to be saved separately from the other variables, though. They're huge—my program was using 10 MB of ram with just a single map open.

Anyhow: So many choices.
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 ... 225 226 [227] 228 229 ... 796