Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 432 433 [434] 435 436 ... 796

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

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6495 on: October 29, 2014, 04:10:56 am »

Find a way to track all the elements you need to remove, then after you get a list of elements to remove, do that.
An alternative thing (at least in C++), assuming that a iterator will only ever delete itself or elements immediately following it, is to pull out the iterator increments into a separate thing and set your iterator = to the return value of the erase call, i.e.:
Code: [Select]
for ( it = res.begin(); it != res.end(); ) {
  if (condition) {
    it = res.erase(it);
  } else {
    ++it;
  }
}
This works because the erase call returns the value of the iterator immediately following the last thing erased.

For adding things there's a fairly simple trick you can do assuming you only add things to the end, though it means you have to do index iteration. (Alternatively you could iterate backwards, and push to the front, though that would need you to have a few separate additions of "count" [one on the iterator index and another on your end condition]).
Code: [Select]
size_t count = 0;
for (i = 0; i < res.size() - count; ++i) {
  if(condition of res[i]) {
    res.push_back(new_thing);
    count += 1;
  }
  if(condition 2 of res[i]) {
    res.push_back(new_thing2);
    res.push_back(new_thing3);
    count += 2;
  }
}
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #6496 on: November 03, 2014, 01:28:51 am »

-
« Last Edit: March 27, 2016, 05:09:45 pm by GUNINANRUNIN »
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6497 on: November 03, 2014, 02:03:59 am »

No code tags? I can only read monospaced type!
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #6498 on: November 03, 2014, 02:58:44 am »

-
« Last Edit: March 27, 2016, 05:09:54 pm by GUNINANRUNIN »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6499 on: November 03, 2014, 05:14:05 am »

Alright I have a separate videogame project- this time in C#
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
//using System.Windows.Controls;//Grid //invalid import??
namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();
           
            Form1 x = new Form1();
            Application.Run(x);



            Button[] bray = new Button[8];
            Button b= new Button();
            //x.Layout += new TableLayoutPanel().get; //invalid import.
           
            for (int i=0; i < bray.Length; i++) {
                bray[i]=new Button();
                b = bray[i];
               // b.MinimumSize.Width = 40;
                b.SetBounds(40, 40, 40, 40);//b.SetBounds(intx,inty,intwidth,intheight)
                b.Text = "Hooray";

                x.Controls.Add(b);
                b.Visible = true;
            }

        }
    }
    static class LoadImages {
     //  public Image i;
   
    }
}
I can't figure out why none of the buttons are showing.
I meant to make a 2*4 grid with the buttons.(rowlength*columnlength)
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6500 on: November 03, 2014, 05:31:02 am »

It's because the buttons are only created after you quit your application, and even then they're not added to the window. First of all, the entire window needs to be initialized before you call Application.Run(). Second, you need to add the form to your window somewhere.
Logged

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #6501 on: November 03, 2014, 08:59:54 am »

Spoiler (click to show/hide)

Code: [Select]
[s]-- 6.
SELECT ???
FROM product_summary;[/s]



Umm.. Hm. Number 6.. How to... ( ._.)7

Other than that I think I did pretty well. Took me about 30 minutes.

E: Maybe this would work for 6.

SELECT MAX(order_total) AS best_products
FROM product_summary;

SELECT sales FROM product_summary ORDER BY sales DESC LIMIT 5;

Substitute whatever the total sales field is called for 'sales'. Unless I'm missing something, that should work.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

Sergius

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6502 on: November 03, 2014, 09:54:42 am »

@GUNINANRUNIN

1. You're selecting from two tables but aren't joining them. That select will just give you a matrix of every possible customer/address combination (I assume there's a customer_id column in the addresses table)

So either
  • WHERE customer.customer_id = addresses.customer_id
  • LEFT JOIN addresses ON customer.customer_id = addresses.customer_id
    • (in the second method don't include the addresses table in the FROM, the join already takes care of that

4. Again, no WHERE or JOIN statement to create a relationship between the tables.

Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6503 on: November 04, 2014, 05:08:40 pm »

So, I've been doing a lot of programming with Python lately and I've come to really love it.  I've always found it kind of interesting that it was strongly typed, compared to say PHP or JavaScript, but figured that was something that didn't matter much.

Today I was reminded of how helpful strong typing can be.  I've been working on some JavaScript middleware for an IP TV set top box system for a while now, and I just wasted two hours trying to figure out why something wouldn't record correctly.  It all came down to JavaScript's interpretation of 0 + '0', which is '00'.  That caused the UNIX timestamp I was passing to the recording function to have an extra 0 at the end, and the set top box reasonably didn't want to schedule a recording a few hundred years into the future.

Yeah... with strong typing that wouldn't have been a problem, since it would have exploded on that line with a very clear indication of why.

Python isn't perfect of course.  My biggest gripe with it so far is probably how verbose and complicated its module and import system can get, but that's probably my fault more than anything.

I've also really been annoyed at the fact that Windows is treated as a second class citizen for some Python packages, and Python 3 is also treated as a second class citizen.  It took me a few hours last night to find and install a library to output BMP files from Python code, during which time I could have probably coded it the hard way.  Some packages didn't install on Windows at all, and some either didn't work with Python 3 or misbehaved in poorly documented ways with it.  I'm still absolutely stunned that the NLP library installed on Windows with Python 3, but I did have to locate some files and move them around to get Python 3 to work with all of its features, none of which was documented.  Some kind of serialized object... a pickled egg I think Python calls it?

I still have so much to learn about Python.  Frequently I learn that some overly verbose or complex thing I need to do is handled natively or using some simple construct.
Logged
Through pain, I find wisdom.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6504 on: November 04, 2014, 06:30:25 pm »

...Python's import system is complicated? Compared to what?

Seriously, try using "import antigravity" sometime.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6505 on: November 04, 2014, 06:43:03 pm »

I think python's import system is a bit weird too actually.  I remember having to create an empty __init__.py file once to make something work and I don't quite remember why.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6506 on: November 04, 2014, 06:44:44 pm »

If it's in a folder, there must be an __init__.py in the folder for said folder to be recognized as a python module.

...That's pretty much it.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6507 on: November 04, 2014, 06:49:12 pm »

Still seems like a non-intuitive way of doing things.  Why not something like:

import 'mymodule/'

or

import_module 'mymodule'
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6508 on: November 04, 2014, 07:07:03 pm »

In my case it was largely the fact that I had some fairly deep module hierarchies that had only one or two files each containing a single class.  It ended up creating some repetitiveness in the import statements, since I'd have to do something like

Code: [Select]
from .astronomy.planet import Planet

Looking back on it, I'm probably just doing something wrong.  I think I can just do something like

Code: [Select]
import astronomy

But then I have to manually put the exported class names in the __init__.py files based on my understanding.  There's probably a better way.  I did find out that dynamically and automatically loading classes from all of the .py files in a directory in the __init__.py file was surprisingly hard to do though.

It's definitely not worse than something like PHP's includes system with its fabulously unpredictable paths or C or C++'s heavy weight includes, but not quite as simple as I'd have hoped for.
Logged
Through pain, I find wisdom.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6509 on: November 04, 2014, 07:26:50 pm »

Nope, just doing it wrong, heh. "from astronomy.planet import Planet" could easily be fixed by just having "import astronomy" then using astronomy.planet.Planet() instead of just Planet().
Pages: 1 ... 432 433 [434] 435 436 ... 796